-
Notifications
You must be signed in to change notification settings - Fork 0
/
drools.sh
executable file
·389 lines (349 loc) · 12.4 KB
/
drools.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#!/bin/bash
# Set Defaults
[[ -z $APP_NAME ]] && APP_NAME="grails-drools-sample"
[[ -z $BASE_DIR ]] && BASE_DIR=$(echo $HOME)
[[ -z $PLUGIN_DIR ]] && PLUGIN_DIR="$BASE_DIR/Development/Plugins/grails-drools"
[[ -z $SOURCE_DIR ]] && SOURCE_DIR="$BASE_DIR/Development/Plugins/grails-drools-sample"
[[ -z $TEST_DIR ]] && TEST_DIR="$(pwd)"
[[ -z $APP_DIR ]] && APP_DIR="$TEST_DIR/$APP_NAME"
[[ -z $BROWSER ]] && BROWSER="/Applications/Google Chrome.app"
[[ -z $DROOLS_VER ]] && DROOLS_VER=6.2.0.Final
[[ -z $GEB_VER ]] && GEB_VER=0.9.3
[[ -z $SELENIUM_VER ]] && SELENIUM_VER=2.43.1
[[ -z $JETTY_PLUGIN_VER ]] && JETTY_PLUGIN_VER=3.0.0
[[ -z $PACKAGE ]] && PACKAGE="grails.plugin.drools_sample"
[[ -z $APP_DIR ]] && APP_DIR="$TEST_DIR/$APP_NAME"
[[ -z $CONTAINERS ]] && CONTAINERS=(jetty tomcat)
[[ -z $GRAILS_BUILD_VER ]] && GRAILS_BUILD_VER=2.4.5
[[ -z $JETTY_VERSIONS ]] && JETTY_VERSIONS=( 2.3.11 2.4.5)
[[ -z $VERSIONS ]] && VERSIONS=( 2.3.11 2.4.5 )
[[ -z $DATE ]] && DATE=$(date +%Y-%m-%d_%T)
[[ -z $MAVEN_BASE_URL ]] && MAVEN_BASE_URL="http://localhost:8081/artifactory"
[[ -z $MAVEN_RELEASE_URL ]] && MAVEN_RELEASE_URL="$MAVEN_BASE_URL/plugins-release-local/"
[[ -z $MAVEN_SNAPSHOT_URL ]] && MAVEN_SNAPSHOT_URL="$MAVEN_BASE_URL/plugins-snapshot-local/"
# Check for Browser
if [ ! -e "$BROWSER" ]; then
echo "Error: No Browser found under $BROWSER"
exit 1
fi
# Do not change any variables below this line.
START_TIME=$(date +"%Y-%m-%d %T")
START_SECONDS=$(date +"%s")
ARG_CHECK=false
read -d '' LEGACY_DEP <<EOF
dependencies {
compile "org.drools:drools-compiler:$DROOLS_VER", {
excludes "activation", "antlr-runtime", "cdi-api", "drools-core", "ecj", "glazedlists_java15",
"gunit", "janino", "junit", "logback-classic", "mockito-all", "mvel2",
"org.osgi.compendium", "org.osgi.core", "protobuf-java", "quartz", "slf4j-api",
"stax-api", "weld-se-core", "xstream"
}
compile "org.drools:drools-core:$DROOLS_VER", {
excludes "activation", "antlr", "antlr-runtime", "cdi-api", "junit", "kie-api", "kie-internal",
"logback-classic", "mockito-all", "mvel2", "org.osgi.compendium", "org.osgi.core",
"protobuf-java", "slf4j-api", "stax-api", "xstream"
}
compile "org.drools:drools-decisiontables:$DROOLS_VER", {
excludes "commons-io", "drools-compiler", "drools-core", "drools-templates", "junit", "logback-classic",
"mockito-all", "org.osgi.compendium", "org.osgi.core", "poi-ooxml", "slf4j-api"
}
compile "org.drools:drools-jsr94:$DROOLS_VER", {
excludes "drools-compiler", "drools-core", "drools-decisiontables", "jsr94", "jsr94-sigtest",
"jsr94-tck", "junit", "mockito-all"
}
compile "org.drools:drools-verifier:$DROOLS_VER", {
excludes "drools-compiler", "guava", "itext", "junit", "kie-api", "mockito-all", "xstream"
}
compile "org.kie:kie-api:$DROOLS_VER", {
excludes "activation", "cdi-api", "jms", "junit", "mockito-all", "org.osgi.compendium",
"org.osgi.core", "quartz", "slf4j-api", "stax-api", "xstream"
}
compile "org.kie:kie-internal:$DROOLS_VER", {
excludes "cdi-api", "junit", "kie-api", "mockito-all", "slf4j-api", "xstream"
}
compile "org.kie:kie-spring:$DROOLS_VER", {
excludes "antlr-runtime", "cdi-api", "commons-logging", "drools-compiler", "drools-core", "drools-core",
"drools-decisiontables", "ecj", "h2", "hibernate-entitymanager", "hibernate-jpa-2.0-api",
"kie-api", "kie-internal", "logback-classic", "named-kiesession", "slf4j-api", "xstream"
}
EOF
read -d '' TEST_DEP <<EOF
dependencies {
test "org.gebish:geb-spock:$GEB_VER"
test "org.seleniumhq.selenium:selenium-chrome-driver:$SELENIUM_VER"
test "org.seleniumhq.selenium:selenium-firefox-driver:$SELENIUM_VER"
test "org.seleniumhq.selenium:selenium-support:$SELENIUM_VER"
test "org.spockframework:spock-grails-support:0.7-groovy-2.0"
EOF
read -d '' TEST_DEP_LEGACY <<EOF
dependencies {
test "org.gebish:geb-spock:$GEB_VER"
test "org.seleniumhq.selenium:selenium-chrome-driver:$SELENIUM_VER"
test "org.seleniumhq.selenium:selenium-firefox-driver:$SELENIUM_VER"
test "org.seleniumhq.selenium:selenium-support:$SELENIUM_VER"
EOF
read -d '' JETTY_PLUGIN <<EOF
compile ":jetty:$JETTY_PLUGIN_VER"
EOF
read -d '' HTML_START <<EOF
<html>
<head>
<title>Geb Tests</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css">
<head>
<body>
<div id="report" class="container container_8">
<div class="grid_6 alpha">
<div class="grailslogo"></div>
<h1>drools Test Results</h1>
<div class=clear></div>
<h2> </h2>
<h2>Started: START_TIME</h2>
<h2> </h2>
<h2>Finished: END_TIME</h2>
<h2> </h2>
<h2>Elapsed Time: ELAPSED_TIME</h2>
<h2> </h2>
EOF
read -d '' HTML_END <<EOF
</body>
</html>
EOF
showUsage() {
echo "Usage: The script requires two arguments."
echo "$ ./drools.sh all all"
echo " will test the plugin and its application using the following Grails versions"
echo " depending on which serverlet container is used."
echo " Jetty: ${JETTY_VERSIONS[@]}"
echo " Tomcat: ${VERSIONS[@]}"
echo " The test results are grouped by container and then version."
echo "$ ./drools.sh jetty 2.3.11"
echo " will test the plugin and its application using Jetty and Grails version 2.3.11."
echo "$TEST_DIR will contain a test summary and geb html pages."
exit 0
}
for container in "${CONTAINERS[@]}"; do
if [ "$container" == "$1" ]; then
if [ "$container" == "jetty" ]; then
for version in "${JETTY_VERSIONS[@]}"; do
if [ "$version" == "$2" ]; then
ARG_CHECK=true
fi
done
fi
if [ "$container" == "tomcat" ]; then
for version in "${VERSIONS[@]}"; do
if [ "$version" == "$2" ]; then
ARG_CHECK=true
fi
done
fi
fi
done
if [ "$1" == "all" ]; then
ARG_CHECK=true
fi
if [ "$2" == "all" ]; then
ARG_CHECK=true
fi
if [ $ARG_CHECK == false ]; then
showUsage
fi
openBrowser() {
if [ -f "$BROWSER" -o -d "$BROWSER" ]; then
/usr/bin/open -a "$BROWSER" "$1"
else
echo "Error: browser ($BROWSER) not found."
fi
exit 0
}
packagePlugin() {
ARTIFACTORY=`curl -s --head "$MAVEN_BASE_URL" | head -n 1 | wc -l`
if [ $ARTIFACTORY == "0" ]; then
echo "Starting Artifactory ...."
artifactory.sh start
sleep 2s
fi
echo "Packaging plugin ...."
source ~/.gvm/bin/gvm-init.sh
gvm use grails $GRAILS_BUILD_VER
cd $PLUGIN_DIR
PLUGIN_VER=$(grep "def version = .*$" DroolsGrailsPlugin.groovy | grep -o \".*\" | tr -d '"')
rm *.zip
grails clean
grails compile
if [[ $PLUGIN_VER == *SNAPSHOT* ]]; then
grails publish-plugin --allow-overwrite --noScm --repository=localPluginSnapshots
else
grails publish-plugin --allow-overwrite --noScm --repository=localPluginReleases
fi
}
testApp() {
CONTAINER=$1
GRAILS_VER=$2
PLUGIN_VER=$3
LEGACY=false
read -d '' TEST_DEP_PLUGIN <<EOF
plugins {
compile ":drools:$PLUGIN_VER"
test ":geb:$GEB_VER"
test ":spock:0.7"
EOF
read -d '' REPOSITORIES <<EOF
repositories {
mavenRepo "$MAVEN_SNAPSHOT_URL"
mavenRepo "$MAVEN_RELEASE_URL"
EOF
source ~/.gvm/bin/gvm-init.sh
if [ $GRAILS_VER == "default" ]; then
gvm use grails
else
gvm use grails $GRAILS_VER
fi
echo "Deleting cached project ...."
rm -r $BASE_DIR/.grails/$GRAILS_VER/projects/$APPNAME
echo "Deleting Ivy cache ...."
rm -r $BASE_DIR/.grails/ivy-cache/org.grails.plugins/drools/*
echo "Deleting test application directory ...."
cd $TEST_DIR
rm -r $APP_NAME
echo "Creating test application ...."
grails create-app $APP_NAME
cd $APP_NAME
echo "Modifying BuildConfig.groovy to resolve test and plugin dependencies ...."
if [ $CONTAINER == "jetty" ]; then
perl -i -pe "s/build.*:tomcat:.*$/$JETTY_PLUGIN/" $APP_DIR/grails-app/conf/BuildConfig.groovy
perl -i -pe "s/test: .*$/test: false,/" $APP_DIR/grails-app/conf/BuildConfig.groovy
fi
perl -i -pe "s/grails.project.dependency.resolution/grails.plugin.drools.drlFileLocation = 'drools-rules'\ngrails.project.dependency.resolution/g" $APP_DIR/grails-app/conf/BuildConfig.groovy
perl -i -pe "s!repositories {!$REPOSITORIES!g" $APP_DIR/grails-app/conf/BuildConfig.groovy
perl -i -pe "s/plugins {/$TEST_DEP_PLUGIN/g" $APP_DIR/grails-app/conf/BuildConfig.groovy
perl -i -pe "s/dependencies {.*$/$TEST_DEP/g" $APP_DIR/grails-app/conf/BuildConfig.groovy
echo "Copying files ...."
cp -r $SOURCE_DIR/grails-app/conf/UrlMappings.groovy $APP_DIR/grails-app/conf/
cp -r $SOURCE_DIR/grails-app/conf/DroolsConfig.groovy $APP_DIR/grails-app/conf/
cp -r $SOURCE_DIR/grails-app/domain/* $APP_DIR/grails-app/domain/
rm $APP_DIR/grails-app/domain/grails/plugin/drools_sample/DroolsRule.groovy
cp -r $SOURCE_DIR/grails-app/controllers/* $APP_DIR/grails-app/controllers/
cp -r $SOURCE_DIR/grails-app/views/test $APP_DIR/grails-app/views/
cp -r $SOURCE_DIR/src/resources $APP_DIR/src/
cp -r $SOURCE_DIR/test/functional $APP_DIR/test/
if [ $GRAILS_VER == "2.2.5" ]; then
grails refresh-dependencies
find $BASE_DIR/.grails/ivy-cache/org.springframework -type f -name *3.2.11* | xargs rm
find $BASE_DIR/.grails/ivy-cache/org.springframework -type f -name *4.0.7* | xargs rm
grails compile
else
grails compile
fi
echo "Creating Drools Domain ...."
grails create-drools-domain $PACKAGE.DroolsRule
cp -r $SOURCE_DIR/grails-app/conf/BootStrap.groovy $APP_DIR/grails-app/conf/
grails clean
grails -Dgeb.env=chrome test-app functional:
}
runTest() {
CONTAINER=$1
GRAILS_VER=$2
GEB_DIR=$3
echo ""
echo "Testing Grails $GRAILS_VER in $CONTAINER ..."
(
testApp $CONTAINER $GRAILS_VER $PLUGIN_VER
)
mkdir $GEB_DIR/$CONTAINER
mkdir $GEB_DIR/$CONTAINER/$GRAILS_VER
cp $APP_DIR/target/test-reports/html/stylesheet.css $GEB_DIR/$CONTAINER
cp -r $APP_DIR/target/test-reports/html $GEB_DIR/$CONTAINER/$GRAILS_VER
echo "<div class="clear"></div><p><a href=\"file://$GEB_DIR/$CONTAINER/$GRAILS_VER/html/index.html\">$GRAILS_VER</a></p>" >> $HTMLFILE
SUMMARY="$(cat $APP_DIR/target/test-reports/plain/TEST-functional-spock-IndexPageSpec.txt | sed -n 2p)"
echo "<p>$SUMMARY</p><p></p>" >> $HTMLFILE
}
runJettyTest() {
container="jetty"
echo "<h1>$container</h1>" >> $HTMLFILE
if [ $1 == "all" ]; then
for version in "${JETTY_VERSIONS[@]}"; do
runTest $container $version $GEB_DIR
done
else
runTest $container $1 $GEB_DIR
fi
}
finishHTML() {
GEB_DIR=$1
cp $APP_DIR/target/test-reports/html/stylesheet.css $GEB_DIR
END_TIME=$(date +"%Y-%m-%d %T")
END_SECONDS=$(date +"%s")
SECONDS_TOTAL=$(($END_SECONDS-$START_SECONDS))
MINUTES=$(($SECONDS_TOTAL / 60))
if [ $MINUTES -eq 1 ]; then
MINUTES_TEXT="$MINUTES minute"
else
MINUTES_TEXT="$MINUTES minutes"
fi
SECONDS=$(($SECONDS_TOTAL % 60))
if [ $SECONDS -eq 1 ]; then
SECONDS_TEXT="$SECONDS second"
else
SECONDS_TEXT="$SECONDS seconds"
fi
ELAPSED_TIME="$MINUTES_TEXT and $SECONDS_TEXT"
perl -i -pe "s/START_TIME/$START_TIME/" $HTMLFILE
perl -i -pe "s/END_TIME/$END_TIME/" $HTMLFILE
perl -i -pe "s/ELAPSED_TIME/$ELAPSED_TIME/" $HTMLFILE
echo "$HTML_END" >> $HTMLFILE
echo ""
echo "Tests finished."
echo "Open the file below in your browser for the test results:"
echo "$HTMLFILE"
openBrowser "$HTMLFILE"
}
packagePlugin
if [ $1 == "all" ]; then
# testApp using all containers
GEB_DIR=$TEST_DIR/droolsTest-ALL-CONTAINERS-$DATE
mkdir $GEB_DIR
HTMLFILE=$GEB_DIR/index.html
touch $HTMLFILE
echo "$HTML_START" >> $HTMLFILE
echo "<h1>Test Results by Container</h1></div><div class=clear></div>" >> $HTMLFILE
for container in "${CONTAINERS[@]}"; do
if [ $container == "jetty" ]; then
runJettyTest $2
else
echo "<h1>$container</h1>" >> $HTMLFILE
if [ $2 == all ]; then
for version in "${VERSIONS[@]}"; do
runTest $container $version $GEB_DIR
done
else
runTest $container $2 $GEB_DIR
fi
fi
done
finishHTML $GEB_DIR
exit 0
else
# testApp using a specific container
CONTAINER=$1
GEB_DIR=$TEST_DIR/droolsTest-$CONTAINER-$DATE
mkdir $GEB_DIR
HTMLFILE=$GEB_DIR/index.html
touch $HTMLFILE
echo "$HTML_START" >> $HTMLFILE
echo "<h1>Test Results for $CONTAINER</h1></div><div class=clear></div>" >> $HTMLFILE
if [ $CONTAINER == "jetty" ]; then
runJettyTest $2
else
if [ $2 == all ]; then
for version in "${VERSIONS[@]}"; do
runTest $CONTAINER $version $GEB_DIR
done
else
runTest $CONTAINER $2 $GEB_DIR
fi
fi
finishHTML $GEB_DIR
exit 0
fi