-
Notifications
You must be signed in to change notification settings - Fork 2
/
branchout-maven
executable file
·198 lines (160 loc) · 5.84 KB
/
branchout-maven
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
test -n "${DEBUG}" && set -x
set -e
function runMaven() {
commands=("${@}")
declare -a expandedCommands
POM_FILE="pom.xml"
test -f reactor.xml && POM_FILE="reactor.xml"
for each in ${!commands[*]}; do
case "${commands[$each]}" in
cv) expandedCommands+=('clean' 'verify');;
cvi) expandedCommands+=('-Pwebapp-interactive' 'clean' 'verify');;
vi) expandedCommands+=('-Pwebapp-interactive' 'verify');;
hth) expandedCommands+=('clean' 'verify'); POM_FILE="head-to-head.xml";;
hthi) expandedCommands+=('-Pwebapp-interactive' 'clean' 'verify'); POM_FILE="head-to-head.xml";;
tag) expandedCommands+=('-B' 'validate' 'release:prepare');;
up) expandedCommands+=('release:perform');;
# Project information commands
dep) expandedCommands+=('dependency:resolve');;
src) expandedCommands+=('dependency:sources');;
tree) expandedCommands+=('dependency:tree');;
pom) expandedCommands+=('help:effective-pom');;
set) expandedCommands+=('help:effective-settings');;
# Project definition update commands
par) expandedCommands+=('versions:update-parent');;
plu) expandedCommands+=('versions:display-plugin-updates');;
update) expandedCommands+=('bounds:update');;
upgrade) expandedCommands+=('bounds:upgrade');;
*) expandedCommands+=("${commands[$each]}");;
esac
done
echo "mvn -f ${POM_FILE} -s ${BRANCHOUT_STATE}/maven/settings.xml ${expandedCommands[*]}"
exec mvn -f "${POM_FILE}" -s "${BRANCHOUT_STATE}/maven/settings.xml" "${expandedCommands[@]}"
}
function mavenSettings() {
if test -z "${BRANCHOUT_MAVEN_REPOSITORY}"; then
readValue "your maven repository" "BRANCHOUT_MAVEN_REPOSITORY"
[[ ${BRANCHOUT_MAVEN_REPOSITORY} =~ ^https:// ]] || BRANCHOUT_MAVEN_REPOSITORY="https://${BRANCHOUT_MAVEN_REPOSITORY}"
"${BRANCHOUT_PATH}/branchout" set "BRANCHOUT_MAVEN_REPOSITORY" "${BRANCHOUT_MAVEN_REPOSITORY}"
fi
if test -z "${BRANCHOUT_DOCKER_REGISTRY}"; then
readValue "your docker registry" "BRANCHOUT_DOCKER_REGISTRY"
"${BRANCHOUT_PATH}/branchout" set "BRANCHOUT_DOCKER_REGISTRY" "${BRANCHOUT_DOCKER_REGISTRY}"
fi
readValue "your artifact repository username" "REPOSITORY_USER"
readSecret "your artifact repository secret" "REPOSITORY_API_KEY"
mkdir -p "${BRANCHOUT_STATE}/maven/"
echo "writing ${BRANCHOUT_STATE}/maven/settings.xml"
if test -f "${PROJECTION_DIRECTORY}/branchout-templates/maven-settings.xml"; then
echo <(cat "${PROJECTION_DIRECTORY}/branchout-templates/maven-settings.xml") > "${BRANCHOUT_STATE}/maven/settings.xml"
else
if [ "$(command -v cygpath)" ]; then
MAVEN_LOCAL_REPOSITORY=$(cygpath --windows "${BRANCHOUT_STATE}/maven/repository")
else
MAVEN_LOCAL_REPOSITORY="${BRANCHOUT_STATE}/maven/repository"
fi
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<settings xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd\" xmlns=\"http://maven.apache.org/SETTINGS/1.1.0\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
<localRepository>${MAVEN_LOCAL_REPOSITORY}</localRepository>
<servers>
<server>
<username>${REPOSITORY_USER}</username>
<password>${REPOSITORY_API_KEY}</password>
<id>branchout-maven</id>
</server>
<server>
<username>${REPOSITORY_USER}</username>
<password>${REPOSITORY_API_KEY}</password>
<id>${BRANCHOUT_DOCKER_REGISTRY}</id>
</server>
</servers>
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<url>${BRANCHOUT_MAVEN_REPOSITORY}</url>
<id>branchout-maven</id>
</mirror>
</mirrors>
<pluginGroups>
<pluginGroup>net.stickycode.plugins</pluginGroup>
</pluginGroups>
</settings>
" > "${BRANCHOUT_STATE}/maven/settings.xml"
fi
}
function mavenReactor() {
MODULES=$(find . -name "pom.xml" -print | awk -v FS="(/|pom.xml)" '{print $2}')
MODULE_XML=""
NEWLINE=$'\n'
TAB=$'\t'
ensureValue "the Maven group" "GROUP"
for module in $MODULES
do
MODULE_XML="${MODULE_XML}${NEWLINE}${TAB}<module>${module}</module>${NEWLINE}"
done
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<settings xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd\" xmlns=\"http://maven.apache.org/SETTINGS/1.1.0\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
<groupId>${GROUP}</groupId>
<artifactId>${PWD##*/}</artifactId>
<version>0</version>
<packaging>pom</packaging>
<name>\${project.artifactId}</name>
<modules>
$MODULE_XML
</modules>
</project>" > reactor.xml
echo "Reactor generated"
}
function usage() {
echo "branchout-maven settings|reactor|<alias>|<maven command>
settings
Generate the maven settings file
reactor
Generate the reactor.xml for the current directory
alias
cv clean verify
cvi clean verify -Pwebapp-interactive
maven command
clean
generate-resources
process-resouces
compile
process-classes
test
prepare-package
package
integration-test
verify
"
exit 1
}
function main() {
test $# -gt 0 || usage
BRANCHOUT_PATH="$(dirname "$0")"
# shellcheck source=branchout-configuration
. "${BRANCHOUT_PATH}/branchout-configuration"
# shellcheck source=branchout-environment
. "${BRANCHOUT_PATH}/branchout-environment"
case "${1}" in
version)
echo "Branchout $BRANCHOUT_STATE with $(java -version 2>&1 | head -n 1) as $GIT_AUTHOR_EMAIL"
runMaven --version
;;
reactor)
mavenReactor "${*}"
;;
settings)
mavenSettings "${*}"
;;
show)
sed -e 's,<password>.*</password>,<password>XXXXX</password>,g' "${BRANCHOUT_STATE}/maven/settings.xml"
;;
*)
test -f "${BRANCHOUT_STATE}/maven/settings.xml" || mavenSettings
runMaven "${@}"
esac
}
main "${@}"