forked from craftercms/craftercms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
757 lines (681 loc) · 29.2 KB
/
build.gradle
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
import java.nio.charset.Charset
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardWatchEventKinds
import java.io.BufferedReader;
import java.nio.file.StandardOpenOption;
import java.net.HttpURLConnection;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.lang3.SystemUtils;
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.apache.commons', name: 'commons-text', version: '1.1'
classpath group: 'org.apache.commons', name: 'commons-lang3', version: '3.6'
}
}
plugins {
id "de.undercouch.download" version "3.1.2"
}
def isWin=System.getProperty('os.name').toLowerCase().contains('windows')
def isOSX=System.getProperty('os.name').toLowerCase().contains('mac')
def isNix=(System.getProperty('os.name').toLowerCase().contains('nix') || System.getProperty('os.name').toLowerCase().contains('aix') || System.getProperty('os.name').toLowerCase().contains('nux'))
def commandLinePrefix = []
def startUpFile = "./startup.sh"
def shutDownFile ="./shutdown.sh"
if (isWin) {
startUpFile = "startup.bat"
shutDownFile = "shutdown.bat"
commandLinePrefix =["cmd","/c"]
}
def getModule() {
if (project.hasProperty("moduleName")) {
def moduleName=project.property("moduleName")
moduleName=moduleName.trim().toLowerCase()
return moduleName.trim().isEmpty()? "all" : moduleName
} else {
return "all"
}
}
def getEnv(){
if (project.hasProperty("env")) {
def enviromentName=project.property("env")
enviromentName=enviromentName.trim().toLowerCase()
return enviromentName.trim().isEmpty()? "all" : enviromentName
} else {
return "all"
}
}
def isAllEnvs() {
return getEnv().equalsIgnoreCase("all")
}
ext {
/** Unzip Properties **/
tomcatVersion=project.hasProperty("tomcat.version")? project.property("tomcat.version") : "8.5.6"
solrVersion=project.hasProperty("solr.version")? project.property("solr.version") : "6.4.1"
downloadDir=project.hasProperty("downloadDir")? project.property("downloadDir") : "./downloads/"
/** Environment Building properties **/
authEnv=project.hasProperty("authoring.root")? project.property("authoring.root") : "./crafter-authoring/"
deliveryEnv=project.hasProperty("delivery.root")? project.property("delivery.root") : "./crafter-delivery/"
includeProfile=project.hasProperty("crafter.profile")? project.property("crafter.profile") : false
includeSocial=project.hasProperty("crafter.social")? project.property("crafter.social") : false
/** Social Need Profile **/
if (includeSocial) {
includeProfile=true
}
//Authoring
authTomcatPort=project.hasProperty("authoring.tomcat.http.port")? project.property("authoring.tomcat.http.port") : 8080
authTomcatShutdownPort=project.hasProperty("authoring.tomcat.shutdown.port")? project.property("authoring.tomcat.shutdown.port") : 8005
authTomcatAJPPort=project.hasProperty("authoring.tomcat.ajp.port")? project.property("authoring.tomcat.ajp.port") : 8009
authTomcatSSLPort=project.hasProperty("authoring.tomcat.https.port")? project.property("authoring.tomcat.https.port") : 8443
authTomcatDebug=project.hasProperty("authoring.tomcat.debug.port")? project.property("authoring.tomcat.debug.port") : 8000
authMongoDBPort=project.hasProperty("authoring.mongo.port")? project.property("authoring.mongo.port") : 27020
authSolrPort=project.hasProperty("authoring.solr.port")? project.property("authoring.solr.port") : 8694
authSolrDebugPort=project.hasProperty("authoring.solr.debug.port")? project.property("authoring.solr.debug.port") : 5005
authMariaDbPort=project.hasProperty("authoring.mariadb.port")? project.property("authoring.mariadb.port") : 33306
authDeployerPort=project.hasProperty("authoring.deployer.port")? project.property("authoring.deployer.port") : 9191
authDeployerDebugPort=project.hasProperty("authoring.deployer.debug.port")? project.property("authoring.deployer.debug.port") : 5000
authDeploymentDir=project.hasProperty("authoring.deployment.dir")? project.property("authoring.deployment.dir") : "data/repos/sites"
// Delivery
deliverySolrPort=project.hasProperty("delivery.solr.port")? project.property("delivery.solr.port") : 8695
deliverySolrDebugPort=project.hasProperty("delivery.solr.debug.port")? project.property("delivery.solr.debug.port") : 5006
deliveryDeployerPort=project.hasProperty("delivery.deployer.port")? project.property("delivery.deployer.port") : 9192
deliveryDeployerDebugPort=project.hasProperty("delivery.deployer.debug.port")? project.property("delivery.deployer.debug.port") : 5001
deliveryDeploymentDir=project.hasProperty("delivery.deployment.dir")? project.property("delivery.deployment.dir") : "data/repos/sites"
deliveryTomcatPort=project.hasProperty("delivery.tomcat.http.port")? project.property("delivery.tomcat.http.port") : 9080
deliveryTomcatShutdownPort=project.hasProperty("delivery.tomcat.shutdown.port")? project.property("delivery.tomcat.shutdown.port") : 9005
deliveryTomcatAJPPort=project.hasProperty("delivery.tomcat.ajp.port")? project.property("delivery.tomcat.ajp.port") : 9009
deliveryTomcatSSLPort=project.hasProperty("delivery.tomcat.https.port")? project.property("delivery.tomcat.https.port") : 9443
deliveryTomcatDebugPort=project.hasProperty("delivery.tomcat.debug.port")? project.property("delivery.tomcat.debug.port") : 9000
deliveryMongoDBPort=project.hasProperty("delivery.mongodb.port")? project.property("delivery.mongodb.port") : 28020
/** Git properties **/
gitURLTemplate=project.hasProperty("crafter.git.url")? project.property("crafter.git.url") : "https://github.com/craftercms/"
gitSourceBranch=project.hasProperty("crafter.git.branch")? project.property("crafter.git.branch") : "master"
gitRepo=project.hasProperty("crafter.git.remote")? project.property("crafter.git.remote") : "origin"
shallowClone=project.hasProperty("crafter.git.shallowClone")? project.property("crafter.git.shallowClone") : false
studioUIFromRepo=project.hasProperty("crafter.ui.repo")? project.property("crafter.ui.repo") : false
forceDeploy=project.hasProperty("forceDeploy")? project.property("forceDeploy") : false
keepBin=project.hasProperty("keepBin")? project.property("keepBin") : false
testingPlatform=project.hasProperty("crafter.testing.platform")? project.property("crafter.testing.platform") : System.properties['os.name'].toString().toLowerCase().replaceAll(" ","-")
chromeDriverVersion=project.hasProperty("crafter.testing.chrome")? project.property("crafter.testing.chrome") : 2.31
browserToTest=project.hasProperty("crafter.testing.browser")? project.property("crafter.testing.browser") : "chrome"
testArtifacts=project.hasProperty("crafter.unittest") ? project.property("crafter.unittest") : false
/** Clonable Artifacts **/
VALID_MODULES=["commons", "core", "search", "profile", "engine", "deployer", "studio", "social", "studio-ui", "test-suite"]
/** Deployable Artifacts **/
VALID_DEPLOYABLE_MODULES=[
"search":"./src/search/crafter-search-server/target/crafter-search.war",
"profile":"./src/profile/server/target/crafter-profile.war",
"engine":"./src/engine/target/ROOT.war",
"deployer":"./src/deployer/target/crafter-deployer.jar",
"studio":"./src/studio/target/studio.war",
"social":"./src/social/server/target/crafter-social.war"]
WINDOWS_EDGE_DRIVER_URL = [
"15063" : "https://download.microsoft.com/download/3/4/2/342316D7-EBE0-4F10-ABA2-AE8E0CDF36DD/MicrosoftWebDriver.exe",
"14393" : "https://download.microsoft.com/download/3/2/D/32D3E464-F2EF-490F-841B-05D53C848D15/MicrosoftWebDriver.exe",
"10586" : "https://download.microsoft.com/download/C/0/7/C07EBF21-5305-4EC8-83B1-A6FCC8F93F45/MicrosoftWebDriver.msi",
"10240" : "https://download.microsoft.com/download/8/D/0/8D0D08CF-790D-4586-B726-C6469A9ED49C/MicrosoftWebDriver.msi"
]
}
apply from:"downloads.gradle"
apply from:"environments.gradle"
task("utils"){
description "builds the utils project and copies the utils jar file to the environment"
doLast {
buildModule(commandLinePrefix, "utils", "./")
copy {
from "./utils/target/craftercms-utils.jar"
into "${authEnv}/bin"
}
copy {
from "./utils/target/craftercms-utils.jar"
into "${deliveryEnv}/bin"
}
}
}
task("upgrade"){
description "Upgrades the installed tomcat version, solr scripts, etc. without deleting your data then builds and deploys"
doLast {
def authEnvFolder = new File("${authEnv}")
if (authEnvFolder.exists()) {
authEnvFolder.eachFile { dir ->
if (!dir.getName().equalsIgnoreCase("data")) {
if (!dir.isFile()) {
dir.deleteDir()
} else {
dir.delete()
}
}
}
}
update.execute();
forceDeploy=true
build.execute()
deploy.execute()
}
}
task("init"){
description "Clones Crafter CMS stack"
doFirst{
def module = getModule();
}
doLast {
if (module.equals("all")) {
VALID_MODULES.each {
cloneModule(commandLinePrefix, it).execute()
}
} else if (VALID_MODULES.contains(module)) {
cloneModule(commandLinePrefix, module).execute()
} else {
throw new InvalidUserDataException("${module} is not a valid module, please one of ${VALID_MODULES}")
}
}
}
task("update") {
description "Update the various modules of Crafter CMS"
doFirst{
def module = getModule();
}
doLast {
if (module.equals("all")) {
VALID_MODULES.each {
updateModule(commandLinePrefix, it).execute()
}
} else if (VALID_MODULES.contains(module)) {
updateModule(commandLinePrefix, module).execute()
} else {
throw new InvalidUserDataException("${module} is not a valid module, please use one of ${VALID_MODULES}")
}
}
}
task("selfupdate") {
description "Updates the Crafter CMS project"
doLast {
def arry = commandLinePrefix + ["git", "pull", gitRepo, gitSourceBranch]
executeProcess(arry,".")
}
}
task("start") {
description "Start Crafter CMS"
doLast {
def env = getEnv()
println "Running for the first time might take longer while fetching OS dependent requirements."
switch (env) {
case "all":
if(!file(authEnv).exists() || !file(deliveryEnv).exists()){
throw new InvalidUserDataException("Neither enviroment ('authoring'/'delivery') are deployed. Please run deploy before 'start'.")
}
startAuth(commandLinePrefix, startUpFile).execute()
startDelivery(commandLinePrefix, startUpFile).execute()
break
case "authoring":
if (!file(authEnv).exists()) {
throw new InvalidUserDataException("The 'authoring' enviroment is not deployed. Please run 'deploy -Penv=authoring' before 'start'.")
}
startAuth(commandLinePrefix, startUpFile).execute()
break
case "delivery":
if (!file(deliveryEnv).exists()) {
throw new InvalidUserDataException("The 'delivery' enviroment is not deployed. Please run 'deploy -Penv=delivery' before 'start'.")
}
startDelivery(commandLinePrefix, startUpFile).execute()
break
default:
throw new InvalidUserDataException("'${env}' is not a valid environment, please use 'authoring' or 'delivery'.")
}
}
}
task("stop") {
description "Stop Crafter CMS"
doLast {
def env = getEnv()
switch (env) {
case "all":
if (!file(authEnv).exists() || !file(deliveryEnv).exists()) {
throw new InvalidUserDataException("Neither enviroment ('authoring'/'delivery') are deployed. Please run deploy before 'stop'.")
}
stopAuth(commandLinePrefix,shutDownFile).execute()
stopDelivery(commandLinePrefix, shutDownFile).execute()
case "authoring":
if (!file(authEnv).exists()) {
throw new InvalidUserDataException("The 'authoring' enviroment is not deployed. Please run 'deploy -Penv=authoring' before 'stop'.")
}
stopAuth(commandLinePrefix, shutDownFile).execute()
break
case "delivery":
if (!file(deliveryEnv).exists()) {
throw new InvalidUserDataException("The 'delivery' enviroment is not deployed. Please run 'deploy -Penv=delivery' before 'stop'.")
}
stopDelivery(commandLinePrefix, shutDownFile).execute()
break
default:
throw new InvalidUserDataException("'${env}' is not a valid environment, please use 'authoring' or 'delivery'.")
}
}
}
task("clean") {
description "Clean Crafter CMS stack"
doFirst {
def module = getModule();
}
doLast {
if (module.equals("all")) {
VALID_MODULES.each {
if(!(it.equalsIgnoreCase("studio-ui")||(it.equalsIgnoreCase("test-suite")))) { // Not a pom project ignore
cleanModule(commandLinePrefix, it).execute()
}
}
} else if (VALID_MODULES.contains(module)) {
if(!(module.equalsIgnoreCase("studio-ui")||(module.equalsIgnoreCase("test-suite")))) { // Not a pom project ignore
cleanModule(commandLinePrefix, module).execute()
}
} else {
throw new InvalidUserDataException("${module} is not a valid module, please use one of ${VALID_MODULES}")
}
}
}
task("build") {
description "Builds Crafter CMS"
doFirst {
def module = getModule();
}
doLast {
if (module.equals("all")) {
VALID_MODULES.each {
if (!(it.equalsIgnoreCase("studio-ui")||(it.equalsIgnoreCase("test-suite")))) {
buildModule(commandLinePrefix, it).execute()
}
}
} else if (VALID_MODULES.contains(module)) {
if (!(module.equalsIgnoreCase("studio-ui")||(module.equalsIgnoreCase("test-suite")))) {
buildModule(commandLinePrefix, module).execute()
}
} else {
throw new InvalidUserDataException("${module} is not a valid module, please use one of ${VALID_MODULES}")
}
}
}
task("test") {
description "Builds and run tests"
doFirst {
def driverPath=""
switch (browserToTest.toString().toLowerCase()){
case "chrome":
downloadChromeDriver.execute()
if(SystemUtils.IS_OS_WINDOWS){
driverPath=file("./src/test-suite/bin/${browserToTest}-${testingPlatform}/chromedriver.exe")
}else{
driverPath=file("./src/test-suite/bin/${browserToTest}-${testingPlatform}/chromedriver")
}
break;
case "edge":
downloadEdgeDriver.execute();
driverPath=file("./src/test-suite/bin/${browserToTest}/MicrosoftWebDriver.exe")
break
default:
driverPath=askForPath();
}
if(!file("./src/test-suite/test-properties.properties").exists()){
def properties = []
properties.add("webBrowser=${browserToTest}")
properties.add("baseUrl=http://localhost:8080/studio/#/login")
properties.add("${browserToTest}.driver.path=${StringEscapeUtils.escapeJava(file(driverPath).absolutePath)}")
Files.write(Paths.get("./src/test-suite/test-properties.properties"), properties, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
}
}
doLast{
startAuth(commandLinePrefix, startUpFile)
try {
// waitUntilAuthIsUp(10)//10*30sec
buildModule(commandLinePrefix,
"test-suite", "./src/",
["-Dfile=src/test/resources/testng.xml,src/test/resources/testngcomplexscenarios.xml,src/test/resources/testngAPI.xml"],
true)
}catch (GradleException ex){ // no nothing
} finally {
stopAuth(commandLinePrefix, shutDownFile)
}
}
}
task("deploy") {
description "Setup the Crafter CMS environment/s"
doLast {
def module = getModule()
def env = getEnv()
switch (env){
case "all":
checkEnvWD(authEnv, "authoring")
checkEnvWD(deliveryEnv, "delivery")
break
case "authoring":
checkEnvWD(authEnv, env)
break
case "delivery":
checkEnvWD(deliveryEnv, env)
break
default:
throw new InvalidUserDataException("'${env}' is not a valid environment, please use 'authoring' or 'delivery'.")
}
if (module.equals("all")) {
VALID_DEPLOYABLE_MODULES.keySet().each {
if (isAllEnvs()) {
deployModule(commandLinePrefix, it, "authoring").execute()
deployModule(commandLinePrefix, it, "delivery").execute()
} else {
deployModule(commandLinePrefix, it, env).execute()
}
if(!keepBin) {
file(VALID_DEPLOYABLE_MODULES[it]).delete()
}
}
} else if (VALID_DEPLOYABLE_MODULES.containsKey(module)) {
if (isAllEnvs()) {
deployModule(commandLinePrefix, module, "authoring").execute()
deployModule(commandLinePrefix, module, "delivery").execute()
} else {
deployModule(commandLinePrefix, module, env).execute()
}
if (!keepBin) {
file(VALID_DEPLOYABLE_MODULES[module]).delete()
}
} else {
throw new InvalidUserDataException("${module} is not a valid module, please use one of ${VALID_DEPLOYABLE_MODULES.keySet()}")
}
utils.execute()
}
}
task("bundle") {
description "Builds a deployable and distributable bundle of Crafter CMS"
doLast {
def env = getEnv()
switch (env) {
case "all":
pack(authEnv, "authoring")
pack(deliveryEnv, "delivery")
break
case "authoring":
pack(authEnv, "authoring")
break
case "delivery":
pack(deliveryEnv, "delivery")
break
default:
throw new InvalidUserDataException("'${env}' is not a valid environment, please use 'authoring' or 'delivery'.")
}
}
}
def cleanModule(commandLinePrefix, module) {
def ctask=tasks.findByPath("clean${module}")
if (ctask!= null) {
return ctask
} else {
return tasks.create("clean${module}") {
executeProcess(commandLinePrefix + commandLinePrefix + ["mvn", "clean"], "./src/${module}".toString())
}
}
}
def updateModule(commandLinePrefix, module) {
def btask=tasks.findByPath("update${module}")
if (btask!= null) {
return btask
} else {
return tasks.create("update${module}") {
if (!file("./src/${module}").exists()) {
throw new InvalidUserDataException("Module ${module} is not initialized. Please use 'update' to initialize it.")
} else {
def arry = commandLinePrefix + ["git", "pull", gitRepo, gitSourceBranch]
executeProcess(arry,"./src/${module}".toString())
}
}
}
}
def cloneModule(commandLinePrefix, module){
def btask=tasks.findByPath("clone${module}")
if (btask!= null) {
return btask
} else {
return tasks.create("clone${module}") {
def finalUrl = "${gitURLTemplate}${module}.git".toString()
def path = "src/${module}".toString()
def gitCloneCmd = ["git","clone"]
if(shallowClone){
gitCloneCmd.add("--depth")
gitCloneCmd.add("1")
}
def arry = commandLinePrefix + gitCloneCmd+["-b",gitSourceBranch,finalUrl,path]
if (file(path).exists()) {
println ("Module ${module} has already been initialized, please use " +
"'update' to update it.")
} else {
println "Cloning: ${module}, branch: ${gitSourceBranch}, url: ${finalUrl}"
executeProcess(arry,".")
}
}
}
}
def startAuth(commandLinePrefix, startUpFile) {
def btask = tasks.findByPath("startAuth")
if (btask!= null){
return btask
} else {
tasks.create("startAuth") {
executeProcess(commandLinePrefix + [startUpFile], "$authEnv/bin",true)
}
}
}
def startDelivery(commandLinePrefix, startUpFile){
def btask=tasks.findByPath("startDelivery")
if (btask!= null) {
return btask
} else {
tasks.create("startDelivery") {
executeProcess(commandLinePrefix + [startUpFile], "$deliveryEnv/bin", true)
}
}
}
def stopAuth(commandLinePrefix, shutDownFile) {
def btask = tasks.findByPath("stopAuth")
if (btask!= null) {
return btask
} else {
tasks.create("stopAuth") {
executeProcess(commandLinePrefix + [shutDownFile], "$authEnv/bin", true)
}
}
}
def stopDelivery(commandLinePrefix, shutDownFile) {
def btask=tasks.findByPath("stopDelivery")
if (btask!= null) {
return btask
} else {
tasks.create("stopDelivery") {
executeProcess(commandLinePrefix + [shutDownFile], "$deliveryEnv/bin", true)
}
}
}
def buildModule(commandLinePrefix, module, path="./src/", commandLinePost=[], forceTest=false) {
def btask=tasks.findByPath("build${module}")
def actualCommandLinePost = [];
actualCommandLinePost.addAll(commandLinePost)
if(!testArtifacts && !forceTest){ //ForceTest is needed to make test-suite run since, well they are tests
actualCommandLinePost.add("-Dmaven.test.skip=true")
// Ignore integration test to avoid starting mongo and jetty for nothing
if(module.equalsIgnoreCase("search")){
actualCommandLinePost.add("-pl")
actualCommandLinePost.add("!crafter-search-itest")
}else if(module.equalsIgnoreCase("profile")){
actualCommandLinePost.add("-pl")
actualCommandLinePost.add("!integration-tests")
}
}
if (btask!= null) {
return btask
} else {
return tasks.create("build${module}") {
if(module.equalsIgnoreCase("studio") && !studioUIFromRepo) {
actualCommandLinePost.add("-Dstudio.ui.path=../studio-ui/".toString())
actualCommandLinePost.add("-Dexec.skip=true")
}
// Always do a Clean build, never trust caches or FS.
def array=commandLinePrefix + commandLinePrefix + ["mvn", "clean", "install"] + actualCommandLinePost
executeProcess(array, "${path}${module}".toString())
}
}
}
def deployBinary(deployable, env){
if (deployable.exists()) {
def path = env.equals("authoring")? authEnv : deliveryEnv
path += deployable.absolutePath.endsWith(".jar")? "bin/crafter-deployer/" : "bin/apache-tomcat/webapps/"
path += deployable.name
delete {
delete path
delete path.take(path.lastIndexOf('.'))
}
copy {
from deployable.absolutePath
into path.take(path.lastIndexOf('/'))
}
} else {
println "WARN: You haven't built ${module} module"
}
}
def deployModule(commandLinePrefix, module, env) {
def dtask=tasks.findByPath("deploy${module}${env}")
if (dtask!= null) {
return dtask
} else {
return tasks.create("deploy${module}${env}") {
println "Deploy ${module} to ${env}"
if (module.equals("studio") && env.equals("delivery")) {
println "Ignoring module 'studio' can not be deployed in environment 'delivery'"
} else if((module.equals("profile") && !includeProfile) || (module.equals("social") && !includeSocial)) {
println "Ignoring module '$module' not enabled for environment '$env'"
} else {
def deployable = file(VALID_DEPLOYABLE_MODULES[module])
deployBinary(deployable, env)
if(module.equalsIgnoreCase("profile")){
deployBinary(file("./src/profile/admin-console/target/crafter-profile-admin.war"), env)
} else if (module.equalsIgnoreCase("social")) {
deployBinary(file("./src/social/admin/target/crafter-social-admin.war"), env)
}
}
}
}
}
def checkEnvWD(path, env) {
def ddir = file(path)
if (!ddir.exists() || forceDeploy) {
ddir.mkdir()
def deployerDir = file("${path}/bin/crafter-deployer")
deployerDir.mkdir()
downloadTomcat.execute()
downloadSolr.execute()
if (env.equals("authoring")) {
authoringEnvironment.execute()
} else if (env.equals("delivery")) {
deliveryEnvironment.execute()
}
}
}
def pack(environmentPath,envName){
def dtask=tasks.findByPath("tar${envName}")
if (dtask!= null) {
return dtask
} else {
def zipTask = tasks.findByPath("zip${envName}")
if (zipTask != null) {
zipTask.execute()
} else {
tasks.create("zip${envName}", Zip.class) {
from(environmentPath) {
into("crafter")
}
archiveName "crafter-cms-${envName}.zip"
fileMode null
dirMode null
includeEmptyDirs true
metadataCharset "UTF-8"
caseSensitive false
destinationDir(file("bundles/"))
}.execute()
}
def tarTask = tasks.findByPath("tar${envName}")
if (tarTask != null) {
tarTask.execute()
} else {
tasks.create("tar${envName}", Tar.class) {
from(environmentPath) {
into("crafter")
}
archiveName "crafter-cms-${envName}.tar.gz"
fileMode null
dirMode null
includeEmptyDirs true
caseSensitive false
compression = Compression.GZIP
destinationDir(file("bundles/"))
}.execute()
}
}
}
def executeProcess(command, workingDir, printOutputUntilFinish = false) {
ProcessBuilder pb = new ProcessBuilder(command)
def processOutput = File.createTempFile("process", "out")
pb.directory(new File(workingDir))
pb.redirectOutput(processOutput)
Process proc = pb.start();
watchProcessOutput(proc,processOutput)
proc.waitFor()
if (proc.exitValue() != 0) {
throw new GradleException("${command} @ ${workingDir} return a non-zero value (${proc.exitValue()})")
}
}
// Poor's man tail (but get's the job done
def watchProcessOutput(process, processOutputFile){
Thread.start {
def reader=null
if(System.getProperty('os.name').toLowerCase().contains('windows')){
reader = Files.newBufferedReader(Paths.get(processOutputFile.path), Charset.forName("ISO-8859-1"))
}else{
reader = Files.newBufferedReader(Paths.get(processOutputFile.path), Charset.forName("UTF-8"))
}
while(process.alive) {
// Thread.sleep(100)
def line=null
while((line=reader.readLine()) != null) {
println line
}
}
processOutputFile.delete()
}
}
def askForPath(){
def console = System.console();
def inputPath = console.readLine("> Please enter path for selemiun driver of ${browserToTest} ")
if(!file(inputPath).exists()){
console.println("${inputPath} does not exist, please enter a new valid path");
askForPath();
}
return inputPath
}
def waitUntilAuthIsUp(tryThinsManyTimes){
if(tryThinsManyTimes<=0){
return false
}else{
try{
URL url = new URL("http://localhost:${authTomcatPort}/studio");
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
HttpURLConnection.setFollowRedirects(false);
huc.setConnectTimeout(30000);
huc.setRequestMethod("GET");
huc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)");
huc.connect();
return true
}catch(java.net.SocketTimeoutException | java.net.ConnectException ex){
println "Studio is not Ready yet trying again"
waitUntilAuthIsUp(tryThinsManyTimes-1)
}
}
}