forked from craftercms/craftercms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
773 lines (685 loc) · 31.5 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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
import org.apache.commons.lang3.SystemUtils
import org.apache.commons.text.StringEscapeUtils
import org.apache.commons.io.input.Tailer
import org.apache.commons.io.input.TailerListenerAdapter
import java.nio.charset.Charset
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardOpenOption
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'
classpath group: 'commons-io', name: 'commons-io', version: '2.6'
classpath 'org.ajoberstar:grgit:1.1.0'
}
}
plugins {
id "de.undercouch.download" version "3.1.2"
}
project.version = "3.0.16" // craftercms version flag
def isWin = System.getProperty('os.name').toLowerCase().contains('windows')
def commandLinePrefix = []
def startUpFile = "./startup.sh"
def shutDownFile = "./shutdown.sh"
if (isWin) {
startUpFile = "startup.bat"
shutDownFile = "shutdown.bat"
commandLinePrefix = ["cmd", "/c"]
}
ext {
/** Subprocess Properties **/
processLogFile = ".gradle.log"
processTailReadDelay = 100
processTailFinishDelay = 1000
/** Unzip Properties **/
groovyVersion = project.hasProperty("groovy.version") ? project.property("groovy.version") : "2.5.0"
tomcatVersion = project.hasProperty("tomcat.version") ? project.property("tomcat.version") : "8.5.24"
solrVersion = project.hasProperty("solr.version") ? project.property("solr.version") : "6.6.5"
mariadb4jVersion = project.hasProperty("mariadb4j.version") ? project.property("mariadb4j.version") : "2.2.7"
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
}
if (project.hasProperty("debug")) {
startUpFile = "./debug.sh"
if (isWin) {
startUpFile = "debug.bat"
}
}
//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
authSMTPPort = project.hasProperty("authoring.studio.smtp.port") ? project.property("authoring.studio.smtp.port") : 25
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" // craftercms branch flag
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.40
browserToTest = project.hasProperty("crafter.testing.browser") ? project.property("crafter.testing.browser") : "chrome"
testArtifacts = project.hasProperty("crafter.unittest") ? project.property("crafter.unittest") : false
testingSuites = project.hasProperty("crafter.testing.suites") ? project.property("crafter.testing.suites") :
"src/test/resources/testng_SanityTest.xml"+
",src/test/resources/testng_StudioAccountManagement.xml"+
",src/test/resources/testng_StudioContent.xml" +
",src/test/resources/testng_StudioContextualNavigation.xml"+
",src/test/resources/testng_StudioSiteDropdown.xml"+
",src/test/resources/testng_StudioDashboard.xml"+
",src/test/resources/testng_StudioGeneral.xml"+
",src/test/resources/testng_StudioPreviewTools.xml"+
",src/test/resources/testng_StudioSiteConfig.xml"+
",src/test/resources/testng_StudioSites.xml"+
",src/test/resources/testng_StudioUsers.xml"+
",src/test/resources/testng_StudioLoginLogout.xml"+
",src/test/resources/testng_StudioAPI.xml"
startMongodb = project.hasProperty("startMongodb") ? project.property("startMongodb") : false // Does not really.
silentBuild = project.hasProperty("crafter.build.silent") ? project.property("crafter.build.silent") : false
typeOfBundle = project.hasProperty("crafter.bundle.archive") ? project.property("crafter.bundle.archive") : "both"
/** Cloneable Artifacts **/
VALID_MODULES = ["commons", "core", "search", "profile", "engine", "deployer", "studio", "social", "studio-ui", "test-suite", "plugin-maker"]
/** 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-exec.jar",
"studio" : "./src/studio/target/studio.war",
"social" : "./src/social/server/target/crafter-social.war"]
WINDOWS_EDGE_DRIVER_URL = [
"16299": "https://download.microsoft.com/download/D/4/1/D417998A-58EE-4EFE-A7CC-39EF9E020768/MicrosoftWebDriver.exe",
"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"
]
WINDOWS_IE_DRIVER_URL= "http://selenium-release.storage.googleapis.com/3.8/IEDriverServer_x64_3.8.0.zip"
git = org.ajoberstar.grgit.Grgit.open(dir: ".")
gitRevisionId = git.head().id.substring(0, 6)
}
apply from: "downloads.gradle"
apply from: "environments.gradle"
def deliveryDeps = []
def cleanDeps = []
def buildDeps = []
def initDeps = []
def updateDeps = []
def startDeps = []
def stopDeps = []
def statusDeps = []
def preTestDeps = browserToTest.equalsIgnoreCase("chrome") ? [downloadChromeDriver] : [downloadEdgeDriver,downloadIEDriver]
def bundleDeps = []
def envs = []
def envDepends = []
if (getEnv().equalsIgnoreCase("all")) {
envs = ["authoring", "delivery"]
envDepends = [authoringEnvironment, deliveryEnvironment]
} else {
envs = [getEnv()]
envDepends = [tasks.findByName("${getEnv()}Environment")]
}
/** Some blackmagic here and there creates module_build tasks **/
def buildModules = []
def deployModules = [:]
if (project.hasProperty("moduleName")) {
buildModules = project.property("moduleName").toLowerCase().split(",")
buildModules.each {
deployModules.put(it, VALID_DEPLOYABLE_MODULES[it])
}
} else {
buildModules = VALID_MODULES
deployModules = VALID_DEPLOYABLE_MODULES
}
buildModules.each { module ->
// Creates the Clean Task
if (!tasks.findByPath("${module}_clean")) {
task "${module}_clean" doLast({
def array = commandLinePrefix + ["mvn", "clean"]
executeProcess(array, "./src/${module}".toString())
})
} else {
logger.debug("Task ${module}_build already exists")
}
// Creates the Build Tasks
if (!tasks.findByPath("${module}_build")) {
if (!module.equalsIgnoreCase("test-suite")) {
task "${module}_build" doLast({
def actualCommandLinePost = [];
if (!testArtifacts) {
actualCommandLinePost.add("-Dmaven.test.skip=true")
}
if (module.equalsIgnoreCase("search")) {
actualCommandLinePost.add("-pl")
actualCommandLinePost.add("!crafter-search-itest")
} else if (module.equalsIgnoreCase("profile")) {
actualCommandLinePost.add("-pl")
if (!includeProfile) {
actualCommandLinePost.add("!admin-console,!integration-tests,!server")
} else {
actualCommandLinePost.add("!integration-tests")
}
}
if (module.equalsIgnoreCase("studio") && !studioUIFromRepo) {
actualCommandLinePost.add("-Dstudio.ui.path=../studio-ui/".toString())
actualCommandLinePost.add("-Dexec.skip=true")
}
def array = commandLinePrefix + ["mvn", "install"] + actualCommandLinePost
executeProcess(array, "./src/${module}".toString())
})
// Creates the Dependencies Array
def buildTask = tasks.findByName("${module}_build")
buildTask.description "Builds and installs locally ${module} module"
buildDeps.add(buildTask)
}
// Create init tasks
task "${module}_init" doLast {
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()) {
logger.lifecycle("Module ${module} has already been initialized, please use " +
"'update' to update it.")
} else {
logger.lifecycle "Cloning: ${module}, branch: ${gitSourceBranch}, url: ${finalUrl}"
executeProcess(arry, ".")
}
}
//Creates Update Tasks
task "${module}_update" doLast {
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 cleanTask = tasks.findByName("${module}_clean")
cleanTask.description "Cleans ${module} module"
cleanDeps.add(cleanTask)
def initTask = tasks.findByName("${module}_init")
initTask.description = "Clones from ${gitURLTemplate}${module} branch ${gitSourceBranch} the module ${module}"
initDeps.add(initTask)
def updateTask = tasks.findByName("${module}_update")
updateTask.description "Updates from ${gitRepo} branch ${gitSourceBranch} the module ${module}"
updateDeps.add(updateTask)
} else {
logger.debug("Task ${module}_build already exists")
}
}
envs.each { env ->
// Creates the deploy tasks
deployModules.keySet().each { module ->
if (!(env.equalsIgnoreCase("delivery") && module.equalsIgnoreCase("studio"))) {
if (!tasks.findByName("${module}_${env}_deploy")) {
task "${module}_${env}_deploy" doLast({
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 deployTask = tasks.findByName("${module}_${env}_deploy")
deployTask.description "Deploy ${module} in the ${env} enviroment"
deliveryDeps.add(deployTask)
} else {
logger.debug("Task ${module}_deploy already exists")
}
}
}
/* Per Env tasks */
if (!tasks.findByName("${env}_start")) {
task "${env}_start" doLast({
def extraStartupParams = []
if (startMongodb) {
extraStartupParams.add("forceMongo")
}
def path = env.equalsIgnoreCase("authoring") ? "${authEnv}" : "${deliveryEnv}"
if (!file(path).exists()) {
throw new InvalidUserDataException("The '${env}' enviroment is not deployed. Please run 'deploy -Penv=${env}' before 'start'.")
}
executeProcess(commandLinePrefix + [startUpFile] + extraStartupParams, "${path}/bin")
})
}
if (!tasks.findByName("${env}_stop")) {
task "${env}_stop" doLast({
def extraStartupParams = []
if (startMongodb) {
extraStartupParams.add("forceMongo")
}
def path = env.equalsIgnoreCase("authoring") ? "${authEnv}" : "${deliveryEnv}"
if (!file(path).exists()) {
throw new InvalidUserDataException("The '${env}' enviroment is not deployed. Please run 'deploy -Penv=${env}' before 'start'.")
}
executeProcess(commandLinePrefix + [shutDownFile] + extraStartupParams, "${path}/bin")
})
}
if (!tasks.findByName("${env}_status") && !isWin) {
task "${env}_status" doLast({
def extraStartupParams = []
if (startMongodb) {
extraStartupParams.add("forceMongo")
}
def path = env.equalsIgnoreCase("authoring") ? "${authEnv}" : "${deliveryEnv}"
if (!file(path).exists()) {
throw new InvalidUserDataException("The '${env}' enviroment is not deployed. Please run 'deploy -Penv=${env}' before 'start'.")
}
executeProcess(commandLinePrefix + ["./crafter.sh", "status"], "${path}/bin")
})
}
if (!tasks.findByName("${env}_bundle_zip")) {
task "${env}_bundle_zip"(type: Zip) {
description "Bundles as a Zip file ${env} enviroment"
def environmentPath = env.equalsIgnoreCase("authoring") ? "${authEnv}" : "${deliveryEnv}"
from(environmentPath) {
into("crafter")
}
archiveName "crafter-cms-${env}.zip"
fileMode null
dirMode null
includeEmptyDirs true
metadataCharset "UTF-8"
caseSensitive false
destinationDir(file("bundles/"))
zip64 true
}
}
if (!tasks.findByName("${env}_bundle_tar")) {
task "${env}_bundle_tar"(type: Tar) {
description "Bundles as a Tar file ${env} enviroment"
def environmentPath = env.equalsIgnoreCase("authoring") ? "${authEnv}" : "${deliveryEnv}"
from(environmentPath) {
into("crafter")
}
archiveName "crafter-cms-${env}.tar.gz"
fileMode null
dirMode null
includeEmptyDirs true
caseSensitive false
compression = Compression.GZIP
destinationDir(file("bundles/"))
}
}
switch (typeOfBundle.toLowerCase()) {
case "zip":
bundleDeps.add(tasks.findByName("${env}_bundle_zip"))
break;
case "tar":
bundleDeps.add(tasks.findByName("${env}_bundle_tar"))
break;
default:
bundleDeps.add(tasks.findByName("${env}_bundle_zip"))
bundleDeps.add(tasks.findByName("${env}_bundle_tar"))
break;
}
statusDeps.add(tasks.findByName("${env}_status"))
stopDeps.add(tasks.findByName("${env}_stop"))
startDeps.add(tasks.findByName("${env}_start"))
}
/* Cleanup non buildable modules */
buildDeps.removeAll([
tasks.findByName("studio-ui_build"),
tasks.findByName("plugin-maker_build")
] as Task[])
cleanDeps.removeAll([
tasks.findByName("studio-ui_clean"),
tasks.findByName("plugin-maker_clean"),
tasks.findByName("test-suite_build")
] as Task[])
if (!includeSocial) {
buildDeps.removeAll([tasks.findByName('social_build')] as Task[])
deliveryDeps.removeIf({
it.name.contains("social")
})
}
if (!includeProfile) {
deliveryDeps.removeIf({
it.name.contains("profile")
})
}
task selftest {
description "Selftest gradle script."
doLast {
def selftestScript="initialSetupCheckForTestScript"
if (isWin) {
selftestScript+=".bat"
} else {
selftestScript = "./"+selftestScript+".sh"
}
def array = commandLinePrefix + [selftestScript]
executeProcess(array, "./src/test-suite")
}
}
task clean() {
//Dummy task Builds used as dependency of other tasks
description "Clean all configured Crafter Modules"
}
task build() {
description "Builds all configured Crafter Modules"
//Dummy task Builds used as dependency of other tasks
}
task init(dependsOn: initDeps) {
description "Clones all configured Crafter modules from ${gitURLTemplate} and branch ${gitSourceBranch}"
}
task update(dependsOn: updateDeps) {
description "Update all configured Crafter modules from ${gitSourceBranch} and branch ${gitSourceBranch}"
}
task upgrade() {
description "Delete all enviroment information (keeps the site data,db and indexes), update builds and deploy a new enviroment."
}
task deploy() {
description "Deploys all configured Crafter Modules"
}
task bundle(dependsOn: bundleDeps) {
description "Zips and Tars all Crafter enviroments."
}
task start(dependsOn: startDeps) {
description "Starts configured Crafter enviroments.."
}
task stop(dependsOn: stopDeps) {
description "Stops configured Crafter enviroments.."
}
task status(dependsOn: statusDeps) {
description "Gets the status configured Crafter enviroments.."
}
task utils() {
description "Builds and deploys Crafter Utililty tools jar file."
doLast {
def array = commandLinePrefix + ["mvn", "clean", "package"]
executeProcess(array, "./utils/")
envs.each { env ->
def path = env.equalsIgnoreCase("authoring") ? "${authEnv}" : "${deliveryEnv}"
copy {
from "./utils/target/craftercms-utils.jar"
into "${path}/bin"
}
}
}
}
task preUpgrade {
def enviroments = []
doFirst {
switch (getEnv()) {
case "all":
enviroments.addAll([new File("${authEnv}"), new File("${deliveryEnv}")])
break
case "authoring":
enviroments.add(new File("${authEnv}"))
break
case "delivery":
enviroments.add(new File("${deliveryEnv}"))
break
default:
throw new InvalidUserDataException("'${env}' is not a valid environment, please use 'authoring' or 'delivery'.")
}
}
doLast {
enviroments.each { envFolder ->
if (envFolder.exists()) {
envFolder.eachFile { dir ->
if (!dir.getName().equalsIgnoreCase("data")) {
if (!dir.isFile()) {
dir.deleteDir()
} else {
dir.delete()
}
}
}
}
}
}
}
task preDeploy {
doLast {
if (getEnv().equalsIgnoreCase("all")) {
checkOrCreateCheck("${authEnv}")
checkOrCreateCheck("${deliveryEnv}")
} else {
def path = env.equalsIgnoreCase("authoring") ? "${authEnv}" : "${deliveryEnv}"
checkOrCreateCheck(path)
}
}
}
task selfupdate {
description "Updates the Crafter CMS project"
doLast {
def arry = commandLinePrefix + ["git", "pull", gitRepo, gitSourceBranch]
executeProcess(arry, ".")
}
}
task preTest(dependsOn: preTestDeps) {
def repoFolder = file("${authEnv}/data/repos/sites")
def driverPath = ""
doFirst {
switch (browserToTest.toString().toLowerCase()) {
case "chrome":
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":
driverPath = file("./src/test-suite/bin/${browserToTest}/MicrosoftWebDriver.exe")
break
case "ie":
driverPath = file("./src/test-suite/bin/ie-win/IEDriverServer.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)}")
properties.add("deliverybaseUrl=http://localhost:9080/")
if (SystemUtils.IS_OS_WINDOWS) {
properties.add("executionenvironment=windows")
} else {
properties.add("executionenvironment=unix")
}
Files.write(Paths.get("./src/test-suite/test-properties.properties"), properties, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
}
// Exists, is a folder and has sites
if (repoFolder.exists() && repoFolder.isDirectory() && (repoFolder.listFiles().length > 0)) {
def dataFolderSuffix = "-${new Date().format("YYYYMMdd")}-${UUID.randomUUID().toString()}"
logger.lifecycle("About to begin automatic testing suite")
logger.lifecycle("Current Data folder will be move to data_${dataFolderSuffix}")
logger.lifecycle("It will move it back when done ")
sleep(5 * 1000)
repoFolder.parentFile.parentFile.renameTo(repoFolder.parentFile.parentFile.absolutePath + dataFolderSuffix)
repoFolder.parentFile.parentFile.mkdir()
Files.write(Paths.get(repoFolder.parentFile.parentFile.absolutePath, "_btbk.txt"), [dataFolderSuffix], StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
}
}
}
task postTest {
def repoFolder = file("${authEnv}/data/repos/sites")
def folderSuffixCacheFile = Paths.get(repoFolder.parentFile.parentFile.absolutePath, "_btbk.txt").toFile()
if (folderSuffixCacheFile.exists()) {
logger.lifecycle("Moving back pre-test data")
logger.lifecycle("Test data was backup in the folder ${folderSuffixCacheFile.toString()}")
logger.lifecycle("This folder can be safely remove if needed.")
def dataFolderSufix = Files.readAllLines(folderSuffixCacheFile.toPath(), Charset.forName("UTF-8")).get(0)
def backupedFolder = file(repoFolder.parentFile.parentFile.absolutePath + dataFolderSufix)
if (backupedFolder.exists()) {
repoFolder.parentFile.parentFile.renameTo(repoFolder.parentFile.parentFile.absolutePath +
"$dataFolderSufix-td")
backupedFolder.renameTo(Paths.get(backupedFolder.parentFile.absolutePath, "data").toString())
}
}
}
task delay {
doLast {
sleep(30 * 1000)
}
}
task test() {
description "Tests Crafter CMS."
doLast {
def actualCommandLinePost = ["-Dfile=" + testingSuites]
def array = commandLinePrefix + ["mvn", "clean", "install"] + actualCommandLinePost
executeProcess(array, "./src/test-suite")
}
}
task newPlugin(type: GradleBuild) {
description "Creates the folder structure for a new plugin"
group "plugin"
buildFile = Paths.get("src", "plugin-maker", "build.gradle")
tasks = ['newPlugin']
startParameter.projectProperties = project.getGradle().getStartParameter().getProjectProperties()
}
task packagePlugin(type: GradleBuild) {
description "Packages a Crafter Studio plugin"
group "plugin"
buildFile = Paths.get("src", "plugin-maker", "build.gradle")
tasks = ['packagePlugin']
startParameter.projectProperties = project.getGradle().getStartParameter().getProjectProperties()
}
task publishPlugin(type: GradleBuild) {
description "Publishes a plugin to the Crafter Marketplace"
group "plugin"
buildFile = Paths.get("src", "plugin-maker", "build.gradle")
tasks = ['publishPlugin']
startParameter.projectProperties = project.getGradle().getStartParameter().getProjectProperties()
}
/** Makes sure Depends are run in order. **/
dependsOnOrdered(clean, cleanDeps)
dependsOnOrdered(build, [clean] + buildDeps)
dependsOnOrdered(init, initDeps)
dependsOnOrdered(update, updateDeps)
dependsOnOrdered(deploy, [preDeploy, downloadGroovy, downloadTomcat, downloadSolr, downloadMariaDB4j, utils] + envDepends + deliveryDeps)
dependsOnOrdered(upgrade, [update, preUpgrade, build, deploy])
// If delivery no test (for now)
if (!project.hasProperty("env") || (project.hasProperty("env") && !project.property("env").equalsIgnoreCase("delivery"))) {
dependsOnOrdered(test, [preTest, authoring_start, delay])
test.finalizedBy(authoring_stop)
test.finalizedBy(postTest)
}
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('/'))
rename('-exec', '')
}
} else {
logger.lifecycle "WARN: You haven't built ${module} module"
}
}
def executeProcess(command, workingDir) {
ProcessBuilder pb = new ProcessBuilder(command)
pb.directory(new File(workingDir))
pb.redirectErrorStream(true)
def log = new File(processLogFile)
pb.redirectOutput(ProcessBuilder.Redirect.to(log))
def tailer = null
if(!silentBuild) {
tailer = Tailer.create(log, new TailerListenerAdapter() {
def void handle(String line) {
println line
}
}, processTailReadDelay)
}
Process proc = pb.start();
proc.waitFor()
if(tailer) {
Thread.sleep(processTailFinishDelay)
tailer.stop()
}
log.delete()
if (proc.exitValue() != 0) {
throw new GradleException("${command} @ ${workingDir} return a non-zero value (${proc.exitValue()})")
}
}
def checkOrCreateCheck(path) {
def ddir = file(path)
if (!ddir.exists() || forceDeploy) {
ddir.mkdir()
def deployerDir = file("${path}/bin/crafter-deployer")
deployerDir.mkdir()
}
}
def askForPath() {
def console = System.console();
def inputPath = console.readLine("> Please enter path for selemiun driver of ${browserToTest} ")
if (!file(inputPath).exists()) {
console.logger.lifecycle("${inputPath} does not exist, please enter a new valid path");
askForPath();
}
return inputPath
}
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 environmentName = project.property("env")
environmentName = environmentName.trim().toLowerCase()
return environmentName.trim().isEmpty() ? "all" : environmentName
} else {
return "all"
}
}
// Run task in the right order.
void dependsOnOrdered(Task task, List others) {
task.dependsOn(others)
for (int i = 0; i < others.size() - 1; i++) {
others.get(i + 1).mustRunAfter(others.get(i))
}
}