-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathbuild-folder.sh
executable file
·181 lines (172 loc) · 4.56 KB
/
build-folder.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
SCDIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
SCDIR=$(realpath $SCDIR)
bold="\033[1m"
red="\033[31m"
dim="\033[2m"
end="\033[0m"
(return 0 2>/dev/null) && sourced=1 || sourced=0
function check_env() {
eval ev='$'$1
if [ "$ev" == "" ]; then
echo "$1 not defined"
if ((sourced != 0)); then
return 1
else
exit 1
fi
fi
}
if [ "$1" == "" ]; then
echo -e "Options: ${bold} <comma-separated-folders> [<maven-goals>]*${end}"
exit 1
fi
if [ "$VERBOSE" = "true" ]; then
MAVEN_OPTS="-X"
elif [ "$VERBOSE" = "false" ]; then
MAVEN_OPTS="-q"
fi
MAVEN_OPTS="$MAVEN_OPTS -B"
if [ "$SKIP_DEPLOY" != "true" ]; then
MAVEN_OPTS="$MAVEN_OPTS -s $SCDIR/.settings.xml"
fi
FOLDER_NAMES="$1"
shift
MAVEN_GOAL=$*
if [ "$MAVEN_GOAL" == "" ]; then
echo -e "Using default goal ${bold}install${end}"
MAVEN_GOAL="install"
fi
# Determine profile based on version type
if [ "$VERSION" == "" ]; then
echo "Determining version number"
VERSION=$($SCDIR/mvn-get-version.sh)
fi
echo -e "Determining profile to use for version $VERSION"
set +e
IS_SNAPSHOT=$(echo $VERSION | grep -E "^.*-SNAPSHOT$")
IS_MILESTONE=$(echo $VERSION | grep -E "^.*-(M|RC)[0-9]+$")
IS_GA=$(echo $VERSION | grep -E "^.*\.[0-9]+$")
if [ -n "$IS_MILESTONE" ]; then
MAVEN_PROFILE="-Pmilestone"
elif [ -n "$IS_SNAPSHOT" ]; then
MAVEN_PROFILE="-Psnapshot"
elif [ -n "$IS_GA" ]; then
MAVEN_PROFILE="-Prelease"
else
echo "Bad version format: $VERSION"
exit 1
fi
echo "Profile for version $VERSION is '$MAVEN_PROFILE'"
# if goal includes 'deploy' or is GA release then add the profile based on version
IS_DEPLOY=$(echo $MAVEN_GOAL | grep -E "\bdeploy\b")
if [ -n "$IS_DEPLOY" ] || [ -n "$IS_GA" ]; then
echo "Using profile: $MAVEN_PROFILE"
MAVEN_GOAL="$MAVEN_GOAL $MAVEN_PROFILE"
fi
SAVED_IFS=$IFS
IFS=,
FOLDERS=
START_TIME=$(date +%s)
for FOLDER in $FOLDER_NAMES; do
if [ ! -d "$FOLDER" ]; then
echo -e "${bold}Folder not found ${red}$FOLDER${end}"
exit 2
fi
if [ "$FOLDERS" == "" ]; then
FOLDERS="$FOLDER"
else
FOLDERS="$FOLDERS $FOLDER"
fi
done
# IFS will affect mvnw ability to split arguments.
IFS=$SAVED_IFS
if [[ "$MAVEN_GOAL" == *"deploy"* ]] && [ "$SKIP_DEPLOY" != "true" ]; then
check_env ARTIFACTORY_USERNAME
check_env ARTIFACTORY_PASSWORD
fi
MAVEN_THREADS_OPT="1"
if [ "$MAVEN_THREADS" != "" ]; then
case $MAVEN_THREADS in
"true")
MAVEN_THREADS_OPT="0.5C"
;;
"false")
MAVEN_THREADS_OPT="1"
;;
*)
MAVEN_THREADS_OPT="$MAVEN_THREADS"
;;
esac
fi
MVN_THR="-T $MAVEN_THREADS_OPT"
if [ "$SKIP_RESOLVE" = "" ]; then
SKIP_RESOLVE=true
fi
if [ "$SKIP_RESOLVE" = "true" ]; then
RETRIES=0
RESULT=0
else
RETRIES=3
fi
while ((RETRIES > 0)); do
echo -e "Resolving dependencies for ${bold}$FOLDER_FOLDER_NAMES${end}"
set +e
$SCDIR/mvnw -U -pl "$FOLDER_NAMES" $MAVEN_OPTS -T 0.5C dependency:resolve
RESULT=$?
set -e
if ((RESULT == 0)); then
break
fi
RETRIES=$((RETRIES - 1))
if ((RETRIES >= 0)); then
echo -e "RETRY:Resolving dependencies for ${bold}$FOLDER${end}"
fi
done
if ((RESULT == 0)); then
for FOLDER in $FOLDERS; do
# save values that may be modified by set-env.sh
SAVED_MAVEN_OPTS="$MAVEN_OPTS"
SAVED_MVN_THR="$MVN_THR"
SAVED_MAVEN_GOAL="$MAVEN_GOAL"
if [ -f "$FOLDER/set-env.sh" ]; then
echo "Sourcing:$FOLDER/set-env.sh"
source "$FOLDER/set-env.sh"
fi
set +e
echo -e "Maven goals:${bold}-f $FOLDER $MAVEN_OPTS $MVN_THR $MAVEN_GOAL${end}"
MVNW="./mvnw"
if [ ! -f $MVNW ]; then
MVNW="$SCDIR/mvnw"
fi
IS_DEPLOY=false
# if [ "$BUILD_VERSION_TYPE" != "" ]; then
# if [[ "$MAVEN_GOAL" == *"deploy"* ]]; then
# MAVEN_GOAL="${MAVEN_GOAL//deploy/}"
# IS_DEPLOY=true
# fi
# MVNW="jfrog mvn"
# fi
echo -e "Executing:${bold}$MVNW -f "$FOLDER" $MAVEN_OPTS $MVN_THR $MAVEN_GOAL${end}"
$MVNW -f "$FOLDER" -Pfull $MAVEN_OPTS $MVN_THR $MAVEN_GOAL
RESULT=$?
set -e
if ((RESULT != 0)); then
echo -e "Maven goals:${bold}-f $FOLDER $MAVEN_GOAL${end}:FAILED=${RESULT}"
break
fi
# if [ "$IS_DEPLOY" == "true" ]; then
# echo -e "Executing:${bold}jfrog rt build-publish${end}"
# jfrog rt build-publish
# fi
echo -e "Maven goals:${bold}-f $FOLDER $MAVEN_GOAL${end}:SUCCESS"
# restore values that may be modified by set-env.sh
MAVEN_OPTS="$SAVED_MAVEN_OPTS"
MVN_THR="$SAVED_MVN_THR"
MAVEN_GOAL="$SAVED_MAVEN_GOAL"
done
fi
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
echo "Build of $FOLDER_NAMES $MAVEN_GOAL completed with result:$RESULT in $DURATION seconds"
exit $RESULT