1#!/bin/bash 2# Copyright 2019 Google LLC 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16set -eo pipefail 17shopt -s nullglob 18 19## Get the directory of the build script 20scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}")) 21## cd to the parent directory, i.e. the root of the git repo 22cd ${scriptDir}/.. 23 24# include common functions 25source ${scriptDir}/common.sh 26 27# Print out Java 28java -version 29echo $JOB_TYPE 30 31function determineMavenOpts() { 32 local javaVersion=$( 33 # filter down to the version line, then pull out the version between quotes, 34 # then trim the version number down to its minimal number (removing any 35 # update or suffix number). 36 java -version 2>&1 | grep "version" \ 37 | sed -E 's/^.*"(.*?)".*$/\1/g' \ 38 | sed -E 's/^(1\.[0-9]\.0).*$/\1/g' 39 ) 40 41 if [[ $javaVersion == 17* ]] 42 then 43 # MaxPermSize is no longer supported as of jdk 17 44 echo -n "-Xmx1024m" 45 else 46 echo -n "-Xmx1024m -XX:MaxPermSize=128m" 47 fi 48} 49 50export MAVEN_OPTS=$(determineMavenOpts) 51 52# this should run maven enforcer 53retry_with_backoff 3 10 \ 54 mvn install -B -V -ntp \ 55 -DskipTests=true \ 56 -Dmaven.javadoc.skip=true \ 57 -Dclirr.skip=true 58 59mvn -B dependency:analyze -DfailOnWarning=true 60 61echo "****************** DEPENDENCY LIST COMPLETENESS CHECK *******************" 62## Run dependency list completeness check 63function completenessCheck() { 64 # Output dep list with compile scope generated using the original pom 65 # Running mvn dependency:list on Java versions that support modules will also include the module of the dependency. 66 # This is stripped from the output as it is not present in the flattened pom. 67 # Only dependencies with 'compile' or 'runtime' scope are included from original dependency list. 68 msg "Generating dependency list using original pom..." 69 mvn dependency:list -f pom.xml -DincludeScope=runtime -Dsort=true | grep '\[INFO] .*:.*:.*:.*:.*' | sed -e 's/ --.*//' >.org-list.txt 70 71 # Output dep list generated using the flattened pom (only 'compile' and 'runtime' scopes) 72 msg "Generating dependency list using flattened pom..." 73 mvn dependency:list -f .flattened-pom.xml -DincludeScope=runtime -Dsort=true | grep '\[INFO] .*:.*:.*:.*:.*' >.new-list.txt 74 75 # Compare two dependency lists 76 msg "Comparing dependency lists..." 77 diff .org-list.txt .new-list.txt >.diff.txt 78 if [[ $? == 0 ]] 79 then 80 msg "Success. No diff!" 81 else 82 msg "Diff found. See below: " 83 msg "You can also check .diff.txt file located in $1." 84 cat .diff.txt 85 return 1 86 fi 87} 88 89# Allow failures to continue running the script 90set +e 91 92error_count=0 93for path in **/.flattened-pom.xml 94do 95 # Check flattened pom in each dir that contains it for completeness 96 dir=$(dirname "$path") 97 pushd "$dir" 98 completenessCheck "$dir" 99 error_count=$(($error_count + $?)) 100 popd 101done 102 103if [[ $error_count == 0 ]] 104then 105 msg "All checks passed." 106 exit 0 107else 108 msg "Errors found. See log statements above." 109 exit 1 110fi 111