@@ -482,3 +482,100 @@ function install_modules() {
482482 -T 1C
483483 fi
484484}
485+
486+
487+ # In the given directory ($1),
488+ # update the pom.xml's dependency on the given artifact ($2) to the given version ($3)
489+ # ex: update_dependency google-cloud-java/google-cloud-jar-parent google-cloud-shared-dependencies 1.2.3
490+ function update_pom_dependency {
491+ pushd " $1 " || exit 1
492+ xmllint --shell pom.xml & > /dev/null << EOF
493+ setns x=http://maven.apache.org/POM/4.0.0
494+ cd .//x:artifactId[text()="$2 "]
495+ cd ../x:version
496+ set $3
497+ save pom.xml
498+ EOF
499+ popd || exit 1
500+ }
501+
502+ # Find all pom.xml files that declare a specific version for the given artifact ($1)
503+ function find_all_poms_with_versioned_dependency {
504+ poms=($( find . -name pom.xml) )
505+ for pom in " ${poms[@]} " ; do
506+ if xmllint --xpath " //*[local-name()='artifactId' and text()='$1 ']/following-sibling::*[local-name()='version']" " $pom " & > /dev/null; then
507+ found+=(" $pom " )
508+ fi
509+ done
510+ POMS=(${found[@]} )
511+ unset found
512+ export POMS
513+ }
514+
515+ # In the given directory ($1),
516+ # find and update all pom.xmls' dependencies on the given artifact ($2) to the given version ($3)
517+ # ex: update_all_poms_dependency google-cloud-java google-cloud-shared-dependencies 1.2.3
518+ function update_all_poms_dependency {
519+ pushd " $1 " || exit 1
520+ find_all_poms_with_versioned_dependency " $2 "
521+ for pom in $POMS ; do
522+ update_pom_dependency " $( dirname " $pom " ) " " $2 " " $3 "
523+ done
524+ git diff
525+ popd || exit 1
526+ }
527+
528+ # Parse the version of the pom.xml file in the given directory ($1)
529+ # ex: VERSION=$(parse_pom_version java-shared-dependencies)
530+ function parse_pom_version {
531+ # Namespace (xmlns) prevents xmllint from specifying tag names in XPath
532+ result=$( sed -e ' s/xmlns=".*"//' " $1 /pom.xml" | xmllint --xpath ' /project/version/text()' -)
533+
534+ if [ -z " ${result} " ]; then
535+ echo " Version is not found in $1 "
536+ exit 1
537+ fi
538+ echo " $result "
539+ }
540+
541+ # ex: find_last_release_version java-bigtable
542+ # ex: find_last_release_version java-storage 2.22.x
543+ function find_last_release_version {
544+ repo=$1
545+ branch=${2-" main" } # Default to using main branch
546+ org=${3-" googleapis" }
547+ curl -s -o " versions_${repo} .txt" " https://raw.githubusercontent.com/${org} /${repo} /${branch} /versions.txt"
548+
549+ # First check to see if there's an entry for the overall repo. Used for google-cloud-java.
550+ primary_artifact=$( grep -E " ^${repo} " " versions_${repo} .txt" | head -n 1)
551+ if [ -z " ${primary_artifact} " ]; then
552+ # Otherwise, use the first google-cloud-* artifact's version.
553+ primary_artifact=$( grep -E " ^google-cloud-" " versions_$1 .txt" | head -n 1)
554+ fi
555+ if [ -z " ${primary_artifact} " ]; then
556+ echo " Unable to identify primary artifact for $1 "
557+ exit 1
558+ fi
559+
560+ parts=($( echo " $primary_artifact " | tr " :" " \n" ) )
561+ echo " ${parts[1]} "
562+ }
563+
564+ # copies settings.xml from the root of sdk-platform-java into Maven's home
565+ # folder
566+ function setup_maven_mirror {
567+ echo " Setup maven mirror"
568+ mkdir -p " ${HOME} /.m2"
569+ cp " ${commonScriptDir} /../../settings.xml" " ${HOME} /.m2"
570+ }
571+
572+ function install_repo_modules {
573+ target_projects=" $1 "
574+ projects_arg=" "
575+ if [ -n " ${target_projects} " ]; then
576+ projects_arg=" --projects ${target_projects} "
577+ fi
578+ echo " Installing this repo's modules to local maven."
579+ mvn -q -B -ntp install ${projects_arg} \
580+ -Dcheckstyle.skip -Dfmt.skip -DskipTests -T 1C
581+ }
0 commit comments