forked from openjdk/jmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·204 lines (174 loc) · 5.88 KB
/
build.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
set -e # immediately exit if any command has a non-zero exit status
set -u # a reference to any variable you have not previously defined causes the program to immediately exit
set -o pipefail # If any command in a pipeline fails, that return code will be used as the return code of the whole pipeline
PROGNAME=$(basename "$0")
JETTY_PID=""
function err_report() {
err_log "$(date +%T) ${PROGNAME}: Error on line $1"
err_log "$(date +%T) current working directory: $PWD"
}
function exitTrap() {
if [ -n "${JETTY_PID}" ]; then
echo "$(date +%T) terminating jetty server"
pkill -P "${JETTY_PID}"
fi
}
function err_log() {
echo "$@" >&2
}
trap 'err_report $LINENO' ERR
trap 'exitTrap' EXIT
function printHelp() {
echo "usage: call ./$(basename "$0") with the following options:"
{
printf " \t%s\t%s\n" "--runTests" "to run the tests"
printf " \t%s\t%s\n" "--runUiTests" "to run the tests including UI tests"
printf " \t%s\t%s\n" "--packageJmc" "to package JMC"
printf " \t%s\t%s\n" "--clean" "to run maven clean"
printf " \t%s\t%s\n" "--run" "to run JMC once it was packaged"
printf " \t%s\t%s\n" "--help" "to show this help dialog"
} | column -ts $'\t'
}
if [ $# -eq 0 ]; then
printHelp
exit 0
fi
function runTests() {
mvn verify
}
function runUiTests() {
mvn verify -P uitests
}
function packageJmc() {
local timestamp
timestamp="$(date +%Y%m%d%H%M%S)"
local BASEDIR
BASEDIR=$(mvn help:evaluate -Dexpression=project.build.directory --non-recursive -q -DforceStdout)
mkdir -p "${BASEDIR}" # just in case clean was called before
local p2SiteLog="${BASEDIR}/build_${timestamp}.1.p2_site.log"
local jettyLog="${BASEDIR}/build_${timestamp}.2.jetty.log"
local installLog="${BASEDIR}/build_${timestamp}.3.install.log"
local packageLog="${BASEDIR}/build_${timestamp}.4.package.log"
pushd releng/third-party 1> /dev/null || {
err_log "directory releng/third-party not found"
exit 1
}
echo "$(date +%T) building p2:site - logging output to ${p2SiteLog}"
mvn p2:site --log-file "${p2SiteLog}"
echo "$(date +%T) run jetty - logging output to ${jettyLog}"
touch "${jettyLog}" # create file so that it exists already for tail below
mvn jetty:run --log-file "${jettyLog}" &
JETTY_PID=$!
while ! grep -q "^\[INFO\] Started Jetty Server$" "${jettyLog}"; do
echo "$(date +%T) waiting for jetty server to start"
sleep 1
done
echo "$(date +%T) jetty server up and running"
popd 1> /dev/null || {
err_log "could not go to project root directory"
exit 1
}
pushd core 1> /dev/null || {
err_log "directory core not found"
exit 1
}
echo "$(date +%T) installing core artifacts - logging output to ${installLog}"
mvn clean install --log-file "${installLog}"
popd 1> /dev/null || {
err_log "could not go to project root directory"
exit 1
}
echo "$(date +%T) packaging jmc - logging output to ${packageLog}"
mvn package --log-file "${packageLog}"
if [[ "${OSTYPE}" =~ "linux"* ]]; then
echo "You can now run jmc by calling \"${PROGNAME} --run\" or \"${BASEDIR}/products/org.openjdk.jmc/linux/gtk/x86_64/JDK\ Mission\ Control/jmc\""
elif [[ "${OSTYPE}" =~ "darwin"* ]]; then
echo "You can now run jmc by calling \"${PROGNAME} --run\" or \"${BASEDIR}/products/org.openjdk.jmc/macosx/cocoa/x86_64/JDK\ Mission\ Control.app/Contents/MacOS/jmc\""
else
err_log "unknown OS type: \"${OSTYPE}\". Please check your package in \"${BASEDIR}/products/org.openjdk.jmc/\""
fi
}
function clean() {
mvn clean
pushd core 1> /dev/null || {
err_log "directory core not found"
exit 1
}
mvn clean
popd 1> /dev/null || {
err_log "could not go to project root directory"
exit 1
}
pushd releng/third-party 1> /dev/null || {
err_log "directory releng/third-party not found"
exit 1
}
mvn clean
popd 1> /dev/null || {
err_log "could not go to project root directory"
exit 1
}
}
function run() {
local BASEDIR
BASEDIR="$(mvn help:evaluate -Dexpression=project.build.directory --non-recursive -q -DforceStdout)"
local path
if [[ "${OSTYPE}" =~ "linux"* ]]; then
path="${BASEDIR}/products/org.openjdk.jmc/linux/gtk/x86_64/JDK Mission Control/jmc"
elif [[ "${OSTYPE}" =~ "darwin"* ]]; then
path="${BASEDIR}/products/org.openjdk.jmc/macosx/cocoa/x86_64/JDK Mission Control.app/Contents/MacOS/jmc"
else
err_log "unknown OS type: ${OSTYPE}"
exit 1
fi
if [ -f "${path}" ]; then
exec "${path}"
else
err_log "JMC not found in \"${path}\". Did you call --packageJmc before?"
exit 1
fi
}
function parseArgs() {
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
printHelp
exit 0
;;
--test)
runTests
;;
--testUi)
runUiTests
;;
--packageJmc)
packageJmc
;;
--clean)
clean
;;
--run)
run
;;
*)
err_log "unknown argument \"$1\""
printHelp
exit 1
;;
esac
shift
done
}
function checkPreconditions() {
if ! command -v mvn &> /dev/null ; then
err_log "It seems you do not have maven installed. Please ensure you have it installed and executable as \"mvn\"."
exit 1
fi
if ! command -v java &> /dev/null ; then
err_log "It seems you do not have java installed. Please ensure you have it installed and executable as \"java\"."
exit 1
fi
}
checkPreconditions
parseArgs "$@"