-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
732 lines (678 loc) · 26.7 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
plugins {
id 'com.admc.ivyxml' version '1.0.0'
id 'com.admc.javaPropFile' version '1.0.0'
}
apply plugin: 'java'
defaultTasks 'jar'
import com.admc.gradle.GradleUtil
ivyxml.load()
def localGradleFile = file('local.gradle')
if (localGradleFile.isFile()) {
logger.info("Executing optional build file '$localGradleFile'.")
apply from: localGradleFile
}
// Defaults that can be overridden with property files:
compileJava.sourceCompatibility = '1.6'
compileJava.targetCompatibility = compileJava.sourceCompatibility
// compileJava.options.bootClasspath Needs to be set in local properties file
project.ext.set('org.name', System.properties['user.name'])
project.ext.set('jar.title', 'Customization')
project.ext.set('jqueryVer', '1.10.2')
project.ext.set('jqueryUiVer', '1.10.3')
propFileLoader.typeCasting = true
propFileLoader.traditionalPropertiesInit()
if (hasProperty("xlint")) compileJava.options.compilerArgs << "-Xlint:$xlint"
repositories { mavenCentral() }
task noop << { }
noop.description = 'Noop task for Gradle testing'
// compileOnly is a Work-around for short-sighted Maven convention where
// Runtime classpath must include every compilation classpath element:
configurations {
compileOnly
jflex
beaver
baseconf
}
project.ext.set('rtLibs', null)
jar { doFirst {
project.ext.set('rtLibs', [])
configurations.runtime.files.each { project.rtLibs << it.name }
project.metaInf << files('doc/LICENSE.txt')
jar {
exclude '**/.*/**'
manifest { attributes(
'Main-Class': 'com.admc.jcreole.JCreole',
'Class-Path': project.rtLibs.join(' '),
'Specification-Title': 'JCreole',
'Specification-Version': project.property('spec.version'),
'Specification-Vendor': 'Axis Data Management Corp.',
'Implementation-Title': project.property('jar.title'),
'Implementation-Version': project.version,
'Implementation-Vendor': project.property('org.name')
) }
}
} }
File grammarFile = file('src/main/java/com/admc/jcreole/CreoleParser.grammar')
File scannerFile =
file('build/derived-src/com/admc/jcreole/CreoleScanner.java')
File lexSpecFile = file('src/main/java/com/admc/jcreole/creole.flex')
File parserFile = file('build/derived-src/com/admc/jcreole/CreoleParser.java')
File termsFile = file('build/derived-src/com/admc/jcreole/Terminals.java')
task beaver {
inputs.source grammarFile
outputs.file parserFile
}
beaver << {
if (parserFile.exists()) parserFile.delete()
javaexec {
main = '-jar'
args = [configurations.beaver.asPath, '-d', 'build/derived-src',
'-t', '-T', grammarFile.path]
}
assert parserFile.exists()
}
beaver.description = '''Generate Beaver parser 'CreoleParser'.'''
beaver.dependsOn << { GradleUtil.verifyResolve(configurations.beaver) }
task jflex(dependsOn: beaver) {
inputs.source lexSpecFile
inputs.source termsFile
outputs.file scannerFile
inputs.source fileTree (
dir:'src/main/java',
exclude:'**/.*/**',
include:'**/*.grammar'
)
}
jflex << {
assert termsFile.exists():
'dependOn failed to generate Terminals.java before JFlex runs'
String jxVerbSwitch = ((project.hasProperty('jflex.verbose')
&& Boolean.parseBoolean(project.property('jflex.verbose')))
? '-v' : '-q')
javaexec {
main = '-jar'
args = [configurations.jflex.asPath, '-d',
// JFlex is so brain-dead that unlike their own Ant task,
// their base product won't move output files into
// appropriate package subdirectories, so we must specify.
'build/derived-src/com/admc/jcreole', jxVerbSwitch,
'--nobak', lexSpecFile.path]
}
}
jflex.description = '''Generate JFlex scanner 'CreoleScanner'.'''
jflex.dependsOn << { GradleUtil.verifyResolve(configurations.jflex) }
// This task only for SCM administrator. Upgrade version and execute this task.
task upgradeWrapper(type: Wrapper) { doFirst {
assert project.hasProperty('newVersion') :
'''Property 'newVersion' is required for task 'upgradeWrapper'.'''
assert project.newVersion == gradle.gradleVersion :
"You invoked Gradle system with version $gradle.gradleVersion instead of desired version $project.newVersion"
} }
upgradeWrapper << {
gradleVersion = project['newVersion']
println 'WARNING: Merge our customizations into the newly-generated wrapper scripts'
}
upgradeWrapper.description = 'Upgrade Gradle version. For SCM Administrators.'
task serialver(dependsOn: compileJava) << {
assert project.hasProperty('className'):
'''Property 'className' is required for task 'serialver'.'''
String fileSep = System.properties['file.separator']
String javaHome = System.properties['java.home']
String javacHome = (javaHome.endsWith("jre")
? javaHome.substring(0, javaHome.length() - "/jre".length())
: javaHome)
// Could alternatively use Gradle's ExecSpec via exec(...)
Process process = new ProcessBuilder([
javacHome + fileSep + 'bin' + fileSep + 'serialver',
'-classpath',
'classes' + System.properties['path.separator']
+ configurations.runtime.asPath,
project.property('className')
]).redirectErrorStream(true).start()
// Must read input before waitFor-ing
File outFile = new File(System.properties['java.io.tmpdir'],
'serialVer-' + System.properties['user.name'] + '.txt')
process.inputStream.eachLine { println it; outFile.write(it + '\n') }
assert process.waitFor() == 0: '''Execution of 'serialver' failed'''
println """Also written to file '$outFile.absolutePath'
so you can read it into your editor."""
}
serialver.description = "Generates Java serialversion for specified 'classname'"
compileJava.dependsOn jflex
// This parallels what built-in source set 'providedCompile' does for wars.
compileJava.doFirst {
setClasspath(compileJava.classpath.plus(configurations.buildOnly))
assert compileJava.options.bootClasspath != null:
"""For portability, we require a JRE 6 rt lib. Set in 'local.properties' like
compileJava.options.bootClasspath =/local/jdk1.6.0_30/jre/lib/rt.jar\n"""
assert file(compileJava.options.bootClasspath).isFile():
"compileJava.options.bootClasspath value not a file: " +
compileJava.options.bootClasspath
}
sourceSets.main.java.srcDirs = [file('src/main/java'), file('build/derived-src')]
compileJava.dependsOn << { GradleUtil.verifyResolve(configurations.compile) }
compileTestJava.dependsOn << {
GradleUtil.verifyResolve(configurations.testCompile)
}
task checkTabs << {
FileTree tree = fileTree(dir: '.')
tree.exclude '**/.*/**'
tree.include '*.*'
tree.include 'gradlew'
tree.include 'src/**'
tree.include 'doc/**'
def tabFiles = []
tree.each { if (it.text.indexOf('\t') > -1) tabFiles << relativePath(it) }
if (tabFiles.size() > 0) println ' ' + tabFiles.join('\n ')
}
checkTabs.description = 'Reports on any text files containing tab characters'
task zip(dependsOn: ['standaloneRef', 'internetRef', 'javadoc'], type: Zip) {
exclude '**/.*/**'
from configurations.runtime.allArtifacts.files
from configurations.runtime
into(project.name + '-' + project.version)
from ('build/docs/javadoc') { into 'apidocs' }
from ('.') { include 'doc/**' }
from ('.') {
include 'README.txt'
into 'doc'
}
from ('build/distributions') {
include 'jcreole-ref-*.html'
into 'doc'
}
}
zip.description =
'Build zip of end-user executable JCreole jar with dependencies'
task srcZip(dependsOn: ['standaloneRef', 'internetRef', 'javadoc'], type: Zip) {
classifier = 'src'
exclude '**/.*/**'
into(project.name + '-' + project.version)
from ('build/docs/javadoc') { into 'apidocs' }
from ('.') {
include 'app.properties'
include 'ivy.xml'
include 'README.txt'
include 'template*/**'
include 'src/**'
include 'doc/**'
include 'build.gradle'
include 'common.gradle'
include 'gradle/**'
include 'gradlew'
include 'gradlew.bat'
include 'config/**'
}
}
srcZip.description = 'Build source distribution zip file'
task stage(dependsOn: jar, type: Copy) {
from configurations.runtime.allArtifacts.files
from configurations.runtime
into 'build/stage'
}
stage.description = 'Stage JCreole jar and dependency jars in build/stage'
task ensureLogCfgfile << {
/* ensureLogCfgfile uses onlyIf instead of inputs/outputs for running
* conditionally, because we only want to run it if the destination file
* is missing, regardless of file ages. */
assert !project.julCfgfile.exists():
"""ensureLogCfgfile's onlyIf not working because running even though
target file exists: $project.julCfgfile.absolutePath"""
project.julCfgfile.write(
file('template-jul.properties').getText('ISO-8859-1'), 'ISO-8859-1')
println """Local logging cfg file created. Edit per your needs:
$julCfgfile"""
}
ensureLogCfgfile.onlyIf {
project.ext.set('julCfgfile', new File(project.hasProperty('jul.cfgfile')
? project.property('jul.cfgfile') : 'local-jul.properties'))
!project.julCfgfile.exists()
}
private void ref(String style) {
assert style != null:
'''Parameter 'style' may not be null.
'''
String boilerQualifier = null
switch (style) {
case 'i': // Internet
boilerQualifier = 'inet'
break
case 's': // Standalone
boilerQualifier = 'standalone'
break
default:
assert false: """Unsupported 'style' param value: $style
"""
}
String outputDoc = 'build/distributions/jcreole-ref-' + style + '.html'
javaexec {
main = '-jar'
args = [ 'build/stage/' + jar.archiveName,
'-r',
'boilerplate-' + boilerQualifier + '.html',
'-o',
outputDoc,
'jcreole-ref.creole'
]
systemProperties 'java.util.logging.config.file': julCfgfile.path
}
println "HTML reference written to '$outputDoc'."
}
task internetRef(dependsOn: ['stage', 'ensureLogCfgfile']) << {
ref('i')
}
internetRef.onlyIf {
File f = file('build/distributions/jcreole-ref-i.html')
if (!f.exists()) return true
long lastMod = f.lastModified()
File fOther = file('build/stage/' + jar.archiveName)
assert fOther.exists()
if (fOther.lastModified() > lastMod) return true
fOther = file('src/main/resources/jcreole-ref.creole')
assert fOther.exists()
if (fOther.lastModified() > lastMod) return true
fOther = file('src/main/resources/boilerplate-inet.html')
assert fOther.exists()
if (fOther.lastModified() > lastMod) return true
fOther = file('src/main/webapp/site.css')
assert fOther.exists()
if (fOther.lastModified() > lastMod) return true
fOther = file('src/main/webapp/jcreole.css')
assert fOther.exists()
if (fOther.lastModified() > lastMod) return true
return false
}
internetRef.description = 'Generate Standalone JCreole Reference doc'
task standaloneRef(dependsOn: ['stage', 'ensureLogCfgfile']) << {
ref('s')
}
standaloneRef.onlyIf {
File f = file('build/distributions/jcreole-ref-s.html')
if (!f.exists()) return true
long lastMod = f.lastModified()
File fOther = file('build/stage/' + jar.archiveName)
assert fOther.exists()
if (fOther.lastModified() > lastMod) return true
fOther = file('src/main/resources/jcreole-ref.creole')
assert fOther.exists()
if (fOther.lastModified() > lastMod) return true
fOther = file('src/main/resources/boilerplate-standalone.html')
assert fOther.exists()
if (fOther.lastModified() > lastMod) return true
fOther = file('src/main/webapp/site.css')
assert fOther.exists()
if (fOther.lastModified() > lastMod) return true
fOther = file('src/main/webapp/jcreole.css')
assert fOther.exists()
if (fOther.lastModified() > lastMod) return true
return false
}
standaloneRef.description = 'Generate Standalone JCreole Reference doc'
task html(dependsOn: ['stage', 'ensureLogCfgfile']) << {
assert project.hasProperty('creolepath'):
'''Property 'creolepath' is required by task 'html'.'''
if (!project.hasProperty('htmloutPath'))
project.ext.set('htmloutPath', 'build/tmp/generated.html')
javaexec {
main = '-jar'
args = [ 'build/stage/' + jar.archiveName,
'-o',
project.htmloutPath,
project.creolepath
]
systemProperties 'java.util.logging.config.file': julCfgfile.path
}
println """HTML written to '$project.htmloutPath'.
If the document includes relative links, you'll need to copy the resources
accordingly."""
}
html.description = 'Generate HTML'
task scan(dependsOn: ['compileJava', 'ensureLogCfgfile']) << {
assert project.hasProperty('creolepath'):
'''Property 'creolepath' is required by task 'scan'.'''
javaexec {
main = 'com.admc.jcreole.JFlexDriver'
args = [project.creolepath]
classpath file('build/classes/main')
classpath configurations.runtime.asPath
systemProperties 'java.util.logging.config.file': julCfgfile.path
}
}
scan.description = 'Run JFlex scanner'
task parse(dependsOn: ['compileJava', 'ensureLogCfgfile']) << {
assert project.hasProperty('creolepath'):
'''Property 'creolepath' is required by task 'parse'.'''
javaexec {
main = 'com.admc.jcreole.JCreole'
args = ['-', project.creolepath]
classpath file('build/classes/main')
classpath configurations.runtime.asPath
systemProperties 'java.util.logging.config.file': julCfgfile.path
}
}
parse.description = 'Run Beaver parser'
task sourcesJar(type: Jar, dependsOn:classes) {
exclude '**/.*/**'
classifier = 'sources'
from sourceSets.main.allSource
}
sourcesJar.description = 'Build sources jar file'
task javadocJar(type: Jar, dependsOn:javadoc) {
exclude '**/.*/**'
classifier = 'javadoc'
from javadoc.destinationDir
}
javadocJar.description = 'Build javadoc jar file'
javadoc {
classpath += configurations.buildOnly
}
test.inputs.dir 'src/test/data'
import com.admc.gradle.ContentAsStringFilter
import com.admc.gradle.JavaPropFile
processResources {
String siteCss = file('src/main/webapp/site.css').getText('UTF-8')
String jcreoleCss = file('src/main/webapp/jcreole.css').getText('UTF-8')
exclude '**/.*/**'
// The eachFile intermediary here is how you filter a subset of a
// plugin-provided input file collection (in this case, the resource
// file collection provided by the java plugin).
eachFile { fcd ->
// Unlike Gradles plain {... } filter, our closure here will get
// executed just one time for each matching file.
if (fcd.name == 'boilerplate-inet.html')
fcd.filter(ContentAsStringFilter, closure: {
// Making this setting immediately before the expand() call to
// eliminate dependencies on Gradle's complicated
// execution-time dependencies.
propFileLoader.unsatisfiedRefBehavior =
JavaPropFile.Behavior.LITERAL
/* N.b. You will run into classpath problems for the setting
* above if you nest this build file into another with
* 'apply from'. This is due to terrible project
* hierarchy design in Gradle. */
propFileLoader.expand(it, [
('ver|jquery'): project.jqueryVer,
('ver|jqueryui'): project.jqueryUiVer,
('ver|jcreole'): project.version,
('buildInc|siteCss'): siteCss,
('buildInc|jcreoleCss'): jcreoleCss,
])
})
if (fcd.name == 'boilerplate-standalone.html')
fcd.filter(ContentAsStringFilter, closure: {
// Making this setting immediately before the expand() call to
// eliminate dependencies on Gradle's complicated
// execution-time dependencies.
propFileLoader.unsatisfiedRefBehavior =
JavaPropFile.Behavior.LITERAL
/* N.b. You will run into classpath problems for the setting
* above if you nest this build file into another with
* 'apply from'. This is due to terrible project
* hierarchy design in Gradle. */
propFileLoader.expand(it, [
('ver|jcreole'): project.version,
('buildInc|siteCss'): siteCss,
('buildInc|jcreoleCss'): jcreoleCss,
])
})
}
}
apply plugin: 'maven'
apply plugin: 'signing'
signing {
sign configurations.archives
}
artifacts {
archives sourcesJar
archives javadocJar
}
configurations { deployJars }
if (project.hasProperty('mavenRepository.dest.url')) {
def url = project.property('mavenRepository.dest.url')
assert url != null:
'''Property 'mavenRepository.dest.url' may not be null
'''
assert url instanceof URL:
('''Property 'mavenRepository.dest.url' must be of type URL. Is a '''
+ url.class.name + '\n')
if (url.protocol == 'scp') {
repositories { mavenCentral() }
dependencies {
deployJars 'org.apache.maven.wagon:wagon-ssh:latest.milestone'
}
}
}
uploadArchives {
def authMap = [:]
if (project.hasProperty('mavenRepository.dest.username'))
authMap['userName'] = project.property('mavenRepository.dest.username')
if (project.hasProperty('mavenRepository.dest.password'))
authMap['password'] = project.property('mavenRepository.dest.password')
if (project.hasProperty('mavenRepository.dest.privateKey'))
authMap['privateKey'] =
project.property('mavenRepository.dest.privateKey')
repositories.mavenDeployer {
configuration = configurations.deployJars
beforeDeployment {
MavenDeployment deployment -> signing.signPom(deployment)
}
if (project.hasProperty('mavenRepository.dest.url'))
repository(url: project.property('mavenRepository.dest.url')) {
authentication(authMap)
}
pom.project {
// The hasProperty tests are necessary even for required variables
// because this code is evaluated even if the uploadArchives task
// will never be executed.
if (project.hasProperty('title')) name project.property('title')
if (project.hasProperty('description'))
description project.property('description')
if (project.hasProperty('url')) url project.property('url')
if (project.hasProperty('inceptionYear'))
inceptionYear project.property('inceptionYear')
scm {
if (project.hasProperty('scm.url'))
url project.property('scm.url')
if (project.hasProperty('scm.connection'))
connection project.property('scm.connection')
if (project.hasProperty('scm.tag'))
tag project.property('scm.tag')
}
if (project.hasProperty('org.name')
|| project.hasProperty('org.url')) organization {
if (project.hasProperty('org.name'))
name project.property('org.name')
if (project.hasProperty('org.url'))
url project.property('org.url')
}
licenses {
license {
name 'Apache 2.0'
url 'https://github.com/unsaved/jcreole/raw/master/doc/LICENSE.txt'
distribution 'repo'
}
}
if (project.hasProperty('developer.name')
|| project.hasProperty('developer.email')) developers {
developer {
if (project.hasProperty('developer.id'))
id project.property('developer.id')
if (project.hasProperty('developer.name'))
name project.property('developer.name')
if (project.hasProperty('developer.email'))
email project.property('developer.email')
}
}
}
}
}
uploadArchives { doFirst {
['title', 'group', 'mavenRepository.dest.url', 'scm.connection',
'scm.url', 'url', 'inceptionYear', 'description'].each {
assert (project.hasProperty(it) && project.property(it) != null
&& project.property(it) != '') :
"""Property '$it' is required by 'uploadArchives' task.
"""
}
['mavenRepository.dest.url', 'scm.url', 'url', 'org.url'].each {
assert project.property(it) != null:
"""Property '$it' may not be null
"""
assert (!project.hasProperty(it)
|| project.property(it) instanceof URL):
("""Property '$it' must be of type URL. Is a """
+ project.property(it).class.name + '\n')
}
} }
task springWar(dependsOn: jar, type: Jar) {
extension = 'war'
baseName = 'springDocServer'
exclude '**/.*/**'
from('src/main/webapp') {
eachFile { fcd ->
// Unlike Gradle's plain {... } filter, our closure here will get
// executed just one time for each matching file.
if (fcd.name == 'boilerplate.html')
fcd.filter(ContentAsStringFilter, closure: {
propFileLoader.unsatisfiedRefBehavior =
JavaPropFile.Behavior.LITERAL
propFileLoader.expand(it, [
('ver|jquery'): project.jqueryVer,
('ver|jqueryui'): project.jqueryUiVer,
('ver|jcreole'): project.version,
])
})
}
}
copy {
from 'config/spring-web.xml'
into 'build/tmp'
rename { 'web.xml' }
}
into('WEB-INF') { from 'config'; includes = ['applicationContext.xml'] }
into('WEB-INF') { from 'build/tmp'; includes = ['web.xml'] }
into('WEB-INF/lib') {
from configurations.compile
from configurations.spring_rt
from jar.archivePath
}
//metaInf { from 'config/context.xml' }
}
task war(dependsOn: jar, type: Jar) {
extension = 'war'
baseName = 'docServer'
exclude '**/.*/**'
from('src/main/webapp') {
eachFile { fcd ->
// Unlike Gradle's plain {... } filter, our closure here will get
// executed just one time for each matching file.
if (fcd.name == 'boilerplate.html')
fcd.filter(ContentAsStringFilter, closure: {
propFileLoader.unsatisfiedRefBehavior =
JavaPropFile.Behavior.LITERAL
propFileLoader.expand(it, [
('ver|jquery'): project.jqueryVer,
('ver|jqueryui'): project.jqueryUiVer,
('ver|jcreole'): project.version,
])
})
}
}
into('WEB-INF') { from 'config'; excludes = [
'**/.*/**', 'context.xml', 'applicationContext.xml', 'spring-web.xml'] }
into('WEB-INF/lib') {
from configurations.compile
from jar.archivePath
}
//metaInf { from 'config/context.xml' }
}
//war.doFirst { GradleUtil.verifyResolve(configurations.runtime) }
File explodeDest() {
if (!project.hasProperty('explode.suffix'))
project.ext.set('explode.suffix', '')
if (!project.hasProperty('deploy.dir')
&& !project.hasProperty('deploy.explode.dir'))
throw new GradleException(
"You must set property 'deploy.explode.dir' or 'deploy.dir'")
return new File(project.hasProperty('deploy.explode.dir')
? project.property('deploy.explode.dir')
: project.property('deploy.dir'),
war.baseName + project.property('explode.suffix'))
}
File warDest() {
if (!project.hasProperty('deploy.dir')) return null
return new File(project.property('deploy.dir'), war.baseName + '.war')
}
task deploy (dependsOn: war) << {
File dest = warDest()
if (dest == null)
throw new GradleException("You must set property 'deploy.dir'")
copy {
from war.archivePath
into dest.parentFile
rename { dest.name }
}
}
deploy.description = 'Deploy to app server in war format'
task explode (dependsOn: war) << {
File dest = explodeDest()
copy {
from zipTree(war.archivePath)
into dest
}
new File(dest, 'WEB-INF/web.xml').setLastModified(new Date().time)
}
explode.description = 'Deploy to app server in exploded format'
task undeploy << {
explodeDest().deleteDir()
File warDest = warDest()
if (warDest != null) warDest.delete()
}
undeploy.description = 'Undeploy'
task aundeploy(dependsOn: undeploy) // Work-around for alpha sequence of deps.
aundeploy.description =
'Undeploy. Task renamed to work around Gradle sequencing bug'
task reexplode(dependsOn: [aundeploy, explode])
reexplode.description = 'Undeploy then explode'
task redeploy(dependsOn: [aundeploy, deploy])
redeploy.description = 'Undeploy then deploy'
task deployableWar (dependsOn: war) << {
File shortWar = new File(libsDir, war.baseName + '.war')
if (!war.archivePath.canRead())
throw new GradleException(
'Somehow source war not available: ' + war.archivePath)
if (shortWar.canRead()
&& war.archivePath.lastModified() > shortWar.lastModified())
if (!shortWar.delete())
throw new GradleException("Failed to delete '" + shortWar + "'")
if (shortWar.canRead()) return
try {
if (['ln', '-s', war.archivePath.absolutePath, shortWar.absolutePath]
.execute().waitFor())
throw new GradleException('ln failed: ' +
['ln', '-s', war.archivePath.absolutePath,
shortWar.absolutePath]
.join(' '))
} catch (IOException ioe) {
copy {
from war.archivePath
into shortWar.parentFile
rename { shortWar.name }
}
}
}
deployableWar.description =
'Copies war to a file name suitable for direct deployment'
/* This task needs to be updated to satisfy filtering
task refreshContent (dependsOn: war) << {
File dest = explodeDest()
copy {
//from 'build/tmp/filtered-content'
//from 'build/tmp/renamed'
from 'src/main/webapp'
into dest
exclude '**X.*X**'
}
}
refreshContent.description = 'Refresh webapp content on app server'
*/