forked from apache/ofbiz-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
1122 lines (999 loc) · 43.9 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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import at.bxm.gradleplugins.svntools.tasks.SvnCheckout
import org.apache.tools.ant.filters.ReplaceTokens
import org.asciidoctor.gradle.AsciidoctorTask
/* ========================================================
* Project setup
* ======================================================== */
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'at.bxm.gradleplugins:gradle-svntools-plugin:2.2.1' //避免每次执行需要联网,原值latest.release
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.7'
classpath 'at.bxm.gradleplugins:gradle-svntools-plugin:latest.release'
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.8.1' // Rather than using 1.5.9.2 see OFBIZ-10693
classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16'
}
}
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: "at.bxm.svntools"
apply plugin: 'org.asciidoctor.convert'
apply from: 'common.gradle'
//增加自定义扩展任务
apply from: 'external.gradle'
// global properties
ext.os = System.getProperty('os.name').toLowerCase()
ext.pluginsDir = "${rootDir}/plugins"
// java settings
List jvmArguments = ['-Xms128M', '-Xmx1024M']
if (project.hasProperty('jvmArgs')) {
jvmArguments = jvmArgs.tokenize()
}
ext.ofbizMainClass = 'org.apache.ofbiz.base.start.Start'
javadoc.failOnError = true
javadoc.options {
encoding "UTF-8"
charSet "UTF-8"
// Those external Javadoc links should correspond to the actual
// versions declared in the "dependencies" block.
links(
"https://docs.oracle.com/javase/8/docs/api",
"https://docs.oracle.com/javaee/7/api",
"http://docs.groovy-lang.org/docs/groovy-2.4.16/html/api",
"https://commons.apache.org/proper/commons-cli/apidocs"
)
}
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
// Java compile options, syntax gradlew -PXlint:none build
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
if (!project.hasProperty('Xlint:none')) {
options.compilerArgs << "-Xlint:all"
// Exclude varargs warnings which are not silenced by @SafeVarargs.
options.compilerArgs << "-Xlint:-varargs"
}
}
// defines the footer files for svn and git info
def File gitFooterFile = file("${rootDir}/runtime/GitInfo.ftl")
def File svnFooterFile = file("${rootDir}/runtime/SvnInfo.ftl")
// root and subproject settings
defaultTasks 'build'
allprojects {
repositories{
jcenter()
mavenLocal()
}
}
subprojects {
configurations {
// compile-time plugin libraries
pluginLibsCompile
// runtime plugin libraries
pluginLibsRuntime
//compile-only libraries
pluginLibsCompileOnly
}
}
configurations {
junitReport {
description = 'libraries needed to run junitreport for OFBiz unit tests'
}
ofbizPlugins {
description = 'ofbiz plugin dependencies configuration'
transitive = true
}
}
dependencies {
// ofbiz compile libs
compile 'apache-xerces:xercesImpl:2.9.1'
compile 'com.google.zxing:core:3.3.3'
compile 'com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2'
compile 'com.googlecode.ez-vcard:ez-vcard:0.9.10'
compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20180219.1'
compile 'com.googlecode.libphonenumber:libphonenumber:8.9.16'
compile 'com.ibm.icu:icu4j:63.1'
compile 'com.lowagie:itext:2.1.7' // Don't update due to license change in newer versions, see OFBIZ-10455
compile 'com.sun.mail:javax.mail:1.6.2'
compile 'com.sun.syndication:com.springsource.com.sun.syndication:0.9.0'
compile 'com.thoughtworks.xstream:xstream:1.4.11.1'
compile 'commons-cli:commons-cli:1.4'
compile 'commons-net:commons-net:3.6'
compile 'commons-validator:commons-validator:1.6'
compile 'commons-fileupload:commons-fileupload:1.3.3'
compile 'de.odysseus.juel:juel-impl:2.2.7'
compile 'javax.el:javax.el-api:3.0.1-b06'
compile 'javax.servlet:javax.servlet-api:4.0.1'
compile 'javax.servlet.jsp:javax.servlet.jsp-api:2.3.3'
compile 'junit:junit-dep:4.11'
compile 'net.fortuna.ical4j:ical4j:1.0-rc3-atlassian-11'
compile 'org.apache.ant:ant-junit:1.10.5'
compile 'org.apache.axis2:axis2-kernel:1.7.8'
compile 'org.apache.commons:commons-collections4:4.2'
compile 'org.apache.commons:commons-csv:1.6'
compile 'org.apache.commons:commons-dbcp2:2.5.0'
compile 'org.apache.geronimo.components:geronimo-transaction:3.1.4'
compile 'org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1'
compile 'org.apache.httpcomponents:httpclient-cache:4.5.6'
compile 'org.apache.logging.log4j:log4j-api:2.11.1' // the API of log4j 2
compile 'org.apache.poi:poi:3.17'
compile 'org.apache.shiro:shiro-core:1.4.0'
compile 'org.apache.sshd:sshd-core:1.7.0'
compile 'org.apache.tika:tika-core:1.18'
compile 'org.apache.tika:tika-parsers:1.18'
compile 'org.apache.tomcat:tomcat-catalina-ha:9.0.13'
compile 'org.apache.tomcat:tomcat-catalina:9.0.13'
compile 'org.apache.tomcat:tomcat-jasper:9.0.13'
compile 'org.apache.tomcat:tomcat-tribes:9.0.13'
compile 'org.apache.xmlgraphics:fop:2.3'
compile 'org.apache.xmlrpc:xmlrpc-client:3.1.3'
compile 'org.apache.xmlrpc:xmlrpc-server:3.1.3'
compile 'org.codehaus.groovy:groovy-all:2.4.16' // Remember to change the version number in javadoc.options block
compile 'org.freemarker:freemarker:2.3.28' // Remember to change the version number in FreeMarkerWorker class when upgrading
compile 'org.hamcrest:hamcrest-all:1.3'
compile 'org.owasp.esapi:esapi:2.1.0.1'
compile 'org.springframework:spring-test:5.1.2.RELEASE'
compile 'org.zapodot:jackson-databind-java-optional:2.6.1'
compile 'oro:oro:2.0.8'
compile 'wsdl4j:wsdl4j:1.6.3'
compile 'org.jsoup:jsoup:1.11.3'
compile 'io.jsonwebtoken:jjwt:0.9.1'
// ofbiz unit-test compile libs
testCompile 'org.mockito:mockito-core:2.23.0'
// ofbiz runtime libs
runtime 'de.odysseus.juel:juel-spi:2.2.7'
runtime 'net.sf.barcode4j:barcode4j-fop-ext:2.1'
runtime 'net.sf.barcode4j:barcode4j:2.1'
runtime 'org.apache.axis2:axis2-transport-http:1.7.8'
runtime 'org.apache.axis2:axis2-transport-local:1.7.8'
runtime 'org.apache.derby:derby:10.14.2.0'
runtime 'org.apache.geronimo.specs:geronimo-jaxrpc_1.1_spec:1.1'
runtime 'org.apache.logging.log4j:log4j-1.2-api:2.11.1' // for external jars using the old log4j1.2: routes logging to log4j 2
runtime 'org.apache.logging.log4j:log4j-core:2.11.1' // the implementation of the log4j 2 API
runtime 'org.apache.logging.log4j:log4j-jul:2.11.1' // for external jars using the java.util.logging: routes logging to log4j 2
runtime 'org.apache.logging.log4j:log4j-slf4j-impl:2.11.1' // for external jars using slf4j: routes logging to log4j 2
runtime 'org.codeartisans.thirdparties.swing:batik-all:1.8pre-r1084380'
// plugin libs
subprojects.each { subProject ->
compile project(path: subProject.path, configuration: 'pluginLibsCompile')
runtime project(path: subProject.path, configuration: 'pluginLibsRuntime')
compileOnly project(path: subProject.path, configuration: 'pluginLibsCompileOnly')
}
// libs needed for junitreport
junitReport 'junit:junit:4.12'
junitReport 'org.apache.ant:ant-junit:1.10.5'
// bug workaround - see OFBIZ-9873
asciidoctor 'org.jruby:jruby-complete:9.2.4.0'
// local libs
getDirectoryInActiveComponentsIfExists('lib').each { libDir ->
compile fileTree(dir: libDir, include: '**/*.jar')
}
compile fileTree(dir: file("${rootDir}/lib"), include: '**/*.jar')
}
def excludedJavaSources = [
'org/apache/ofbiz/accounting/thirdparty/cybersource/IcsPaymentServices.java',
'org/apache/ofbiz/accounting/thirdparty/orbital/OrbitalPaymentServices.java',
'org/apache/ofbiz/accounting/thirdparty/paypal/PayPalServices.java',
'org/apache/ofbiz/accounting/thirdparty/securepay/SecurePayPaymentServices.java',
'org/apache/ofbiz/accounting/thirdparty/securepay/SecurePayServiceTest.java',
'org/apache/ofbiz/accounting/thirdparty/verisign/PayflowPro.java',
'org/apache/ofbiz/order/thirdparty/taxware/TaxwareException.java',
'org/apache/ofbiz/order/thirdparty/taxware/TaxwareServices.java',
'org/apache/ofbiz/order/thirdparty/taxware/TaxwareUTL.java'
]
// Files and directories present in config directories that should not be included in ofbiz.jar (see OFBIZ-8321).
def excludedConfigFiles = [
'README',
'APACHE2_HEADER_FOR_XML',
'*.txt',
'*.jks',
'fop.xconf',
'MiniLang.xslt',
'AutoImportTemplate.ftl',
'axis2',
'barcode'
]
sourceSets {
main {
java {
srcDirs = getDirectoryInActiveComponentsIfExists('src/main/java')
exclude excludedJavaSources
}
groovy {
srcDirs = getDirectoryInActiveComponentsIfExists('src/main/groovy')
}
resources {
srcDirs = getDirectoryInActiveComponentsIfExists('src/main/java')
srcDirs += getDirectoryInActiveComponentsIfExists('config')
srcDirs += "${rootDir}/framework/base/dtd"
exclude excludedJavaSources
exclude excludedConfigFiles
// Below are necessary for unit tests run by Gradle and integration tests
exclude { FileTreeElement elem -> elem.getName().contains('Labels.xml') }
exclude { FileTreeElement elem -> elem.getName().contains('.properties') &&
!elem.getName().contains('start.properties') &&
!elem.getName().contains('load-data.properties') &&
!elem.getName().contains('debug.properties') &&
!elem.getName().contains('cache.properties') &&
!elem.getName().contains('test.properties') &&
!elem.getName().contains('rmi.properties')
}
}
}
test {
java {
srcDirs = getDirectoryInActiveComponentsIfExists('src/test/java')
}
groovy {
srcDirs = getDirectoryInActiveComponentsIfExists('src/test/groovy')
}
resources {
srcDirs = getDirectoryInActiveComponentsIfExists('src/test/java')
}
}
}
jar {
manifest {
attributes(
"Implementation-Title": project.name,
"Main-Class": ofbizMainClass,
"Class-Path": getJarManifestClasspathForCurrentOs()
)
}
}
// Eclipse plugin settings
eclipse.classpath.file.whenMerged { classpath ->
/* The code inside this block removes unnecessary entries
* in the .classpath file which are generated automatically
* due to the settings in the sourceSets block
*/
def fileSep = System.getProperty("file.separator")
iterateOverActiveComponents { component ->
def componentName = component.toString() - rootDir.toString() - fileSep
def eclipseEntry = os.contains('windows') ? componentName.replaceAll("\\\\", "/") : componentName
classpath.entries.removeAll { entry ->
// remove any "src" entries in .classpath of the form /componentName
entry.kind == 'src' &&
entry.path ==~ '.*/+(' + componentName.tokenize(fileSep).last() + ')$' ||
entry.path ==~ /(\/+framework)$/ ||
entry.path ==~ /(\/+applications)$/ ||
entry.path ==~ /(\/+plugins)$/ ||
entry.path ==~ /(\/+themes)$/ ||
entry.path ==~ eclipseEntry + '/config' ||
entry.path ==~ eclipseEntry + '/dtd'
}
}
}
tasks.eclipse.dependsOn(cleanEclipse)
/* OWASP plugin
*
* If project property "enableOwasp" is flagged then
* gradle will download required dependencies and
* activate Gradle's OWASP plugin and its related tasks.
*
* Syntax: gradlew -PenableOwasp dependencyCheckAnalyze
*/
buildscript {
if (project.hasProperty('enableOwasp')) {
dependencies {
classpath 'org.owasp:dependency-check-gradle:3.0.2'
}
}
}
if (project.hasProperty('enableOwasp')) {
apply plugin: 'org.owasp.dependencycheck'
}
/* ========================================================
* Tasks
* ======================================================== */
// ========== Task group labels ==========
def cleanupGroup = 'Cleaning'
def docsGroup = 'Documentation'
def ofbizServer = 'OFBiz Server'
def ofbizPlugin = 'OFBiz Plugin'
def sysadminGroup = 'System Administration'
// ========== OFBiz Server tasks ==========
task loadAll(group: ofbizServer) {
dependsOn 'ofbiz --load-data'
description 'Load default data; meant for OFBiz development, testing, and demo purposes'
}
task testIntegration(group: ofbizServer) {
dependsOn 'ofbiz --test'
description 'Run OFBiz integration tests; You must run loadAll before running this task'
}
task terminateOfbiz(group: ofbizServer,
description: 'Force termination of any running OFBiz servers, only use if \"--shutdown\" command fails') {
doLast {
if (os.contains('windows')) {
Runtime.getRuntime().exec("wmic process where \"CommandLine Like \'%org.apache.ofbiz.base.start.Start%\'\" Call Terminate")
} else {
def processOutput = new ByteArrayOutputStream()
exec {
commandLine 'ps', 'ax'
standardOutput = processOutput
}
processOutput.toString().split(System.lineSeparator()).each { line ->
if (line ==~ /.*org\.apache\.ofbiz\.base\.start\.Start.*/) {
exec { commandLine 'kill', '-9', line.tokenize().first() }
}
}
}
}
}
task loadAdminUserLogin(group: ofbizServer) {
description 'Create admin user with temporary password equal to ofbiz. You must provide userLoginId'
createOfbizCommandTask('executeLoadAdminUser',
['--load-data', 'file=/runtime/tmp/AdminUserLoginData.xml'],
jvmArguments, false)
executeLoadAdminUser.doFirst {
copy {
from ("${rootDir}/framework/resources/templates/AdminUserLoginData.xml") {
filter(ReplaceTokens, tokens: [userLoginId: userLoginId])
}
into "${rootDir}/runtime/tmp/"
}
}
dependsOn executeLoadAdminUser
doLast {
delete("${rootDir}/runtime/tmp/AdminUserLoginData.xml")
}
}
task loadTenant(group: ofbizServer, description: 'Load data using tenantId') {
createOfbizCommandTask('executeLoadTenant', [], jvmArguments, false)
if (project.hasProperty('tenantId')) {
executeLoadTenant.args '--load-data'
executeLoadTenant.args "delegator=default#${tenantId}"
}
if (project.hasProperty('tenantReaders')) {
executeLoadTenant.args '--load-data'
executeLoadTenant.args "readers=${tenantReaders}"
}
if (project.hasProperty('tenantComponent')) {
executeLoadTenant.args '--load-data'
executeLoadTenant.args "component=${tenantComponent}"
}
executeLoadTenant.doFirst {
if (!project.hasProperty('tenantId')) {
throw new GradleException('Missing project property tenantId')
}
}
dependsOn executeLoadTenant
}
task createTenant(group: ofbizServer, description: 'Create a new tenant in your environment') {
def databaseTemplateFile = "${rootDir}/framework/resources/templates/AdminNewTenantData-Derby.xml"
task prepareAndValidateTenantArguments {
doLast {
if (!project.hasProperty('tenantId')) {
throw new GradleException('Project property tenantId is missing')
}
// dbPlatform values: D(Derby), M(MySQL), O(Oracle), P(PostgreSQL) (default D)
if (project.hasProperty('dbPlatform')) {
if (dbPlatform == 'D') {
databaseTemplateFile = "${rootDir}/framework/resources/templates/AdminNewTenantData-Derby.xml"
} else if (dbPlatform == 'M') {
databaseTemplateFile = "${rootDir}/framework/resources/templates/AdminNewTenantData-MySQL.xml"
} else if (dbPlatform == 'O') {
databaseTemplateFile = "${rootDir}/framework/resources/templates/AdminNewTenantData-Oracle.xml"
} else if (dbPlatform == 'P') {
databaseTemplateFile = "${rootDir}/framework/resources/templates/AdminNewTenantData-PostgreSQL.xml"
} else {
throw new GradleException('Invalid value for property dbPlatform: ' + "${dbPlatform}")
}
}
}
}
task generateDatabaseTemplateFile(dependsOn: prepareAndValidateTenantArguments) {
doLast {
def filterTokens = ['tenantId': tenantId,
'tenantName': project.hasProperty('tenantName')? tenantName : tenantId,
'domainName': project.hasProperty('domainName')? domainName : 'org.apache.ofbiz',
'db-IP': project.hasProperty('dbIp')? dbIp : '',
'db-User': project.hasProperty('dbUser')? dbUser : '',
'db-Password': project.hasProperty('dbPassword')? dbPassword : '']
generateFileFromTemplate(databaseTemplateFile, 'runtime/tmp',
filterTokens, 'tmpFilteredTenantData.xml')
}
}
task generateAdminUserTemplateFile(dependsOn: prepareAndValidateTenantArguments) {
doLast {
generateFileFromTemplate(
"${rootDir}/framework/resources/templates/AdminUserLoginData.xml",
'runtime/tmp',
['userLoginId': "${tenantId}-admin".toString()],
'tmpFilteredUserLogin.xml')
}
}
// Load the tenants master database
createOfbizCommandTask('loadTenantOnMasterTenantDb',
['--load-data', 'file=/runtime/tmp/tmpFilteredTenantData.xml',
'--load-data', 'readers=tenant'],
jvmArguments, false)
loadTenantOnMasterTenantDb.dependsOn(generateDatabaseTemplateFile, generateAdminUserTemplateFile)
// Load the actual tenant data
createOfbizCommandTask('loadTenantData', [], jvmArguments, false)
loadTenantData.dependsOn(loadTenantOnMasterTenantDb)
// Load the tenant admin user account
createOfbizCommandTask('loadTenantAdminUserLogin', [], jvmArguments, false)
loadTenantAdminUserLogin.dependsOn(loadTenantData)
/* pass arguments to tasks, must be done this way
* because we are in the configuration phase. We cannot
* set the parameters at the execution phase. */
if (project.hasProperty('tenantId')) {
loadTenantData.args '--load-data'
loadTenantData.args "delegator=default#${tenantId}"
loadTenantAdminUserLogin.args '--load-data'
loadTenantAdminUserLogin.args "delegator=default#${tenantId}"
loadTenantAdminUserLogin.args '--load-data'
loadTenantAdminUserLogin.args "file=${rootDir}/runtime/tmp/tmpFilteredUserLogin.xml"
}
if (project.hasProperty('tenantReaders')) {
loadTenantData.args '--load-data'
loadTenantData.args "readers=${tenantReaders}"
}
dependsOn(loadTenantAdminUserLogin)
// cleanup
doLast {
delete("${rootDir}/runtime/tmp/tmpFilteredTenantData.xml")
delete("${rootDir}/runtime/tmp/tmpFilteredUserLogin.xml")
}
}
// ========== Documentation tasks ==========
tasks.withType(AsciidoctorTask) { task ->
backends 'html5', 'pdf'
attributes \
'doctype': 'book',
'experimental': '',
'icons': 'font',
'sectnums': '',
'chapter-label': '',
'toc': '',
'toclevels': '3'
}
task deleteOfbizDocumentation {
doFirst { delete "${buildDir}/asciidoc/ofbiz" }
}
task deletePluginDocumentation {
def activeComponents = []
iterateOverActiveComponents { component ->
activeComponents.add(component.name)
}
doFirst {
if (!project.hasProperty('pluginId')) {
throw new GradleException('Missing property \"pluginId\"')
}
if(!activeComponents.contains(pluginId)) {
throw new GradleException("Could not find plugin with id ${pluginId}")
}
delete "${buildDir}/asciidoc/plugins/${pluginId}"
}
}
task deleteAllPluginsDocumentation {
doFirst { delete "${buildDir}/asciidoc/plugins" }
}
task generateOfbizDocumentation(group: docsGroup, type: AsciidoctorTask) {
dependsOn deleteOfbizDocumentation
description 'Generate OFBiz documentation manuals'
sourceDir "${rootDir}/docs/asciidoc"
outputDir file("${buildDir}/asciidoc/ofbiz")
}
task generatePluginDocumentation(group: docsGroup) {
dependsOn deletePluginDocumentation
description 'Generate plugin documentation. Expects pluginId flag'
iterateOverActiveComponents { component ->
if (project.hasProperty('pluginId') && component.name == pluginId) {
def pluginAsciidoc = task "${component.name}Documentation" (type: AsciidoctorTask) {
def asciidocFolder = new File("${component}/src/docs/asciidoc")
if (asciidocFolder.exists()) {
copy {
from "${rootDir}/docs/asciidoc/images/OFBiz-Logo.svg"
into "${component}/src/docs/asciidoc/images"
}
sourceDir file("${component}/src/docs/asciidoc")
outputDir file("${buildDir}/asciidoc/plugins/${component.name}")
doLast { println "Documentation generated for plugin ${component.name}" }
} else {
println "No documentation found for plugin ${component.name}"
}
mustRunAfter deletePluginDocumentation
}
dependsOn pluginAsciidoc
doLast { delete "${component}/src/docs/asciidoc/images/OFBiz-Logo.svg" }
}
}
}
task generateAllPluginsDocumentation(group: docsGroup,
description: 'Generate all plugins documentation.') {
dependsOn deleteAllPluginsDocumentation
file("${pluginsDir}").eachDir { plugin ->
iterateOverActiveComponents { component ->
if (component.name == plugin.name) {
if (subprojectExists(":plugins:${plugin.name}")) {
// Note: the "-" between "component.name" and "Documentation" allows to differentiate from
// the other inner task temporary created by the generatePluginDocumentation task
def pluginAsciidoc = task "${component.name}-Documentation" (type: AsciidoctorTask) {
def asciidocFolder = new File("${component}/src/docs/asciidoc")
if (asciidocFolder.exists()) {
copy {
from "${rootDir}/docs/asciidoc/images/OFBiz-Logo.svg"
into "${component}/src/docs/asciidoc/images"
}
sourceDir file("${component}/src/docs/asciidoc")
outputDir file("${buildDir}/asciidoc/plugins/${component.name}")
doLast { println "Documentation generated for plugin ${component.name}" }
}
mustRunAfter deleteAllPluginsDocumentation
}
dependsOn pluginAsciidoc
}
doLast { delete "${component}/src/docs/asciidoc/images/OFBiz-Logo.svg" }
}
}
}
}
// ========== System Administration tasks ==========
task createTestReports(group: sysadminGroup, description: 'Generate HTML reports from junit XML output') {
doLast {
ant.taskdef(name: 'junitreport',
classname: 'org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator',
classpath: configurations.junitReport.asPath)
ant.junitreport(todir: './runtime/logs/test-results') {
fileset(dir: './runtime/logs/test-results') {
include(name: '*.xml')
}
report(format:'frames', todir:'./runtime/logs/test-results/html')
}
}
}
task gitInfoFooter(group: sysadminGroup, description: 'Update the Git Branch-revision info in the footer if Git is used') {
doLast {
def branch
def revision
def timestamp = new Date().format 'yyyy-MM-dd HH:mm:ss'
def gitFolder = new File('.git')
if (!gitFolder.exists()) {
println ("Git is not used")
return
}
def branchOutput = new ByteArrayOutputStream()
exec{
commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD'
standardOutput = branchOutput
}
branch = branchOutput.toString()
def revisionOutput = new ByteArrayOutputStream()
exec{
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = revisionOutput
}
revision = revisionOutput.toString()
gitFooterFile.delete()
gitFooterFile.createNewFile()
gitFooterFile << '${uiLabelMap.CommonBranch} : ' + "${branch}" + System.lineSeparator()
gitFooterFile << '${uiLabelMap.CommonRevision} : ' + "${revision}" + System.lineSeparator()
gitFooterFile << '${uiLabelMap.CommonBuiltOn} : ' + "${timestamp}" + System.lineSeparator()
gitFooterFile << '${uiLabelMap.CommonJavaVersion} : ' + "${org.gradle.internal.jvm.Jvm.current()}"
}
}
task svnInfoFooter(group: sysadminGroup, description: 'Update the Subversion revision info in the footer if Subversion is used') {
doLast {
def timestamp = new Date().format 'yyyy-MM-dd HH:mm:ss'
def svnOutput = new ByteArrayOutputStream()
def svnFolder = new File('.svn')
if (!svnFolder.exists()) {
println ("Subversion is not used")
return
}
exec{
commandLine 'svn', 'info', '--xml'
standardOutput = svnOutput
}
def info = new XmlParser().parseText(svnOutput.toString())
svnFooterFile.delete()
svnFooterFile.createNewFile()
svnFooterFile << '${uiLabelMap.CommonBranch} : ' + "${info.entry.url.text()}" + System.lineSeparator()
svnFooterFile << '${uiLabelMap.CommonRevision} : ' + "${info.entry.commit.@revision}" + System.lineSeparator()
svnFooterFile << '${uiLabelMap.CommonBuiltOn} : ' + "${timestamp}" + System.lineSeparator()
svnFooterFile << '${uiLabelMap.CommonJavaVersion} : ' + "${org.gradle.internal.jvm.Jvm.current()}"
}
}
// ========== OFBiz Plugin Management ==========
task createPlugin(group: ofbizPlugin, description: 'create a new plugin component based on specified templates') {
doLast {
if (!project.hasProperty('pluginResourceName')) {
ext.pluginResourceName = pluginId.capitalize()
}
if (!project.hasProperty('webappName')) {
ext.webappName = pluginId
}
if (!project.hasProperty('basePermission')) {
ext.basePermission = pluginId.toUpperCase()
}
def filterTokens = ['component-name': pluginId,
'component-resource-name': pluginResourceName,
'webapp-name': webappName,
'base-permission': basePermission]
def templateDir = "${rootDir}/framework/resources/templates"
def pluginDir = "${pluginsDir}/${pluginId}"
['config', 'data/helpdata', 'dtd', 'documents', 'entitydef', 'lib', 'patches/test', 'patches/qa',
'patches/production', 'script', 'servicedef', 'src/main/java', 'src/test/java', 'testdef',
'widget', "webapp/${webappName}/error", "webapp/${webappName}/WEB-INF",
"webapp/${webappName}/WEB-INF/actions"].each {
mkdir pluginDir+'/'+it
}
[ [tempName:'ofbiz-component.xml', newName:'ofbiz-component.xml', location:''],
[tempName:'build.gradle', newName:'build.gradle', location:''],
[tempName:'TypeData.xml', newName:"${pluginResourceName}TypeData.xml", location:'data'],
[tempName:'SecurityPermissionSeedData.xml', newName:"${pluginResourceName}SecurityPermissionSeedData.xml", location:'data'],
[tempName:'SecurityGroupDemoData.xml', newName:"${pluginResourceName}SecurityGroupDemoData.xml", location:'data'],
[tempName:'DemoData.xml', newName:"${pluginResourceName}DemoData.xml", location:'data'],
[tempName:'HELP.xml', newName:"HELP_${pluginResourceName}.xml", location:'data/helpdata'],
[tempName:'document.xml', newName:"${pluginResourceName}.xml", location:'documents'],
[tempName:'entitymodel.xml', newName:'entitymodel.xml', location:'entitydef'],
[tempName:'services.xml', newName:'services.xml', location:'servicedef'],
[tempName:'Tests.xml', newName:"${pluginResourceName}Tests.xml", location:'testdef'],
[tempName:'UiLabels.xml', newName:"${pluginResourceName}UiLabels.xml", location:'config'],
[tempName:'index.jsp', newName:'index.jsp', location:"webapp/${webappName}"],
[tempName:'error.jsp', newName:'error.jsp', location:"webapp/${webappName}/error"],
[tempName:'controller.xml', newName:'controller.xml', location:"webapp/${webappName}/WEB-INF"],
[tempName:'web.xml', newName:'web.xml', location:"webapp/${webappName}/WEB-INF"],
[tempName:'CommonScreens.xml', newName:'CommonScreens.xml', location:'widget'],
[tempName:'Screens.xml', newName:"${pluginResourceName}Screens.xml", location:'widget'],
[tempName:'Menus.xml', newName:"${pluginResourceName}Menus.xml", location:'widget'],
[tempName:'Forms.xml', newName:"${pluginResourceName}Forms.xml", location:'widget']
].each { tmpl ->
generateFileFromTemplate(templateDir + '/' + tmpl.tempName,
pluginDir + '/' + tmpl.location, filterTokens, tmpl.newName)
}
println "plugin successfully created in directory ${pluginsDir}/${pluginId}."
}
}
task installPlugin(group: ofbizPlugin, description: 'executes plugin install task if it exists') {
doFirst {
if (!project.hasProperty('pluginId')) {
throw new GradleException('Missing property \"pluginId\"')
}
}
if (project.hasProperty('pluginId')) {
iterateOverActiveComponents { component ->
if (component.name == pluginId) {
if (subprojectExists(":plugins:${pluginId}")) {
if (taskExistsInproject(":plugins:${pluginId}", 'install')) {
dependsOn ":plugins:${pluginId}:install"
doLast { println "installed plugin ${pluginId}" }
} else {
doLast { println "No install task defined for plugin ${pluginId}, nothing to do" }
}
}
}
}
}
}
task uninstallPlugin(group: ofbizPlugin, description: 'executes plugin uninstall task if it exists') {
doFirst {
if (!project.hasProperty('pluginId')) {
throw new GradleException('Missing property \"pluginId\"')
}
if (!subprojectExists(":plugins:${pluginId}")) {
throw new GradleException("Plugin \"${pluginId}\" does not exist")
}
}
if (project.hasProperty('pluginId') && taskExistsInproject(":plugins:${pluginId}", 'uninstall')) {
dependsOn ":plugins:${pluginId}:uninstall"
doLast { println "uninstalled plugin ${pluginId}" }
} else {
doLast { println "No uninstall task defined for plugin ${pluginId}" }
}
}
task removePlugin(group: ofbizPlugin, description: 'Uninstall a plugin and delete its files') {
if (project.hasProperty('pluginId') && subprojectExists(":plugins:${pluginId}")) {
dependsOn uninstallPlugin
}
doLast {
if (file("${pluginsDir}/${pluginId}").exists()) {
delete "${pluginsDir}/${pluginId}"
} else {
throw new GradleException("Directory not found: ${pluginsDir}/${pluginId}")
}
}
}
task pushPlugin(group: ofbizPlugin, description: 'push an existing plugin to local maven repository') {
if (project.hasProperty('pluginId')) {
doFirst {
if (!subprojectExists(":plugins:${pluginId}")) {
throw new GradleException("Plugin ${pluginId} does not exist, cannot publish")
}
}
task createPluginArchive(type: Zip) {
from "${pluginsDir}/${pluginId}"
}
publishing {
publications {
ofbizPluginPublication(MavenPublication) {
artifactId pluginId
groupId project.hasProperty('pluginGroup')? pluginGroup :'org.apache.ofbiz.plugin'
version project.hasProperty('pluginVersion')? pluginVersion :'0.1.0-SNAPSHOT'
artifact createPluginArchive
pom.withXml {
if (project.hasProperty('pluginDescription')) {
asNode().appendNode('description', pluginDescription)
} else {
asNode().appendNode('description', "Publication of OFBiz plugin ${pluginId}")
}
}
}
}
}
if (subprojectExists(":plugins:${pluginId}")) {
dependsOn publishToMavenLocal
}
} else {
doFirst { throw new GradleException('Missing property \"pluginId\"') }
}
}
task pullPlugin(group: ofbizPlugin, description: 'Download and install a plugin with all dependencies') {
doLast {
if (!project.hasProperty('dependencyId')) {
throw new GradleException('You must pass the dependencyId of the plugin')
}
// Connect to a remote maven repository if defined
if (project.hasProperty('repoUrl')) {
repositories {
maven {
url repoUrl
if (project.hasProperty('repoUser') && project.hasProperty('repoPassword')) {
credentials {
username repoUser
password repoPassword
}
}
}
}
}
// download plugin and dependencies
dependencies {
ofbizPlugins dependencyId
}
// reverse the order of dependencies to install them before the plugin
def ofbizPluginArchives = new ArrayList(configurations.ofbizPlugins.files)
Collections.reverse(ofbizPluginArchives)
// Extract and install plugin and dependencies
ofbizPluginArchives.each { pluginArchive ->
ext.pluginId = dependencyId.tokenize(':').get(1)
println "installing plugin: ${pluginId}"
copy {
from zipTree(pluginArchive)
into "${pluginsDir}/${pluginId}"
}
gradlewSubprocess(['installPlugin', "-PpluginId=${pluginId}"])
}
}
}
task pullPluginSource(group: ofbizPlugin, description: 'Download and install a plugin from source control') {
if (project.hasProperty('pluginId')) {
task pullPluginFromSvn(type: SvnCheckout) {
svnUrl = "https://svn.apache.org/repos/asf/ofbiz/ofbiz-plugins/trunk/${pluginId}"
workspaceDir = "${pluginsDir}/${pluginId}"
}
dependsOn pullPluginFromSvn
}
doLast {
gradlewSubprocess(['installPlugin', "-PpluginId=${pluginId}"])
}
}
task pullAllPluginsSource(group: ofbizPlugin,
description: 'Download and install all plugins from source control. Warning! deletes existing plugins') {
task deleteBeforePulling {
doLast { delete "${pluginsDir}" }
}
task pullPluginsFromSvn(type: SvnCheckout, dependsOn: deleteBeforePulling) {
svnUrl = "https://svn.apache.org/repos/asf/ofbiz/ofbiz-plugins/trunk"
workspaceDir = "${pluginsDir}"
}
dependsOn pullPluginsFromSvn
task installAllPlugins {
file("${pluginsDir}").eachDir { plugin ->
iterateOverActiveComponents { component ->
if (component.name == plugin.name) {
if (subprojectExists(":plugins:${plugin.name}")) {
if (taskExistsInproject(":plugins:${plugin.name}", 'install')) {
dependsOn ":plugins:${plugin.name}:install"
doLast { println "installed plugin ${plugin.name}" }
}
}
}
}
}
}
doLast {
gradlewSubprocess(['installAllPlugins'])
}
}
// ========== Clean up tasks ==========
task cleanCatalina(group: cleanupGroup, description: 'Clean Catalina data in runtime/catalina/work') {
doLast { delete "${rootDir}/runtime/catalina/work" }
}
task cleanData(group: cleanupGroup, description: 'Clean all DB data (Derby) under runtime/data') {
doLast { deleteAllInDirWithExclusions("${rootDir}/runtime/data/", ['README', 'derby.properties']) }
}
task cleanDownloads(group: cleanupGroup, description: 'Clean all downloaded files') {
doLast {
delete fileTree(dir: "${rootDir}/framework/base/lib", includes: ['activemq-*.jar'])
delete fileTree(dir: "${rootDir}/framework/entity/lib/jdbc", includes: ['postgresql-*.jar'])
delete fileTree(dir: "${rootDir}/framework/entity/lib/jdbc", includes: ['mysql-*.jar'])
}
}
task cleanLogs(group: cleanupGroup, description: 'Clean all logs in runtime/logs') {
doLast { deleteAllInDirWithExclusions("${rootDir}/runtime/logs/", ['README']) }
}
task cleanOutput(group: cleanupGroup, description: 'Clean runtime/output directory') {
doLast { deleteAllInDirWithExclusions("${rootDir}/runtime/output/", ['README']) }
}
task cleanIndexes(group: cleanupGroup, description: 'Remove search indexes (e.g. Lucene) from runtime/indexes') {
doLast { deleteAllInDirWithExclusions("${rootDir}/runtime/indexes/", ['README', 'index.properties']) }
}
task cleanTempfiles(group: cleanupGroup, description: 'Remove file in runtime/tempfiles') {
doLast {
deleteAllInDirWithExclusions("${rootDir}/runtime/tempfiles/", ['README'])
deleteAllInDirWithExclusions("${rootDir}/runtime/tmp/", ['README'])
}
}
task cleanUploads(group: cleanupGroup, description: 'Remove uploaded files.') {
doLast { deleteAllInDirWithExclusions("${rootDir}/runtime/uploads/", []) }
}
task cleanXtra(group: cleanupGroup, description: 'Clean extra generated files like .rej, .DS_Store, etc.') {
doLast {
delete fileTree(dir: "${rootDir}",
includes: ['**/.nbattrs', '**/*~','**/.#*', '**/.DS_Store', '**/*.rej', '**/*.orig'])
}
}
task cleanFooterFiles(group: cleanupGroup, description: 'clean generated footer files') {
doLast {
delete gitFooterFile
delete svnFooterFile
}
}
/*
* Keep this task below all other clean tasks The location of
* declaration is important because it means that it will automatically
* run whenever the task cleanAll executes (dependency matched by regex)
*/
def cleanTasks = tasks.findAll { it.name ==~ /^clean.+/ }
task cleanAll(group: cleanupGroup, dependsOn: [cleanTasks, clean]) {
description 'Execute all cleaning tasks.'
}
/* ========================================================
* Rules-based OFBiz server commands
* ======================================================== */
tasks.addRule('Pattern: ofbiz <Commands>: Execute OFBiz startup commands') { String taskName ->
if (taskName ==~ /^ofbiz\s.*/ || taskName == 'ofbiz') {
def arguments = (taskName - 'ofbiz').tokenize(' ')
createOfbizCommandTask(taskName, arguments, jvmArguments, false)
}
}
tasks.addRule('Pattern: ofbizDebug <Commands>: Execute OFBiz startup commands in remote debug mode') { String taskName ->