forked from alkacon/opencms-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
610 lines (558 loc) · 21.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
import org.apache.tools.ant.filters.ReplaceTokens
apply plugin: 'java'
sourceCompatibility = java_target_version
version = version_number
buildDir = build_directory
repositories {
mavenCentral()
}
if (!project.hasProperty('max_heap_size')){
project.ext.max_heap_size='1024m'
}
Properties props = new Properties()
props.load(new FileInputStream("$projectDir/modules/all-modules.properties"))
project.ext.allModuleNames = props['modules.common.all']
project.ext.allExternalModuleNames = ''
project.ext.modulesDistsDir = file("${project.buildDir}/modulesZip")
if (project.hasProperty('external_directories')){
def externalPropFile =file(external_directories+'/modules/all-modules.properties')
if (externalPropFile.exists()){
Properties externalprops = new Properties()
println "reading external modules from ${external_directories}/modules/all-modules.properties"
externalprops.load(new FileInputStream(externalPropFile))
project.ext.allExternalModuleNames = externalprops['modules.common.all']
project.ext.allModuleNames += ','+allExternalModuleNames
}else{
println "Can\'t read from external module properties modules/all-modules.properties from directory $external_directories"
}
}
configurations {
compile {
description = 'used to compile the opencms.jar and the modules jars'
transitive = false
extendsFrom distribution
}
testCompile{
transitive = false
extendsFrom compile
}
testRuntime{
transitive = false
}
componentsCompile {
description = 'needed to compile the opencms components'
transitive = false
}
componentsRuntime {
transitive = false
extendsFrom componentsCompile
}
modulesCompile {
description = 'used to compile the modules classes'
transitive = false
extendsFrom compile
}
gwtCompile {
description = 'needed to generate the GWT JavaScript resources'
transitive = false
extendsFrom modulesCompile
}
setupCompile {
transitive = false
extendsFrom modulesCompile
}
distribution {
description = 'libraries included into the opencms distribution'
transitive = false
}
}
// import dependencies
apply from: 'dependencies.gradle'
sourceSets{
main {
java.srcDir 'src'
resources.srcDir 'src'
}
components {
java.srcDir 'src-components'
resources.srcDir 'src-components'
}
modules {
java.srcDir 'src-modules'
resources.srcDir 'src-modules'
}
gwt {
java.srcDir 'src-gwt'
resources.srcDir 'src-gwt'
}
setup {
java.srcDir 'src-setup'
resources.srcDir 'src-setup'
}
test {
java.srcDir 'test'
java.srcDir 'src'
java.srcDir 'src-modules'
java.srcDir 'src-setup'
resources.srcDir 'test'
resources.srcDir 'src'
resources.srcDir 'src-modules'
resources.srcDir 'src-setup'
}
}
// tests require to use the classes folder also for resources
sourceSets.test.output.resourcesDir =sourceSets.test.output.classesDir
task componentsJar(type: Jar) {
from sourceSets.components.output
archiveName 'opencms-components.jar'
include 'org/opencms/**'
exclude '**/.gitignore'
}
task enhance << {
ant.taskdef(
name : 'openjpaenhancer',
classpath : configurations.modulesCompile.asPath,
classname : 'org.apache.openjpa.ant.PCEnhancerTask'
)
ant.openjpaenhancer(classpath : configurations.modulesCompile.asPath){
fileset(dir: "${sourceSets.main.output.classesDir}/org/opencms/db/jpa/persistence"){
exclude(name: '*$*.class')
}
config(propertiesFile: "${projectDir}/webapp/WEB-INF/classes/META-INF/persistence.xml")
}
}
jar {
it.dependsOn enhance
manifest {
attributes 'Implementation-Title': 'Alkacon OpenCms',
'Implementation-Version': version,
'JPA-PersistenceUnits': 'DATA_OPENJPA,DATA_OPENJPA_JTA',
'Meta-Persistence': 'META-INF/persistence.xml'
}
archiveName 'opencms.jar'
include 'org/opencms/**'
include 'com/**'
exclude '**/*.html'
exclude '**/.gitignore'
metaInf {
from("${projectDir}/webapp/WEB-INF/opencms.tld")
}
from ("${projectDir}/webapp/WEB-INF/setupdata/version.properties"){
include 'version.properties'
filter(ReplaceTokens, tokens: [
OPENCMS_VERSION_NUMBER: version_number,
OPENCMS_VERSION_NAME: version_number
])
into '/org/opencms/main/'
}
}
task setupJar(dependsOn: jar, type: Jar) {
from sourceSets.setup.output
archiveName 'opencms-setup.jar'
exclude '**/.gitignore'
}
// iterate all available modules and create the required tasks
allModuleNames.split(',').each{ moduleName ->
def modulePackages = moduleName
def gwtModule = null
def moduleScripts = null
def moduleFolder = file("${projectDir}/modules/${moduleName}")
def srcGwtDir = "${projectDir}/src-gwt/"
def moduleSrcFolder = file("${projectDir}/src-modules")
def isExternal = allExternalModuleNames.contains(moduleName)
if (isExternal.toBoolean()){
moduleFolder = file("${external_directories}/modules/${moduleName}")
srcGwtDir = file("${external_directories}/src-gwt/")
moduleSrcFolder = file("${external_directories}/src-modules")
}
def propertyFile = file("${moduleFolder}/module.properties")
def gwtRename = null
if (propertyFile.exists()){
Properties moduleProperties= new Properties()
moduleProperties.load(new FileInputStream(propertyFile))
if (moduleProperties['module.packages']!=null){
modulePackages=moduleProperties['module.packages']
}
if (moduleProperties['module.gwt']!=null){
gwtModule = moduleProperties['module.gwt']
def moduleXml = (new XmlParser()).parse(srcGwtDir.toString()+"/" +gwtModule.replaceAll('\\.','/')+'.gwt.xml')
gwtRename = moduleXml['@rename-to']
if (gwtRename==null){
gwtRename=moduleName
}
}
if (moduleProperties['module.scripts']!=null){
moduleScripts=moduleProperties['module.scripts']
}
}
def manifestFile = file("${moduleFolder}/resources/manifest.xml")
def moduleDependencies=[]
def moduleVersion = version
if (manifestFile.exists()){
def parsedManifest= (new XmlParser()).parse("${moduleFolder}/resources/manifest.xml")
parsedManifest.module[0].dependencies[0].dependency.each{ dep ->
moduleDependencies.add(dep.@name)
}
moduleVersion = parsedManifest.module[0].version[0].text()
}
def requiresJar = false
// check if there are any java packages to include into the module's jar
modulePackages.split(',').each{ pack ->
def packageFolder
if (isExternal.toBoolean()){
packageFolder= file("${external_directories}/src-modules/"+ pack.replaceAll('\\.','/'))
}else{
packageFolder= file("${projectDir}/src-modules/"+ pack.replaceAll('\\.','/'))
}
if (packageFolder.exists()&&packageFolder.isDirectory()){
packageFolder.listFiles().each{ file ->
if (file.isFile()){
requiresJar = true
}
}
}
}
task "dist_$moduleName" (dependsOn: componentsJar, type: Zip){
ext.moduleName = moduleName
ext.modulePackages = modulePackages
ext.gwtModule = gwtModule
ext.moduleScripts = moduleScripts
ext.moduleFolder = moduleFolder
ext.srcGwtDir = srcGwtDir
ext.isExternal = isExternal
ext.requiresJar = requiresJar
ext.dependencies = moduleDependencies
ext.gwtRenameTo = gwtRename
version moduleVersion
destinationDir modulesDistsDir
// include the jar file if necessary
if (requiresJar.toBoolean()){
from( "${project.buildDir}/libs") {
include "${moduleName}.jar"
into "/system/modules/${moduleName}/lib/"
}
}
// include the GWT resources if necessary
if (gwtModule == null){
from "${moduleFolder}/resources"
}else{
// exclude the manifest for now, use the synced manifest later
from ("${moduleFolder}/resources") {
exclude 'manifest.xml'
exclude "system/modules/${moduleName}/resources/${gwtRenameTo}/**"
}
from( "${project.buildDir}/gwt/${moduleName}") {
exclude '**/WEB-INF/**'
into "/system/modules/${moduleName}/resources/"
}
def syncedManifest="${project.buildDir}/extra/${moduleName}/manifest.xml"
from syncedManifest
doFirst{
ant.taskdef(resource: 'org/opencms/util/ant/taskdefs.properties', classpath: configurations.componentsRuntime.asPath)
ant.syncmanifest(
srcmanifestfile: "${moduleFolder}/resources/manifest.xml",
dstmanifestfile: syncedManifest,
base: "${moduleFolder}/resources/",
prefix: "system/modules/${moduleName}/resources/${gwtRenameTo}",
directory: "${project.buildDir}/gwt/${moduleName}/${gwtRenameTo}"
)
}
}
if (moduleScripts != null){
from( "${project.buildDir}/scripts/${moduleName}") {
into "/system/modules/${moduleName}/resources/"
}
}
baseName moduleName
doFirst {
println '======================================================'
println "Building ZIP for $moduleName version $moduleVersion"
println '======================================================'
}
}
if (requiresJar.toBoolean()){
sourceSets.create(moduleName)
sourceSets[moduleName].java.srcDirs=files("$moduleSrcFolder")
sourceSets[moduleName].resources.srcDirs=files("$moduleSrcFolder")
modulePackages.split(',').each{ pack ->
sourceSets[moduleName].java.includes.add(pack.replaceAll('\\.','/')+'/**')
sourceSets[moduleName].resources.includes.add(pack.replaceAll('\\.','/')+'/**')
}
sourceSets[moduleName].compileClasspath=configurations.modulesCompile
task "jar_$moduleName" (type: Jar) {
manifest {
attributes 'Implementation-Title': 'Alkacon OpenCms', 'Implementation-Version': version
}
from sourceSets[moduleName].output
archiveName moduleName+'.jar'
exclude '**/.gitignore'
doFirst{
println '======================================================'
println "Building ${moduleName}.jar including $modulePackages"
println '======================================================'
}
}
tasks["dist_$moduleName"].dependsOn("jar_$moduleName")
}
if (gwtModule != null){
sourceSets.create(moduleName+'_gwt')
sourceSets[moduleName+'_gwt'].java.srcDirs=files("$srcGwtDir")
sourceSets[moduleName+'_gwt'].resources.srcDirs=files("$srcGwtDir")
task "gwt_$moduleName" (dependsOn: gwtClasses, type: JavaExec) {
ext.buildDir = project.buildDir.toString() +"/gwt/$moduleName"
ext.extraDir = project.buildDir.toString() + "/extra/$moduleName"
inputs.source sourceSets.gwt.java.srcDirs
inputs.dir sourceSets.gwt.output.resourcesDir
outputs.dir buildDir
// Workaround for incremental build (GRADLE-1483)
outputs.upToDateSpec = new org.gradle.api.specs.AndSpec()
doFirst {
println '======================================================'
println "Building GWT resources for $gwtModule"
println '======================================================'
// to clean the output directory, delete it first
def dir = file(buildDir)
if (dir.exists()){
delete{
delete dir
}
}
dir.mkdirs()
}
main = 'com.google.gwt.dev.Compiler'
classpath {
[
sourceSets.main.java.srcDirs, // Java source core
sourceSets.gwt.java.srcDirs, // Java source
sourceSets.gwt.output.resourcesDir, // Generated resources
sourceSets.gwt.output.classesDir, // Generated classes
sourceSets.gwt.compileClasspath, // Deps
sourceSets[moduleName+'_gwt'].java.srcDirs,
sourceSets[moduleName+'_gwt'].output.resourcesDir,
sourceSets[moduleName+'_gwt'].output.classesDir
]
}
args =
[
gwtModule, // Your GWT module
'-war', buildDir,
'-logLevel', 'INFO',
'-localWorkers', '2',
'-style', 'obfuscated',
'-compileReport',
'-extra', extraDir,
'-strict'
// '-draftCompile' // Speeds up compile with 25%
]
maxHeapSize = max_heap_size
}
tasks["dist_$moduleName"].dependsOn("gwt_$moduleName")
}
if (moduleScripts != null){
task "scripts_$moduleName" {
ext.srcDir = file("${moduleFolder}/scripts")
ext.destDir = new File("${project.buildDir}/scripts/$moduleName")
inputs.dir srcDir
outputs.dir destDir
doFirst{
// to clean the output directory, delete it first
if (destDir.exists()){
delete {
delete destDir
}
}
destDir.mkdirs()
}
doLast {
def text=''
moduleScripts.split(',').each{ script ->
def scriptFile = file("${srcDir}/$script")
if (scriptFile.exists()){
text += scriptFile.text
}
}
def destFile = new File(destDir, moduleName+'.scripts.js')
destFile.write(text)
}
}
tasks["dist_$moduleName"].dependsOn("scripts_$moduleName")
}
}
tasks.findAll{ task -> task.name.startsWith('dist_')}.each{ dist_task ->
if (dist_task.requiresJar.toBoolean()){
dist_task.dependencies.each{ dep ->
def depCompileName = 'compile'+dep.replaceAll('\\.','')+'java'
tasks.findAll{ comp_task -> comp_task.name.toLowerCase().equals(depCompileName)}.each {comp_task ->
sourceSets[dist_task.moduleName].compileClasspath += files("${project.buildDir}/classes/$dep") {
builtBy comp_task.name
}
}
}
tasks['jar_'+dist_task.moduleName].dependsOn{
tasks.findAll{ comp_task -> comp_task.name.toLowerCase().equals('compile'+dist_task.moduleName.replaceAll('\\.','')+'java')}
}
}
}
task allModules(dependsOn: tasks.matching{ Task task -> task.name.startsWith('dist_')}) << {
println '======================================================'
println 'Done building modules'
println '======================================================'
}
task war (dependsOn: [setupJar, allModules], type: Zip){
archiveName 'opencms.war'
from ("${projectDir}/webapp"){
// exclude the database drivers
exclude '**/setup/**/*.jar'
exclude '**/update/**'
exclude '**/*.html'
exclude '**/*.properties'
exclude '**/*.txt'
exclude '**/*.xml'
}
from ("${projectDir}/webapp"){
exclude '**/update/**'
include '**/*.html'
include '**/*.properties'
include '**/*.txt'
include '**/*.xml'
filter(ReplaceTokens, tokens: [
OPENCMS_VERSION_NUMBER: version_number,
OPENCMS_VERSION_NAME: version_number,
OPENCMS_VERSION: product_name+' '+version_number,
DRIVERS_VFS: drivers_vfs,
DRIVERS_PROJECT: drivers_project,
DRIVERS_USER: drivers_user,
DRIVERS_HISTORY: drivers_history,
DRIVERS_CONFIGURATION: drivers_configuration,
DRIVERS_SUBSCRIPTION: drivers_subscription,
ADDITIONAL_DB_POOLS: db_additional_pools,
OPENCMS_CONFIGURATION: opencms_configuration,
RUNTIME_INFO: system_runtimeinfo
])
}
from ("${project.buildDir}/libs") {
include '*.jar'
exclude 'opencms-components.jar'
into '/WEB-INF/lib'
}
into ('/WEB-INF/lib') {
from configurations.distribution
}
fileTree('webapp/setup/database'){ include '**/*.jar'}.each {File driverJar ->
// copy the database drivers into the lib folder
from (driverJar.path) {
into '/WEB-INF/lib'
}
}
from (modulesDistsDir) {
into '/WEB-INF/packages/modules'
}
from("${projectDir}/lib/jni") {
into "/WEB-INF/lib/jni"
}
}
task updater (dependsOn: setupJar, type: Zip){
baseName 'opencms-upgrade-to'
from ("${projectDir}/webapp"){
include 'update/**'
exclude 'update/empty.jar'
exclude 'update/readme.txt'
filter(ReplaceTokens, tokens: [
OPENCMS_VERSION_NUMBER: version_number,
OPENCMS_VERSION: product_name+' '+version_number
])
}
from ("${projectDir}/webapp/WEB-INF/solr/conf"){
into '/WEB-INF/solr-update/'
include 'schema.xml'
include 'solrconfig.xml'
}
from ("${projectDir}/webapp/update/readme.txt"){
filter(ReplaceTokens, tokens: [
OPENCMS_VERSION_NUMBER: version_number,
OPENCMS_VERSION: product_name+' '+version_number
])
}
from ("${projectDir}/webapp/WEB-INF"){
into '/WEB-INF'
include 'opencms.tld'
include 'web.xml'
include 'cmsshell.sh'
include 'classes/META-INF/persistence.xml'
include 'classes/ehcache.xml'
include 'classes/repository.properties'
include 'sun-jaxws.xml'
include 'wsdl/**'
}
from ("${project.buildDir}/libs") {
include 'opencms.jar'
include 'opencms-setup.jar'
into '/WEB-INF/lib'
}
into ('/WEB-INF/lib') {
from configurations.distribution
}
tasks.findAll{dist_task -> dist_task.name.startsWith('dist_') && !(updater_excluded_modules.split(',').contains(dist_task.moduleName))}.each{ dist_task ->
from ("${modulesDistsDir}/${dist_task.archiveName}"){
into '/update/modules'
}
if (dist_task.requiresJar.toBoolean()){
from ("${project.buildDir}/libs/${dist_task.moduleName}.jar"){
into 'WEB-INF/lib'
}
}
}
fileTree('webapp/setup/database'){ include '**/*.jar'}.each {File driverJar ->
// copy the database drivers into the lib folder
from (driverJar.path) {
into '/WEB-INF/lib'
}
}
Properties buildProps = new Properties()
buildProps.load(new FileInputStream("${projectDir}/build-default.properties"))
buildProps['updater.jars.remove'].split(',').each{ jar ->
from("${projectDir}/webapp/update/empty.jar"){
into '/WEB-INF/lib'
rename('empty\\.jar', jar)
}
}
}
updater.dependsOn(tasks.matching{dist_task -> dist_task.name.startsWith('dist_') && !(updater_excluded_modules.split(',').contains(dist_task.moduleName))})
task bindist (dependsOn: war, type: Zip){
baseName 'opencms'
from "${project.buildDir}/distributions/opencms.war"
from(projectDir) {
include 'install.html'
include 'license.txt'
include 'history.txt'
filter(ReplaceTokens, tokens: [
OPENCMS_VERSION_NUMBER: version_number,
OPENCMS_VERSION: product_name+' '+version_number
])
}
}
compileTestJava {
// adding the GWT messages classes to the test source as the client message bundles will be tested as well
def testSource=fileTree(dir: "${projectDir}/src-gwt", include: ['**/*Messages.java', '**/CmsDateTimeUtil.java'], exclude: '**/super-src/**')
testSource =testSource.plus(sourceSets.test.java)
source testSource
}
test {
useJUnit()
include 'org/opencms/test/AllTests*'
// important: exclude all anonymous classes
exclude '**/*$*.class'
scanForTestClasses false
testClassesDir = sourceSets.test.output.classesDir
systemProperties['test.data.path'] = "${projectDir}/test/data"
systemProperties['test.webapp.path'] = "${projectDir}/webapp"
systemProperties['test.build.folder'] =sourceSets.test.output.classesDir
maxHeapSize = max_heap_size
jvmArgs '-XX:MaxPermSize=256m'
testLogging.showStandardStreams = true
ignoreFailures true
}
// fixed issue with libraries containing both .java and .class files
tasks.withType(JavaCompile) {
options.compilerArgs += ["-sourcepath", ""]
}