1#!/bin/bash 2 3set -e 4 5# Generate BOM of the artifacts in this repository 6 7bom_lines="" 8# For modules that produce BOMs 9for bom_directory in $(find . -maxdepth 3 -name 'google-*-bom' | sort --dictionary-order); do 10 if [[ "${bom_directory}" = *gapic-libraries-bom ]] || [[ "${bom_directory}" = *google-cloud-core* ]]; then 11 continue 12 fi 13 repo_metadata="${bom_directory}/../.repo-metadata.json" 14 15 pom_file="${bom_directory}/pom.xml" 16 groupId_line=$(grep --max-count=1 'groupId' "${pom_file}") 17 artifactId_line=$(grep --max-count=1 'artifactId' "${pom_file}") 18 version_line=$(grep --max-count=1 'x-version-update' "${pom_file}") 19 20 if [[ "$groupId_line" == *"com.google.maps"* ]]; then 21 # The gapic bom includes cloud libraries 22 continue 23 fi 24 25 bom_lines+=" <dependency>\n\ 26 ${groupId_line}\n\ 27 ${artifactId_line}\n\ 28 ${version_line}\n\ 29 <type>pom</type>\n\ 30 <scope>import</scope>\n\ 31 </dependency>\n" 32done 33 34# For originally-handwritten modules that do not produce a BOM 35for module in $(find . -mindepth 2 -maxdepth 2 -name pom.xml |sort --dictionary-order | xargs dirname); do 36 if ls ${module}/*-bom 1> /dev/null 2>&1; then 37 continue 38 fi 39 if ! test -f "${module}/.repo-metadata.json"; then 40 continue 41 fi 42 43 pom_file="${module}/pom.xml" 44 groupId_line=$(grep --max-count=1 'groupId' "${pom_file}") 45 artifactId_line=$(grep --max-count=1 'artifactId' "${pom_file}") 46 version_line=$(grep --max-count=1 'x-version-update' "${pom_file}") 47 bom_lines+=" <dependency>\n\ 48 ${groupId_line}\n\ 49 ${artifactId_line}\n\ 50 ${version_line}\n\ 51 </dependency>\n" 52done 53 54mkdir -p gapic-libraries-bom 55 56GENERATION_DIR=$(dirname -- "$0"); 57perl -0pe 's/<dependencies>.*<\/dependencies>/<dependencies>\nBOM_ARTIFACT_LIST\n <\/dependencies>/s' ${GENERATION_DIR}/../gapic-libraries-bom/pom.xml > ${GENERATION_DIR}/bom.pom.xml 58awk -v "dependencyManagements=$bom_lines" '{gsub(/BOM_ARTIFACT_LIST/,dependencyManagements)}1' \ 59 "${GENERATION_DIR}/bom.pom.xml" > gapic-libraries-bom/pom.xml 60rm ${GENERATION_DIR}/bom.pom.xml