forked from ndw/xmlcalabash1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
511 lines (448 loc) · 16.1 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
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath fileTree(dir: 'lib').include("*.jar")
classpath group: 'org.daisy.libs', name: 'saxon-he', version: saxonVersion
}
}
plugins {
id "java"
id "osgi"
id "maven"
id "maven-publish"
id "signing"
id "com.bmuschko.izpack" version "2.0"
id "de.undercouch.download" version "2.0.0"
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.undercouch.gradle.tasks.download.Download
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
repositories {
// mavenLocal()
mavenCentral()
maven { url "http://maven.restlet.org" }
maven { url "https://developer.marklogic.com/maven2" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
configurations {
reportruntime {
extendsFrom runtime
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.name == 'saxon' && details.requested.version == '8.7') {
details.useTarget "org.daisy.libs:saxon-he:" + saxonVersion
}
}
}
dependencies {
izpack 'org.codehaus.izpack:izpack-standalone-compiler:4.3.4'
compile fileTree(dir: 'lib').include("*.jar")
compile (
[group: 'com.nwalsh', name: 'nwalsh-annotations', version: '1.0.0'],
[group: 'org.daisy.libs', name: 'jing', version: '20151127.0.0', transitive: false],
[group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'],
[group: 'junit', name: 'junit', version: '4.12'],
[group: 'net.java.dev.msv', name: 'msv-core', version: '2013.6.1'],
[group: 'org.daisy.libs', name: 'saxon-he', version: saxonVersion],
[group: 'com.ibm.icu', name: 'icu4j', version: '49.1'],
[group: 'nu.validator.htmlparser', name: 'htmlparser', version: '1.4'],
[group: 'org.apache.ant', name: 'ant', version: '1.9.4'],
[group: 'org.apache.httpcomponents', name: 'httpcore-osgi', version: '4.4.5'],
[group: 'org.atteo.classindex', name: 'classindex', version: '3.3'],
[group: 'org.ccil.cowan.tagsoup', name: 'tagsoup', version: '1.2.1'],
[group: 'org.restlet.jee', name: 'org.restlet', version: '2.2.2'],
[group: 'org.restlet.jee', name: 'org.restlet.ext.fileupload', version: '2.2.2'],
[group: 'org.restlet.jee', name: 'org.restlet.ext.slf4j', version: '2.2.2'],
[group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.3'],
[group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.10', transitive: false], // leave it up to the user which main log
[group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.7.10', transitive: false], // framework and which bindings to use
[group: 'org.slf4j', name: 'slf4j-api', version: '1.7.10'],
[group: 'org.osgi', name: 'org.osgi.core', version: '4.3.1', transitive: false], // provided by osgi framework
// OSGi bundle that provides isorelax (which is a dependency of net.java.dev.msv, needed for validate-rng)
[group: 'com.sun.xml.bind', name: 'jaxb-extra-osgi', version: '2.2.11'],
)
compile('org.apache.httpcomponents:httpclient-osgi:4.5.2') {
exclude group: 'commons-logging', module: 'commons-logging' // replaced with jcl-over-slf4j
}
compile('org.xmlresolver:xmlresolver:0.13.1') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient-osgi' // older version than defined above
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
}
reportruntime (
fileTree(dir: 'lib').include("*.jar"),
fileTree(dir: 'lib/' + saxonVersion).include('*.jar'),
files("lib/deltaxml.lic"),
[group: 'com.xmlcalabash', name: 'xmlcalabash1-asciidoctor', version: '1.1.0'],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-deltaxml', version: '1.1.2'],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-ditaa', version: '1.1.2'],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-mathml-to-svg', version: '1.1.2'],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-metadata-extractor', version: '1.1.2'],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-plantuml', version: '1.1.2'],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-print', version: '1.1.2'],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-rdf', version: '1.1.2'],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-sendmail', version: '1.1.2'],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-xcc', version: '1.1.2'],
[group: 'com.xmlcalabash', name: 'xmlcalabash1-xmlunit', version: '1.1.2']
)
}
sourceSets {
main {
java {
srcDir 'src/main/java'
exclude 'com/xmlcalabash/testdrivers/**'
}
resources {
srcDirs 'src/main/resources'
}
}
}
// Variables
project.ext.saxonRange = '[' + saxonVersion.substring(0,5) + ',' + saxonVersion.substring(0,4) + (saxonVersion.substring(4,5).toInteger() + 1) + ')'
project.ext.saxonBranch = saxonVersion.substring(0,3).replaceAll("\\.", "")
project.ext.releaseVersion = version
project.ext.distVersion = version + "-" + saxonBranch + snapshot
project.ext.osgiVersion = version.replaceAll("-.*", "")
project.ext.refDocZip = 'xmlcalabash-ref-' + docsVersion + '.zip'
version = project.ext.distVersion // - gets turned into . in some contexts
group = "org.daisy.libs"
def Properties versionProps = new Properties()
def versionPropsFile = file("src/main/resources/etc/version.properties")
versionProps['version'] = releaseVersion
versionProps.store(versionPropsFile.newWriter(),null)
task copyLib(type: Copy) {
FileCollection runtime = configurations.runtime
FileCollection localLib = fileTree(dir: 'lib').include("*.jar")
FileCollection lib = runtime - localLib
lib = lib.filter { File f -> !(f.name ==~ /.*osgi.*/) }
String path = ""
lib.each {
File file -> path += " lib/" + file.name
}
project.ext.runtimeClasspath = path.trim()
from lib
into { "build/dist/lib" }
}
jar {
baseName "com.xmlcalabash"
manifest {
version = project.ext.osgiVersion
instruction 'Built-By', builtBy
instruction 'Implementation-Vendor', 'Norman Walsh'
instruction 'Implementation-Title', 'XML Calabash'
instruction 'Implementation-Version', project.ext.distVersion
instruction 'Main-Class', 'com.xmlcalabash.drivers.Main'
instruction 'Bundle-RequiredExecutionEnvironment', 'J2SE-1.6'
instruction 'Export-Package', 'com.xmlcalabash.*;version=' + project.ext.osgiVersion + ',\
com.nwalsh.annotations,\
org.xmlresolver,\
etc'
instruction 'Import-Package', 'net.sf.saxon.*;version="' + project.ext.saxonRange + '",\
javax.crypto.*,\
javax.xml.*,\
org.apache.commons.httpclient.*,\
org.xml.sax.*,\
!org.osgi.*,\
!com.xmlcalabash.*,\
!com.nwalsh.annotations,\
!org.xmlresolver,\
*;resolution:=optional'
instruction 'DynamicImport-Package', '*'
instruction 'Class-Path', project.ext.runtimeClasspath + " lib"
instruction 'Bundle-ClassPath', '.,lib/nwalsh-annotations.jar,lib/xmlresolver.jar'
}
from('build/dist') {
include 'lib/nwalsh-annotations-*.jar'
include 'lib/xmlresolver-*.jar'
rename '(.*)-.*.jar','$1.jar'
}
}
izpack {
baseDir = file("build/dist")
installFile = file("build/install.xml")
outputFile = file("build/distributions/xmlcalabash-" + project.ext.distVersion + ".jar")
}
compileJava {
options.deprecation = true
}
task copyNotices(type: Copy) {
from 'resources/notices'
into 'build/dist/docs/notices'
}
jar.dependsOn copyNotices
task downloadReferenceDocs(type: Download) {
src docsBaseURI + project.ext.refDocZip
dest new File(buildDir, refDocZip)
}
downloadReferenceDocs.onlyIf { !file("$buildDir/$refDocZip").exists() }
task copyReferenceDocs(dependsOn: downloadReferenceDocs, type: Copy) {
from zipTree(downloadReferenceDocs.dest)
into { "build" }
doLast {
copy {
from "build/xmlcalabash-ref-" + docsVersion
into "build/dist/docs/reference"
}
}
}
task copySchemas(type: Copy) {
from 'resources/schemas'
into 'build/dist/schemas'
}
task copyREADME(type: Copy) {
from 'resources/README'
into 'build/dist'
}
task copyXpl(type: Copy) {
FileCollection xpl = fileTree(dir: 'xpl').exclude("submit-test-report.xpl")
from xpl
into 'build/dist/xpl'
}
// Just depend on something that will create build/dist
task copyVERSION(dependsOn: copyXpl) {
doLast {
def outputFile = new File("$buildDir/dist", "VERSION")
outputFile.withPrintWriter { writer ->
writer.println project.ext.distVersion
}
}
}
task copyToDist(dependsOn: [copyLib,copyNotices,copyReferenceDocs,copySchemas,
copyXpl,copyREADME,copyVERSION]) {
}
jar.dependsOn copyToDist
task javadocJar(type: Jar, dependsOn: javadoc) {
baseName = "com.xmlcalabash"
classifier = 'javadoc'
from tasks.javadoc.destinationDir
}
task sourcesJar(type: Jar) {
baseName = "com.xmlcalabash"
from sourceSets.main.allSource
classifier = 'sources'
}
task copyJar(dependsOn: jar, type: Copy) {
from "build/libs/xmlcalabash-" + distVersion + ".jar"
into "build/dist"
}
task copyJavaDoc(dependsOn: javadoc, type: Copy) {
from "build/docs"
into "build/dist/docs"
}
task makeDist(dependsOn: [ build, copyJar, copyLib ]) {
doLast {
println "Created distribution in build/dist"
}
}
task zipDist(dependsOn: makeDist, type: Zip) {
from('build/dist')
exclude(["calabash", "calabash.bat"])
into 'xmlcalabash-' + version
archiveName 'xmlcalabash-' + version + ".zip"
}
task izPackDist(dependsOn: izPackCreateInstaller) {
// nop
}
task dist(dependsOn: [zipDist, izPackDist]) {
// nop
}
task testSuiteMessages {
doLast {
println "Running test-suite...this may take a few minutes..."
println " Sending report to " + testsReport + "; errors to " + testsErrors
}
}
task testSuite(dependsOn: [makeDist, testSuiteMessages], type: JavaExec) {
classpath = configurations.reportruntime + configurations.runtime + sourceSets.main.output
main = 'com.xmlcalabash.drivers.RunTestReport'
maxHeapSize = "1024m"
args('-D', '-a',
testsRoot + '/tests/required/test-suite.xml',
testsRoot + '/tests/serialization/test-suite.xml',
testsRoot + '/tests/optional/test-suite.xml',
testsRoot + '/tests/extension/test-suite.xml',
'http://xmlcalabash.com/tests/test-suite.xml')
// 'http://localhost:8130/tests/test-suite.xml')
//standardOutput = new FileOutputStream(new File(testsReport))
//errorOutput = new FileOutputStream(new File(testsErrors))
}
task testSuiteClassPath {
doLast {
configurations.reportruntime.each { println it }
configurations.runtime.each { println it }
sourceSets.main.output.each { println it }
}
}
task htmlReport(dependsOn: testSuite, type: JavaExec) {
classpath = configurations.reportruntime + configurations.runtime + sourceSets.main.output
main = 'net.sf.saxon.Transform'
args('-s:' + testsReport,
'-xsl:resources/format-report.xsl',
'-o:' + testsFormat)
}
task aDocReport(dependsOn: testSuite, type: JavaExec) {
classpath = configurations.reportruntime + configurations.runtime + sourceSets.main.output
main = 'net.sf.saxon.Transform'
args('-s:' + testsReport,
'-xsl:resources/asciidoc-report.xsl',
'-o:' + testsADoc)
}
task aDocErrReport(dependsOn: testSuite, type: JavaExec) {
classpath = configurations.reportruntime + configurations.runtime + sourceSets.main.output
main = 'net.sf.saxon.Transform'
args('-s:' + testsReport,
'-xsl:resources/asciidoc-report.xsl',
'-o:' + testsFailADoc,
'show-pass=0',
'show-partial=0')
}
task report(dependsOn: [htmlReport,aDocReport,aDocErrReport]) {
// nop
}
// Just depend on something that will create build/dist
task makeIZPackShell(dependsOn: copyVERSION) {
doLast {
def shell = new File("$buildDir/dist", "calabash")
shell.withPrintWriter { writer ->
writer.println '#!/bin/bash'
writer.println 'java -Xmx1024m -cp %INSTALL_PATH/xmlcalabash-' + version + '.jar com.xmlcalabash.drivers.Main "$@"'
}
shell.setExecutable(true)
def batch = new File("$buildDir/dist", "calabash.bat")
batch.withPrintWriter { writer ->
writer.println 'java -Xmx1024m -cp %INSTALL_PATH/xmlcalabash-' + version + '.jar com.xmlcalabash.drivers.Main %*'
}
}
}
task setupIZPack(dependsOn: [makeDist, makeIZPackShell], type: JavaExec) {
classpath = configurations.reportruntime + configurations.runtime + sourceSets.main.output
main = 'net.sf.saxon.Transform'
args('-s:src/main/izpack/install.xml',
'-xsl:resources/izpack-filter.xsl',
'-o:build/install.xml',
'version.label='+project.ext.distVersion)
}
izPackCreateInstaller.dependsOn setupIZPack
artifacts {
archives javadocJar
archives sourcesJar
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId 'org.daisy.libs'
artifactId 'com.xmlcalabash'
version version
from components.java
}
}
repositories {
maven {
url 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath
}
}
}
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask(":uploadArchives") }
useGpgCmd() // requires gpg2 to be installed
sign configurations.archives
}
def mavenPom = {
name 'XML Calabash'
packaging 'jar'
description 'An XProc 1.0 processor'
url 'https://github.com/ndw/xmlcalabash1'
scm {
url 'scm:[email protected]:ndw/xmlcalabash1.git'
connection 'scm:[email protected]:ndw/xmlcalabash1.git'
developerConnection 'scm:[email protected]:ndw/xmlcalabash1.git'
}
licenses {
license {
name 'Common Development and Distribution License (CDDL) version 1.0'
url 'https://opensource.org/licenses/CDDL-1.0'
distribution 'repo'
}
license {
name 'GNU General Public License version 2'
url 'https://www.gnu.org/licenses/gpl-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'ndw'
name 'Norman Walsh'
}
}
repositories {
repository {
id 'restlet'
url 'https://maven.restlet.org'
}
}
}
install {
repositories {
mavenInstaller {
pom.project(mavenPom)
}
}
}
ext.replaceEnv = { string ->
Matcher m = Pattern.compile("^\\\$\\{env\\.(?<var>.+)\\}\$").matcher(string);
if (m.matches()) {
println 'Substituting environment variable ' + m.group("var") + ' in "' + string + '"'
return System.getenv(m.group("var"))
} else {
return string
}
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment ->
signing.signPom(deployment)
}
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: "ignored")
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: "ignored")
}
pom.project(mavenPom)
}
// settings.xml is not automatically consulted for authentication settings
// this workaround is taken from https://issues.gradle.org/browse/GRADLE-1039
doFirst {
def settings = new File(System.getProperty('user.home') + '/.m2/settings.xml')
if (settings.exists()) {
def xml = new XmlSlurper().parse(settings)
def serverID = isReleaseVersion ? 'sonatype-nexus-staging' : 'sonatype-nexus-snapshots'
def server = xml.servers.children().find({ it.id.text() == serverID })
if (server) {
def mavenUsername = replaceEnv(server.username.text())
def mavenPassword = replaceEnv(server.password.text())
println 'Found server definition "' + serverID + '", username: ' + mavenUsername
if (isReleaseVersion) {
repositories.mavenDeployer.repository.authentication.userName = mavenUsername
repositories.mavenDeployer.repository.authentication.password = mavenPassword
} else {
repositories.mavenDeployer.snapshotRepository.authentication.userName = mavenUsername
repositories.mavenDeployer.snapshotRepository.authentication.password = mavenPassword
}
} else {
println 'No server definition "' + serverID + '" was found in ' + settings
}
} else {
println 'Maven settings file was not found: ' + settings
}
}
}
}