Skip to content

Commit 4f098a1

Browse files
rsafonsecaDaanHoogland
authored andcommitted
Check return code on plugin runs
Signed-off-by: Daan Hoogland <daan@onecht.net>
1 parent b9f5d38 commit 4f098a1

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

‎tools/travis/downloadDeps.sh‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/bin/bash
2+
3+
#Get all dependency blocks from all pom.xml files in the project
14
for line in $(find ../../ -name pom.xml -exec sed -n '/<dependencies>/{:a;n;/<\/dependencies>/b;p;ba}' {} \; | grep -e "artifactId" -e "groupId" -e "version" -e "dependency\>" -e "exclusion\>" -e "exclusions\>"| sed -e 's/\^M//'); do
25

36
#Tokenize values
@@ -11,7 +14,7 @@ for line in $(find ../../ -name pom.xml -exec sed -n '/<dependencies>/{:a;n;/<\/
1114
unset VERSION
1215
unset GROUP
1316
elif [[ $1 == "/dependency" ]]; then
14-
#Filter out project modules interdependencies and noredist artifacts
17+
#Filter out project modules interdependencies
1518
if [[ $GROUP != *org.apache.cloudstack* ]] && [[ $GROUP != *com.cloud* ]] && [[ $ARTIFACT != cloudstack-service-console-proxy-rdpclient ]]; then
1619
if [[ -z $VERSION ]] ; then
1720
VERSION=LATEST
@@ -25,21 +28,23 @@ for line in $(find ../../ -name pom.xml -exec sed -n '/<dependencies>/{:a;n;/<\/
2528
#If version is a maven var, get the value from parent pom
2629
if [[ $2 == \$\{* ]]; then
2730
VERSION=$(grep \<$(echo $2 | awk -v FS="(}|{)" '{print $2 }') ../../pom.xml | awk -v FS="(>|<)" '{print $3}')
31+
#If version tag is empty, add LATEST to avoid maven errors
2832
elif [[ "$2" == "" ]]; then
2933
VERSION="LATEST"
3034
else
3135
VERSION=$2
3236
fi
3337
elif [[ $1 == "artifactId" ]]; then
38+
#This avoids exclusions inside dependency block to overwrite original dependency
3439
if [[ -z $ARTIFACT ]]; then
3540
ARTIFACT=$2
3641
fi
3742
elif [[ $1 == "groupId" ]]; then
43+
#This avoids exclusions inside dependency block to overwrite original dependency
3844
if [[ -z $GROUP ]]; then
3945
GROUP=$2
4046
fi
4147
fi
42-
4348
done
4449

4550
#Add the resolved plugins to properly download their dependencies
@@ -52,25 +57,28 @@ while read line ; do
5257
echo $DATA >> deps.out
5358
done < /tmp/resolvedPlugins
5459

60+
#Remove duplicates and sort them, LANG export is needed to fix some sorting issue, sorting is needed for later function that relies on sorted input
5561
cat deps.out | LANG=C sort -u > cleandeps.out
5662

63+
#Define index of pomfiles, to avoid duplicate deps with different versions in pom.xml, several poms are created in case of more than one version of same artifact
5764
LASTPOM=0
5865
echo '<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.apache.cloudstack</groupId><artifactId>travis-build-deps</artifactId><name>Download Deps for Travis CI</name><version>1</version><repositories><repository><id>mido-maven-public-releases</id><name>mido-maven-public-releases</name><url>http://cs-maven.midokura.com/releases</url></repository><repository><id>juniper-contrail</id><url>http://juniper.github.io/contrail-maven/snapshots</url></repository></repositories><dependencies>' > pom${LASTPOM}.xml
5966
while read line ; do
6067
set -- $line
61-
68+
#This relies on correct sorting, and distributes different versions of same dependency througout different pom files
6269
if [[ $2 == $LASTARTIFACT ]]; then
6370
POMID=$(($POMID+1))
71+
#If value is greater than current number of poms, create a new one
6472
if [[ $POMID -gt $LASTPOM ]]; then
6573
LASTPOM=$POMID
74+
#This outputs the necessary structure to start a pom and also defines the extra repositories
6675
echo '<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.apache.cloudstack</groupId><artifactId>travis-build-deps</artifactId><name>Download Deps for Travis CI</name><version>1</version><repositories><repository><id>mido-maven-public-releases</id><name>mido-maven-public-releases</name><url>http://cs-maven.midokura.com/releases</url></repository><repository><id>juniper-contrail</id><url>http://juniper.github.io/contrail-maven/snapshots</url></repository></repositories><dependencies>' > pom${LASTPOM}.xml
6776
fi
6877
else
6978
POMID=0
7079
fi
7180
LASTARTIFACT=$2
7281
echo "<dependency><groupId>$1</groupId><artifactId>$2</artifactId><version>$3</version></dependency>" >> pom${POMID}.xml
73-
7482
done < cleandeps.out
7583

7684
RETURN_CODE=0
@@ -90,23 +98,27 @@ done
9098
mkdir -p src/main/resources
9199
echo '<?xml version="1.0" encoding="utf-8" ?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"></xs:schema>' > src/main/resources/test.xsd
92100

93-
101+
#Declare plugin tests to run
94102
declare -a arr=("maven-surefire-plugin test" "maven-pmd-plugin pmd" "maven-compiler-plugin compile" "maven-resources-plugin resources" "maven-checkstyle-plugin check" "maven-site-plugin attach-descriptor" "maven-surefire-plugin test" "maven-jar-plugin jar" "license-maven-plugin check" "maven-jgit-buildnumber-plugin extract-buildnumber" "maven-jaxb2-plugin generate" "maven-war-plugin war -DfailOnMissingWebXml=false" "gmaven-plugin compile")
95103
for i in "${arr[@]}"
96104
do
97105
set -- $i
98106
PLUGIN=$1
99107
MOJO=$2
100108
OPTION=$3
109+
#Get every listed version of the plugin and make a run for each version
101110
while read line ; do
102111
set -- $line
103112
JOBS="${JOBS} ${1}:${2}:${3}:${MOJO} $OPTION"
104113
done < <(grep $PLUGIN cleandeps.out)
105114
done
106115
echo "Running $JOBS"
107116
mvn $JOBS -f pom0.xml
117+
if [[ $? -ne 0 ]]; then
118+
RETURN_CODE=1
119+
fi
108120

109-
121+
#Cleanup some files created in the run
110122
rm -rf deps.out src target
111123

112124
exit $RETURN_CODE

0 commit comments

Comments
 (0)