Project

Profile

Help

How to connect?
Download (42.7 KB) Statistics
| Branch: | Revision:

he / build.gradle @ d61f99bb

1
plugins {
2
  id "java"
3
  id "maven-publish"
4
  id "signing"
5
//  id "com.cdsap.talaiot" version "1.3.5"
6
}
7

    
8
import org.gradle.internal.os.OperatingSystem;
9

    
10
apply plugin: 'java'
11

    
12
repositories {
13
  mavenLocal()
14
  mavenCentral()
15
  maven { url = "https://maven.apache.org" }
16
  maven { url "https://dev.saxonica.com/maven" }
17
}
18

    
19
configurations.all {
20
  resolutionStrategy {
21
    force 'xml-apis:xml-apis:1.4.01'
22
  }
23
}
24

    
25
configurations {
26
  preprocessor.extendsFrom(runtimeOnly)
27
  jarjarAsm.extendsFrom(implementation)
28
  testDrivers.extendsFrom(testImplementation)
29
  ikvm.extendsFrom(implementation)
30
  compileDotNet.extendsFrom(implementation)
31
  asmDotNet.extendsFrom(implementation)
32
  documentation.extendsFrom(implementation)
33
  jeldoclet.extendsFrom(implementation)
34
}
35

    
36
// Set saxonLicenseDir in gradle.properties, or from the
37
// command line if you have a license in some other place.
38
if (!hasProperty("saxonLicenseDir")) {
39
  if (System.getenv("SAXON_LICENSE_DIR") != null) {
40
    ext.saxonLicenseDir=System.getenv('SAXON_LICENSE_DIR')
41
  } else {
42
    ext.saxonLicenseDir=System.getenv('HOME') + "/java"
43
  }
44
}
45

    
46
// Set the locations of the W3C test suites
47
if (!hasProperty("w3cQT3TestSuiteDir")) {
48
  ext.w3cQT3TestSuiteDir = System.getenv("W3C_QT3_TEST_SUITE_DIR")
49
}
50
if (!hasProperty("w3cXslt30TestSuiteDir")) {
51
  ext.w3cXslt30TestSuiteDir = System.getenv("W3C_XSLT30_TEST_SUITE_DIR")
52
}
53
if (!hasProperty("w3cXsdTestSuiteDir")) {
54
  ext.w3cXsdTestSuiteDir = System.getenv("W3C_XSD_TEST_SUITE_DIR")
55
}
56

    
57
dependencies {
58
  preprocessor (
59
    [group: 'com.igormaznitsa', name: 'jcp', version: '7.0.4'],
60
    [group: 'com.tonicsystems', name: 'jarjar', version: '0.6' ],
61
    [group: 'net.sf.saxon', name: 'Saxon-HE', version: '10.3' ],
62
    files(saxonLicenseDir)
63
  )
64
  implementation (
65
    [group: 'org.apache.ws.commons.axiom', name: 'axiom', version: '1.2.15'],
66
    [group: 'org.apache.ws.commons.axiom', name: 'axiom-dom', version: '1.2.15'],
67
    [group: 'xom', name: 'xom', version: '1.3.5'],
68
    [group: 'org.jdom', name: 'jdom', version: '1.1.3'],
69
    [group: 'org.jdom', name: 'jdom2', version: '2.0.6'],
70
    [group: 'org.lucee', name: 'dom4j', version: '1.6.1'],
71
    [group: 'xml-resolver', name: 'xml-resolver', version: '1.2' ],
72
    [group: 'com.ibm.icu', name: 'icu4j', version: icu4jVersion ],
73
    [group: 'jline', name: 'jline', version: '2.14.6' ],
74
    [group: 'org.jetbrains', name: 'annotations', version: '20.1.0' ],
75
    // PE and EE
76
    [group: 'javax.mail', name: 'javax.mail-api', version: mailVersion ],
77
    [group: 'com.sun.mail', name: 'javax.mail', version: mailVersion ],
78
    [group: 'org.ccil.cowan.tagsoup', name: 'tagsoup', version: tagsoupVersion],
79
    fileTree(dir: "extra/MyDotNet/classpath"),
80
    fileTree(dir: "extra/MyDotNet/stubs"),
81
    fileTree(dir: "lib/asm-${asmVersion}"),
82
    files("lib/Tidy.jar"),
83
  )
84
  jarjarAsm (
85
    fileTree(dir: "${buildDir}/lib/asm")
86
  )
87
  ikvm (
88
    fileTree(dir: "${ikvmDir}/stubs")
89
  )
90
  compileDotNet (
91
    fileTree(dir: "${ikvmDir}/stubs"),
92
    fileTree(dir: "${ikvmDir}/classpath")
93
  )
94
  asmDotNet (
95
    fileTree(dir: "${ikvmDir}/stubs"),
96
    fileTree(dir: "${ikvmDir}/classpath"),
97
    fileTree(dir: "lib/asm-${asmVersion}")
98
  )
99
  testImplementation (
100
    [group: 'junit', name: 'junit', version: '4.12'],
101
    [group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.4.2'],
102
    [group: 'org.apache.ant', name: 'ant', version: '1.10.9' ],
103
    files("${buildDir}/classes/${saxonEdition}j"),
104
    files("src/main/resources"),
105
    files("lib/Tidy.jar"),
106
    files(saxonLicenseDir),
107
    fileTree("${buildDir}/lib/asm")
108
  )
109
  testRuntimeOnly (
110
    [group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.4.2'],
111
    [group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.4.2'],
112
    [group: 'org.apache.ant', name: 'ant', version: '1.10.9' ],
113
    files("${buildDir}/classes/${saxonEdition}j")
114
  )
115
  documentation (
116
    [group: "com.saxonica", name: "Saxon-EE", version: "10.3"],
117
    files(saxonLicenseDir)
118
  )
119
  jeldoclet (
120
    files("lib/jeldoc.jar"),
121
    // I don't really understand why this has to be done explicitly...
122
    files("${System.getProperty('java.home')}/../lib/tools.jar")
123
  )
124
}
125

    
126
javadoc {
127
  classpath = configurations.implementation
128
}
129

    
130
test {
131
  useJUnitPlatform {
132
    excludeTags 'bytecode'
133
  }
134
}
135

    
136
/*
137
talaiot {
138
  metrics {
139
    performanceMetrics = false
140
  }
141
  publishers {
142
    taskDependencyGraphPublisher {
143
      gexf = false
144
      dot = true
145
      html = false
146
    }
147
  }
148
}
149
*/
150

    
151
ext {
152
  systemOs = OperatingSystem.current()
153
  icu4jJar = null
154
  tagsoupJar = null
155
  mailJar = null
156
  resolverJar = null
157
  version_h = saxonVersion.replace(".", "-")
158
  pathSeparator = System.getProperty("file.separator")
159
  DSTAMP=new Date().format("yyyyMMdd")
160
}
161

    
162
public class DeleteFilesRecursively {
163
  static void delete(File file){
164
    for (File fspec : file.listFiles()) {
165
      if (fspec.isDirectory()) {
166
        delete(fspec);
167
      } else {
168
        fspec.delete();
169
      }
170
    }
171
    file.delete();
172
  }
173
}
174

    
175
// ============================================================
176
// Have you switched branches?
177
def branch = new ByteArrayOutputStream()
178
def result = exec {
179
  commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
180
  standardOutput = branch;
181
}
182
def currentBranch = branch.toString().trim()
183

    
184
def builtBranch = "none";
185
try {
186
  def xbranch = new BufferedReader(new FileReader(new File("build/built-branch")))
187
  builtBranch = "${xbranch.readLine().trim()}"
188
} catch (FileNotFoundException foe) {
189
  // nop
190
}
191

    
192
if (currentBranch != builtBranch
193
    && (file("${buildDir}/src").exists()
194
        || file("${buildDir}/preprocess").exists()
195
        || file("${buildDir}/filtered").exists()
196
        || file("${buildDir}/classes").exists())) {
197
  println("You appear to have switched to the '${currentBranch}' branch.")
198
  println("Deleting stale build sources...")
199
  DeleteFilesRecursively.delete(new File("${buildDir}/src"))
200
  DeleteFilesRecursively.delete(new File("${buildDir}/preprocess"))
201
  DeleteFilesRecursively.delete(new File("${buildDir}/filtered"))
202
  DeleteFilesRecursively.delete(new File("${buildDir}/classes"))
203
}
204

    
205
// ============================================================
206
// Private options required for signing jars. (Can't be
207
// checked into the repository because they're sekrit.)
208
def eToken = "THIS-IS-NOT-THE-ETOKEN"
209
["${System.getenv("SAXON_SIGN_ETOKEN")}",
210
 "${projectDir}/../../private/eToken/macos/eToken.cfg",
211
 "z:/some/other/token/path"].each { path ->
212
  if (eToken == "THIS-IS-NOT-THE-ETOKEN"
213
      && new File(path).exists()) {
214
    eToken = path
215
  }
216
}
217

    
218
def signkeyNewAlias = "THIS-IS-NOT-THE-ALIAS"
219
if (System.getenv("SAXON_SIGN_ALIAS") != null) {
220
  signkeyNewAlias = System.getenv("SAXON_SIGN_ALIAS")
221
}
222

    
223
def signkeyPassword = "THIS-IS-NOT-THE-PASSWORD"
224
if (System.getenv("SAXON_SIGN_PASSWORD") != null) {
225
  signkeyPassword = System.getenv("SAXON_SIGN_PASSWORD")
226
}
227

    
228
def canSignJars = (!eToken.startsWith("THIS-IS-NOT")
229
                   && !signkeyNewAlias.startsWith("THIS-IS-NOT")
230
                   && !signkeyPassword.startsWith("THIS-IS-NOT"))
231

    
232
def signjarArgs = null
233
if (OperatingSystem.current().isWindows()) {
234
  signjarArgs = ["jarsigner",
235
                 "-keystore", "NONE",
236
                 "-storetype", "PKCS11",
237
                 "-tsa", "http://rfc3161timestamp.globalsign.com/advanced",
238
                 "-providerClass", "sun.security.pkcs11.SunPKCS11",
239
                 "-providerArg", eToken]
240
} else {
241
  signjarArgs = ["jarsigner",
242
                 "-tsa", "http://rfc3161timestamp.globalsign.com/advanced",
243
                 "-storetype", "PKCS11",
244
                 "-providerClass", "sun.security.pkcs11.SunPKCS11",
245
                 "-providerArg", eToken]
246
}
247

    
248
// ============================================================
249
// Find jar files that need to be part of the build or release
250
//
251
def filesep = System.getProperty("file.separator")
252
icu4jJar = "${filesep}icu4j-${icu4jVersion}.jar"
253
tagsoupJar = "${filesep}tagsoup-${tagsoupVersion}.jar"
254
mailJar = "${filesep}javax.mail-${mailVersion}.jar"
255
resolverJar = "${filesep}xml-resolver-1.2.jar"
256
configurations.compileClasspath.each { cp ->
257
  if (cp.toString().endsWith(icu4jJar)) {
258
    icu4jJar = cp.toString()
259
  }
260
  if (cp.toString().endsWith(tagsoupJar)) {
261
    tagsoupJar = cp.toString()
262
  }
263
  if (cp.toString().endsWith(mailJar)) {
264
    mailJar = cp.toString()
265
  }
266
  if (cp.toString().endsWith(resolverJar)) {
267
    resolverJar = cp.toString()
268
  }
269
}
270

    
271
apply from: "build-n.gradle"
272
apply from: "build-c.gradle"
273
apply from: "build-doc.gradle"
274

    
275
def pathExists(pathname) {
276
  // Returns true iff pathame is an existing file or directory
277
  try {
278
    // This may throw an error for a Windows pathname, c:/path/to/thing
279
    if (file(pathname).exists()) {
280
      return true;
281
    }
282
  } catch (GradleException e) {
283
    // I don't care
284
  }
285

    
286
  if (OperatingSystem.current().isWindows()) {
287
    try {
288
      // If we're on Windows, try to make c:/path/to/thing work
289
      if (file("file:///${pathname}").exists()) {
290
        return true;
291
      }
292
    } catch (GradleException e) {
293
      // I don't care
294
    }
295
  }
296

    
297
  return false
298
}
299

    
300
// ============================================================
301
// One of the features of Gradle is that you can construct tasks
302
// dynamically during the "configure" phase. This is a feature because
303
// it avoids a lot of tedious repetition of nearly identical tasks. It
304
// has the unfortunate consequence that understanding the tasks
305
// involved becomes harder. I've tried to use this feature sparingly.
306

    
307
["h", "p", "e"].each { initial ->
308
  def release = initial + "e"
309
  def Release = initial.toUpperCase() + "e"
310
  def RELEASE = release.toUpperCase()
311

    
312
  if (release != "he") {
313
    Task libs = task "${release}j_libs"(
314
      description: "Dependency to make sure library files are copie for ${RELEASE}"
315
    ) {
316
      // Just a container to hang dependencies on
317
    }
318

    
319
    Task icu4j = task "${release}j_icu4j"(
320
      type: Copy,
321
      description: "Copy the ICU4J jar into the ${RELEASE} release directory"
322
    ) {
323
      from "${icu4jJar}"
324
      into "${buildDir}/releases/${release}j"
325
    }
326
    libs.dependsOn icu4j
327
  }
328

    
329
  task "${release}j_notices"(
330
    type: Copy,
331
    description: "Copy the notices into the ${RELEASE} release directory"
332
  ) {
333
    into "${buildDir}/releases/${release}j"
334
    from ("src/docs") {
335
      exclude "saxon9"
336
      exclude "tools"
337
      exclude "saxonc-doc"
338
      exclude "welcome"
339
      exclude "notices/APACHE-ANT.txt"
340
      exclude "notices/APACHE-RESOLVER.txt"
341
      exclude "notices/APACHE-TAGSOUP.txt"
342
      exclude "notices/APACHE-XERCES.txt"
343
      exclude "notices/ASM.txt"
344
      exclude "notices/FRIJTERS.txt"
345
      exclude "notices/GPL+CLASSPATH.txt"
346
      exclude "notices/ICU-J.txt"
347
      exclude "notices/LEGAL.txt"
348
    }
349
  }
350

    
351
  task "${release}j_copyTestDrivers"(
352
    dependsOn: ["${release}j_copyTestDriverSources",
353
                "${release}j_copyTestDriverResources"],
354
    description: "Copy test driver sources and resources for ${RELEASE}"
355
  ) {
356
    // Just a container to hang dependencies on
357
  }
358
}
359

    
360
// ============================================================
361
// In an ideal world, I'd make the build process more standalone
362
// by automatically cloning the repositories if they weren't
363
// available. But the QT3 test suite in particular is huge and
364
// takes a long time to clone. So for now, just force users to
365
// tell us where they've cloned them.
366

    
367
task cloneQT3TestSuite() {
368
  doLast {
369
    if (w3cQT3TestSuiteDir == null) {
370
      throw new GradleException("The location of the QT3 test suite is unknown.")
371
    }
372
  }
373
}
374

    
375
task cloneXslt30TestSuite() {
376
  doLast {
377
    if (w3cXslt30TestSuiteDir == null) {
378
      throw new GradleException("The location of the XSLT 3.0 test suite is unknown.")
379
    }
380
  }
381
}
382

    
383
task cloneXsdTestSuite() {
384
  doLast {
385
    if (w3cXsdTestSuiteDir == null) {
386
      throw new GradleException("The location of the XSD test suite is unknown.")
387
    }
388
  }
389
}
390

    
391
// ============================================================
392

    
393
task compileTestDrivers() {
394
  // Just a container to hang dependencies on
395
}
396

    
397
task runQT3TestDriver() {
398
  // Just a container to hang dependencies on
399
}
400

    
401
task runXslt30TestSuiteDriver() {
402
  // Just a container to hang dependencies on
403
}
404

    
405
["h", "p", "e"].each { initial ->
406
  def release = initial + "e"
407
  def RELEASE = release.toUpperCase()
408
  def jpackage = "com.saxonica.testdriver"
409
  if (release == "he") {
410
    jpackage = "net.sf.saxon.testdriver"
411
  }
412

    
413
  task "${release}j_compileTestDrivers"(
414
    type: JavaCompile,
415
    dependsOn: ["${release}j_copyTestDrivers", "${release}jCompile"],
416
    description: "Compile the test classes for ${RELEASE}"
417
  ) {
418
    classpath = configurations.testDrivers + files("${buildDir}/classes/${release}j")
419
    source = "${buildDir}/src/testdrivers/${release}j"
420
    destinationDirectory = new File("${buildDir}/testdriver_classes/${release}j")
421
  }
422

    
423
  fileTree(dir: "src/test/exceptions").each { fn ->
424
    def pos = fn.toString().lastIndexOf(pathSeparator)
425
    def base = fn.toString().substring(pos+1)
426
    base = base.substring(0, base.length() - 4)
427
    task "${release}j_setup_${base}_TestResults"(
428
      type: Copy,
429
      description: "Sets up the test results directory the ${base} tests for ${RELEASE}"
430
    ) {
431
      into "${buildDir}/test-results/${release}j/${base}"
432
      from "src/test/exceptions/${base}.xml"
433
      rename { "exceptions.xml" }
434
    }
435
  }
436

    
437
  task "${release}j_runQT3TestDriver"(
438
    type: JavaExec,
439
    dependsOn: ["${release}j_compileTestDrivers", "${release}j_setup_qt3_TestResults",
440
                "cloneQT3TestSuite"],
441
    description: "Run the QT3 test suite driver for ${RELEASE}"
442
  ) {
443
    classpath = configurations.testDrivers \
444
                + files("${buildDir}/classes/${release}j") \
445
                + files("${buildDir}/testdriver_classes/${release}j")
446
    main = "${jpackage}.QT3TestDriver${RELEASE}"
447
    //args "-?"
448
    args "${w3cQT3TestSuiteDir}",
449
      "catalog.xml",
450
      "-o:${buildDir}/test-results/${release}j/qt3",
451
      "-lang:XQ31",
452
      "-qt30:on",
453
      "-bytecode:off"
454
  }
455

    
456
  task "${release}j_runXslt30TestSuiteDriver"(
457
    type: JavaExec,
458
    dependsOn: ["${release}j_compileTestDrivers", "${release}j_setup_xslt30_TestResults",
459
                "cloneXslt30TestSuite"],
460
    description: "Run the XSLT 3.0 test suite driver for ${RELEASE}"
461
  ) {
462
    classpath = configurations.testDrivers \
463
                + files("${buildDir}/classes/${release}j") \
464
                + files("${buildDir}/testdriver_classes/${release}j")
465
    main = "${jpackage}.Xslt30TestSuiteDriver${RELEASE}"
466
    //args "-?"
467
    args "/Volumes/Saxonica/src/w3c/xslt30-test",
468
      "catalog.xml",
469
      "-o:${buildDir}/test-results/${release}j/xslt30",
470
      "-lang:XT30",
471
      "-qt30:on",
472
      "-bytecode:off"
473
  }
474
}
475

    
476
// ============================================================
477

    
478
task hejJarTests(
479
  type: Jar,
480
  dependsOn: ["hejCompile", "hej_compileTestDrivers"],
481
  description: "Create the tests jar file for HE"
482
) {
483
  archiveBaseName = "saxon-he-test-${saxonVersion}"
484
  manifest {
485
    attributes "Project-Name": "Saxon-HE-TestDriver"
486
    attributes "Main-Class": "com.saxonica.testdriver.gui.TestDriverGui"
487
  }
488
  from ("${buildDir}/testdriver_classes/hej") {
489
    include "net/sf/saxon/testdriver/**"
490
  }
491
}
492

    
493
task pejJarTests(
494
  type: Jar,
495
  dependsOn: ["pejCompile", "pej_compileTestDrivers"],
496
  description: "Create the tests jar file for PE"
497
) {
498
  archiveBaseName = "saxon-pe-test-${saxonVersion}"
499
  manifest {
500
    attributes "Project-Name": "Saxon-PE-TestDriver"
501
    attributes "Main-Class": "com.saxonica.testdriver.gui.TestDriverGui"
502
  }
503
  from ("${buildDir}/testdriver_classes/pej") {
504
    include "net/sf/saxon/testdriver/**"
505
    include "com/saxonica/testdriver/**"
506
    exclude "com/saxonica/testdriver/ee/**"
507
  }
508
}
509

    
510
task eejJarTests(
511
  type: Jar,
512
  dependsOn: ["eejCompile", "eej_compileTestDrivers"],
513
  description: "Create the tests jar file for EE"
514
) {
515
  archiveBaseName = "saxon-ee-test-${saxonVersion}"
516
  manifest {
517
    attributes "Project-Name": "Saxon-EE-TestDriver"
518
    attributes "Main-Class": "com.saxonica.testdriver.gui.TestDriverGui"
519
  }
520
  from ("${buildDir}/testdriver_classes/eej") {
521
    include "net/sf/saxon/testdriver/**"
522
    include "com/saxonica/testdriver/**"
523
    include "com/saxonica/js/**"
524
  }
525
}
526

    
527
// ============================================================
528

    
529
task hej_sampleConfig(
530
  type: JavaExec,
531
  description: "Construct the configuration file XSD"
532
) {
533
  inputs.files fileTree(dir: "${projectDir}/tools/featureKeys")
534
  inputs.files "${projectDir}/src/samples/config/config-raw.xsd"
535
  outputs.file "${projectDir}/src/samples/config/config.xsd"
536
  classpath = configurations.preprocessor
537
  main = "net.sf.saxon.Transform"
538
  args "${projectDir}/tools/featureKeys/FeatureKeys.xml",
539
    "-xsl:${projectDir}/tools/featureKeys/FeatureKeysToSchema.xsl",
540
    "-o:${projectDir}/src/samples/config/config.xsd",
541
    "FeatureKeys=FeatureKeys.xml",
542
    "AdditionalFeatures=AdditionalFeatures.xml",
543
    "ConfigSchema=${projectDir}/src/samples/config/config-raw.xsd"
544
}
545

    
546
// There's no real dependency here, but I'm not sure how the
547
// samples directory should be integrated into the build.
548
task hej_featureKeys(
549
  type: JavaExec,
550
  dependsOn: ["hej_sampleConfig"],
551
  description: "Construct the feature keys for HE"
552
) {
553
  inputs.files fileTree(dir: "${projectDir}/tools/featureKeys")
554
  outputs.file "${projectDir}/src/main/java/net/sf/saxon/lib/Feature.java"
555
  outputs.file "${projectDir}/src/main/java/net/sf/saxon/lib/FeatureCode.java"
556
  outputs.file "${projectDir}/src/main/java/net/sf/saxon/lib/FeatureKeys.java"
557
  classpath = configurations.preprocessor
558
  main = "net.sf.saxon.Transform"
559
  args "${projectDir}/tools/featureKeys/FeatureKeys.xml",
560
    "-xsl:${projectDir}/tools/featureKeys/FeatureKeysToJava.xsl",
561
    "-o:${projectDir}/src/main/java/net/sf/saxon/lib/establish-an-output-base-uri"
562
}
563

    
564
// Make sure we create feature keys before compiling Java
565
compileJava.dependsOn hej_featureKeys
566

    
567
task hej_setupPreprocess(
568
  type: Copy,
569
  dependsOn: ["hej_featureKeys", "record_branch"],
570
  description: "Copy HE sources for preprocessing HE"
571
) {
572
  from "${projectDir}/src/main/java"
573
  into "${buildDir}/filtered/hej"
574
  include "net/sf/saxon/**/*.java"
575
  include "net/sf/saxon/**/package.html"
576
  //include "net/sf/saxon/data/**"
577
  exclude "javax/xml/xquery/*.java"
578
  exclude "**/dotnet/**"
579
  exclude "net/sf/saxon/testdriver/**"
580
  exclude "net/sf/saxon/option/sql/**"
581
  exclude "net/sf/saxon/option/cpp/**"
582
  exclude "net/sf/saxon/jetonnet/**"
583
}
584

    
585
task hej_setupPreprocessForPej(
586
  type: Copy,
587
  dependsOn: ["hej_featureKeys"],
588
  description: "Copy HE sources for preprocessing PE"
589
) {
590
  from "${projectDir}/src/main/java"
591
  into "${buildDir}/filtered/pej"
592
  include "net/sf/saxon/**/*.java"
593
  include "javax/xml/xquery/*.java"
594
  exclude "**/dotnet/**"
595
  include "net/sf/saxon/**/package.html"
596
  exclude "net/sf/saxon/testdriver/**"
597
  exclude "net/sf/saxon/option/cpp/**"
598
  exclude "net/sf/saxon/jetonnet/**"
599
  //include "net/sf/saxon/data/**"
600
}
601

    
602
task eej_setupPreprocessForPej(
603
  type: Copy,
604
  description: "Copy EE sources for preprocessing PE"
605
) {
606
  from "${projectDir}/src/main/java"
607
  into "${buildDir}/filtered/pej"
608
  include "com/saxonica/**/*.java"
609
  exclude "com/saxonica/functions/extfn/cpp/*.java"
610
  exclude "com/saxonica/testdriver/**"
611
  exclude "com/saxonica/testdriver/ee/**/*.java"
612
  exclude "com/saxonica/testdriver/old/**/*.java"
613
  exclude "com/saxonica/ee/**"
614
  exclude "com/saxonica/config/EnterpriseConfiguration.java"
615
  exclude "com/saxonica/expr/CastToUnion.java"
616
  exclude "com/saxonica/expr/CastableToUnion.java"
617
  exclude "com/saxonica/expr/DotNetExtensionFunctionCall.java"
618
  exclude "com/saxonica/config/ee/**"
619
  exclude "com/saxonica/js/**"
620
  exclude "com/saxonica/config/DotNetExtensionLibrary.java"
621
  exclude "com/saxonica/config/DotNetExtensionFunctionFactory.java"
622
  exclude "com/saxonica/config/DotNetPlatformPE.java"
623
  exclude "com/saxonica/config/JavaPlatformEE.java"
624
  exclude "com/saxonica/config/NativePlatformPE.java"
625
  exclude "com/saxonica/Validate.java"
626
  exclude "com/saxonica/config/EnterpriseTransformerFactory.java"
627
  exclude "com/saxonica/config/StreamingTransformerFactory.java"
628
  exclude "com/saxonica/config/EnterpriseXPathFactory.java"
629
  exclude "com/saxonica/config/DynamicLoaderEE.java"
630
  exclude "com/saxonica/config/StandardSchemaResolver.java"
631
  exclude "com/saxonica/jaxp/SchemaFactoryImpl11.java"
632
  exclude "com/saxonica/functions/extfn/NativeCall.java"
633
}
634

    
635
task pej_setupPreprocess(
636
  dependsOn: ["hej_setupPreprocessForPej", "eej_setupPreprocessForPej", "record_branch"],
637
  description: "Copy sources for preprocessing PE"
638
) {
639
  // Just a container to hang dependencies on
640
}
641

    
642
task hej_setupPreprocessForEej(
643
  type: Copy,
644
  dependsOn: ["hej_featureKeys", "record_branch"],
645
  description: "Copy HE sources for EE build"
646
) {
647
  from "${projectDir}/src/main/java"
648
  into "${buildDir}/filtered/eej"
649
  include "net/sf/saxon/**/*.java"
650
  include "javax/xml/xquery/*.java"
651
  exclude "**/dotnet/**"
652
  include "net/sf/saxon/**/package.html"
653
  exclude "net/sf/saxon/testdriver/**"
654
  exclude "net/sf/saxon/option/cpp/**"
655
  exclude "net/sf/saxon/jetonnet/**"
656
  exclude "net/sf/saxon/jetonnet/**"
657
  //include "net/sf/saxon/data/**"
658
}
659

    
660
// Rename org.objectweb to com.saxonica.objectweb in the bytecode sources
661
task eej_setupPreprocessBytecode(
662
  type: Copy,
663
  description: "Copy bytecode sources and fix imports"
664
) {
665
  from "${projectDir}/src/main/java"
666
  into "${buildDir}/filtered/eej"
667
  include "com/saxonica/ee/bytecode/**/*.java"
668
  filter { line ->
669
    line.contains("org.objectweb")
670
      ? line.replaceAll("org.objectweb", "com.saxonica.objectweb")
671
      : line
672
  }
673
}
674

    
675
// N.B. bytecode is explicitly excluded, see eej_setupPreprocessBytecode
676
task eej_setupPreprocess(
677
  type: Copy,
678
  dependsOn: ["hej_setupPreprocessForEej", "eej_setupPreprocessBytecode", "record_branch"],
679
  description: "Copy sources for preprocessing EE"
680
) {
681
  from "${projectDir}/src/main/java"
682
  into "${buildDir}/filtered/eej"
683
  include "com/saxonica/**/*.java"
684
  exclude "com/saxonica/ee/bytecode/**/*.java"
685
  exclude "com/saxonica/functions/extfn/cpp/*.java"
686
  exclude "com/saxonica/testdriver/**/*.java"
687
  exclude "com/saxonica/config/DotNetExtensionFunctionFactory.java"
688
  exclude "com/saxonica/config/DotNetExtensionLibrary.java"
689
  exclude "com/saxonica/config/DotNetPlatformPE.java"
690
  exclude "com/saxonica/config/NativePlatformPE.java"
691
  exclude "com/saxonica/expr/DotNetExtensionFunctionCall.java"
692
  exclude "com/saxonica/functions/extfn/NativeCall.java"
693
  include "com/saxonica/**/package.html"
694
  exclude "com/saxonica/js/**"
695
}
696

    
697
// ============================================================
698

    
699
task hej_preprocess(
700
  type: JavaExec,
701
  dependsOn: ["hej_setupPreprocess"],
702
  description: "Preprocess HE sources"
703
) {
704
  inputs.files fileTree(dir: "${buildDir}/filtered/hej")
705
  outputs.files fileTree(dir: "${buildDir}/preprocess/hej")
706
  classpath = configurations.preprocessor
707
  main = "com.igormaznitsa.jcp.JcpPreprocessor"
708
  args "/c",
709
    "/i:${buildDir}/filtered/hej", "/o:${buildDir}/preprocess/hej",
710
    "/p:EE=false", "/p:PE=false", "/p:DOTNET=false",
711
    "/p:OPT=false", "/p:SAXONC=false", "/p:BYTECODE=false"
712
  doFirst {
713
    mkdir "${buildDir}/preprocess/hej"
714
  }
715
}
716

    
717
task pej_preprocess(
718
  type: JavaExec,
719
  dependsOn: ["pej_setupPreprocess"],
720
  description: "Preprocess HE sources"
721
) {
722
  inputs.files fileTree(dir: "${buildDir}/filtered/pej")
723
  outputs.files fileTree(dir: "${buildDir}/preprocess/pej")
724
  classpath = configurations.preprocessor
725
  main = "com.igormaznitsa.jcp.JcpPreprocessor"
726
  args "/c",
727
    "/i:${buildDir}/filtered/pej", "/o:${buildDir}/preprocess/pej",
728
    "/p:EE=false", "/p:PE=true", "/p:DOTNET=false", "/p:HOF=true",
729
    "/p:OPT=false", "/p:SAXONC=false", "/p:BYTECODE=false"
730
  doFirst {
731
    mkdir "${buildDir}/preprocess/pej"
732
  }
733
}
734

    
735
task eej_preprocess(
736
  type: JavaExec,
737
  dependsOn: ["eej_setupPreprocess", "asm_jarjar"],
738
  description: "Preprocess EE sources"
739
) {
740
  inputs.files fileTree(dir: "${buildDir}/filtered/eej")
741
  outputs.files fileTree(dir: "${buildDir}/preprocess/eej")
742
  classpath = configurations.preprocessor
743
  main = "com.igormaznitsa.jcp.JcpPreprocessor"
744
  args "/c",
745
    "/i:${buildDir}/filtered/eej", "/o:${buildDir}/preprocess/eej",
746
    "/p:EE=true", "/p:PE=false", "/p:DOTNET=false", "/p:HOF=true",
747
    "/p:OPT=false", "/p:SAXONC=false", "/p:BYTECODE=true",
748
    "/p:STREAM=true", "/p:PACKAGES=true", "/p:SCHEMA=true"
749
  doFirst {
750
    mkdir "${buildDir}/preprocess/eej"
751
  }
752
}
753

    
754
// ============================================================
755

    
756
task hej_sources(
757
  type: Copy,
758
  dependsOn: ["hej_preprocess"],
759
  description: "Collect the preprocessed HE sources for compilation"
760
) {
761
  from "${buildDir}/preprocess/hej"
762
  into "${buildDir}/src/hej"
763
  filter { line ->
764
    line.contains("import com.saxonica") ? null : line.replaceFirst("\\s++\$", "")
765
  }
766
}
767

    
768
task pej_sources(
769
  type: Copy,
770
  dependsOn: ["pej_preprocess"],
771
  description: "Collect the preprocessed PE sources for compilation"
772
) {
773
  from "${buildDir}/preprocess/pej"
774
  into "${buildDir}/src/pej"
775
  filter { line ->
776
    if (line.contains("import com.saxonica.ee")
777
        || line.contains("import com.saxonica.config.ee")) {
778
      null
779
    } else {
780
      line.replaceFirst("\\s++\$", "")
781
    }
782
  }
783
}
784

    
785
task eej_sources(
786
  type: Copy,
787
  dependsOn: ["eej_preprocess"],
788
  description: "Collect the preprocessed EE sources for compilation"
789
) {
790
  from "${buildDir}/preprocess/eej"
791
  into "${buildDir}/src/eej"
792
}
793

    
794
// ============================================================
795

    
796
task record_branch(
797
  type: Exec,
798
  description: "Records the branch so we can detect switches."
799
) {
800
  def recordBranch = new ByteArrayOutputStream();
801
  commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
802
  standardOutput = recordBranch
803
  doLast {
804
    def output = new FileWriter(new File("${buildDir}/built-branch"))
805
    output.write(recordBranch.toString("utf-8"))
806
    output.close()
807
  }
808
  doFirst {
809
    mkdir(buildDir)
810
  }
811
}
812

    
813
task hejCompile(
814
  type: JavaCompile,
815
  dependsOn: ["hej_sources"],
816
  description: "Compile HE for Saxon/Java"
817
) {
818
  classpath = configurations.compileClasspath
819
  source "${buildDir}/src/hej"
820
  destinationDirectory = new File("${buildDir}/classes/hej")
821
}
822

    
823
task pejCompile(
824
  type: JavaCompile,
825
  dependsOn: ["pej_sources"],
826
  description: "Compile PE for Saxon/Java"
827
) {
828
  classpath = configurations.compileClasspath
829
  source "${buildDir}/src/pej"
830
  destinationDirectory = new File("${buildDir}/classes/pej")
831
}
832

    
833
task eejCompile(
834
  type: JavaCompile,
835
  dependsOn: ["eej_sources"],
836
  description: "Compile EE for Saxon/Java"
837
) {
838
  classpath = configurations.compileClasspath + configurations.jarjarAsm
839
  source "${buildDir}/src/eej"
840
  destinationDirectory = new File("${buildDir}/classes/eej")
841
}
842

    
843
// ============================================================
844

    
845
task hej_copyTestDriverSources(
846
  type: Copy,
847
  description: "Copy test drivers sources for HE"
848
) {
849
  from "src/main/java"
850
  into "${buildDir}/src/testdrivers/hej"
851
  include "net/sf/saxon/testdriver/*.java"
852
}
853

    
854
task pej_copyTestDriverSources(
855
  type: Copy,
856
  description: "Copy test drivers sources for PE"
857
) {
858
  from "src/main/java"
859
  into "${buildDir}/src/testdrivers/pej"
860
  include "com/saxonica/testdriver/QT3TestDriverPE.java"
861
  include "com/saxonica/testdriver/Xslt30TestSuiteDriverPE.java"
862
  include "com/saxonica/testdriver/Licensor.java"
863
  include "net/sf/saxon/testdriver/*.java"
864
}
865

    
866
task eej_copyTestDriverSources(
867
  type: Copy,
868
  description: "Copy test drivers sources for EE"
869
) {
870
  from "src/main/java"
871
  into "${buildDir}/src/testdrivers/eej"
872
  include "com/saxonica/testdriver/**/*.java"
873
  include "com/saxonica/js/*.java"
874
  include "net/sf/saxon/testdriver/*.java"
875
}
876

    
877
task hej_copyTestDriverResources(
878
  type: Copy,
879
  description: "Copy test drivers resources for HE"
880
) {
881
  from "src/main/java"
882
  into "${buildDir}/testdriver_classes/hej"
883
  include "net/sf/saxon/testdriver/**"
884
  exclude "net/sf/saxon/testdriver/**/*.java"
885
}
886

    
887
task pej_copyTestDriverResources(
888
  type: Copy,
889
  description: "Copy test drivers resources for PE"
890
) {
891
  from "src/main/java"
892
  into "${buildDir}/testdriver_classes/pej"
893
  include "net/sf/saxon/testdriver/**"
894
  include "com/saxonica/testdriver/**"
895
  exclude "net/sf/saxon/testdriver/**/*.java"
896
  exclude "com/saxonica/testdriver/**/*.java"
897
  exclude "com/saxonica/testdriver/old/**"
898
  exclude "com/saxonica/testdriver/gui/cache.xml"
899
}
900

    
901
task eej_copyTestDriverResources(
902
  type: Copy,
903
  description: "Copy test drivers resources for EE"
904
) {
905
  from "src/main/java"
906
  into "${buildDir}/testdriver_classes/eej"
907
  include "net/sf/saxon/testdriver/**"
908
  include "com/saxonica/testdriver/**"
909
  exclude "net/sf/saxon/testdriver/**/*.java"
910
  exclude "com/saxonica/testdriver/**/*.java"
911
  exclude "com/saxonica/testdriver/old/**"
912
  exclude "com/saxonica/testdriver/gui/cache.xml"
913
}
914

    
915
// ============================================================
916
// These tasks all relate to renaming (re-jarring) the ASM jar files
917
// for EE so that the class names begin com.saxonica. This avoids a
918
// problem where a different version of the ASM libraries is used in
919
// the application that is using Saxon.
920

    
921
task asm_createRules(
922
  description: "Create the jarjar rules file for the ASM libraries"
923
) {
924
  outputs.file("${buildDir}/jarjar-asm.rules")
925
  doLast {
926
    new File("${buildDir}/jarjar-asm.rules")
927
      .withWriter("utf-8") { writer ->
928
        writer.writeLine("rule org.objectweb.** com.saxonica.objectweb.@1")
929
      }
930
  }
931
  doFirst {
932
    mkdir "${buildDir}"
933
  }
934
}
935

    
936
task asm_jarjar(
937
  description: "Placeholder for the ASM jarjar dependencies"
938
) {
939
  // just a task to hang dependencies on
940
}
941

    
942
task asm_unzip(
943
  type: Copy,
944
  description: "Extract classes from the asm-xml-${asmVersion} jar"
945
) {
946
  // This one is from the original ASM
947
  def zipFile = file("lib/asm-${asmVersion}/asm-xml-${asmVersion}.jar")
948
  def outputDir = "${buildDir}/classes/eej"
949
  from zipTree(zipFile)
950
  into outputDir
951
}
952

    
953
["asm", "asm-analysis", "asm-commons", "asm-tree", "asm-util"].each { asm ->
954
  Task t = task "asm_${asm}"(
955
    type: JavaExec,
956
    dependsOn: ["asm_createRules"],
957
    description: "Run jarjar on ${asm}-${asmVersion} classes"
958
) {
959
    inputs.file "lib/asm-${asmVersion}/${asm}-${asmVersion}.jar"
960
    outputs.file "${buildDir}/lib/asm/${asm}-${asmVersion}.jar"
961
    classpath = configurations.preprocessor
962
    main = "com.tonicsystems.jarjar.Main"
963
    args "--rules", "${buildDir}/jarjar-asm.rules",
964
      "lib/asm-${asmVersion}/${asm}-${asmVersion}.jar",
965
      "${buildDir}/lib/asm/${asm}-${asmVersion}.jar"
966
    doFirst {
967
      mkdir "${buildDir}/lib/asm"
968
    }
969
  }
970
  asm_jarjar.dependsOn t
971

    
972
  t = task "asm_unzip${asm}"(
973
    type: Copy,
974
    dependsOn: ["asm_jarjar"],
975
    description: "Extract the classes from the ${asm}-${asmVersion} jar"
976
  ) {
977
    def zipFile = file("${buildDir}/lib/asm/${asm}-${asmVersion}.jar")
978
    def outputDir = "${buildDir}/classes/eej"
979
    from zipTree(zipFile)
980
    into outputDir
981
  }
982
  asm_unzip.dependsOn t
983
}
984

    
985
// ============================================================
986

    
987
task hej_MetaInf(
988
  description: "Create META-INF/services/javax.xml.transform.TransformerFactory for HE"
989
) {
990
  outputs.file("${buildDir}/services/saxon-he/META-INF/services/javax.xml.transform.TransformerFactory")
991
  doFirst {
992
    mkdir "${buildDir}/services/saxon-he/META-INF/services"
993
  }
994
  doLast {
995
    new File("${buildDir}/services/saxon-he/META-INF/services/javax.xml.transform.TransformerFactory")
996
      .withWriter("utf-8") { writer ->
997
        writer.writeLine("net.sf.saxon.TransformerFactoryImpl")
998
      }
999
  }
1000
}
1001

    
1002
task pej_MetaInf(
1003
  description: "Create META-INF/services/javax.xml.transform.TransformerFactory for PE"
1004
) {
1005
  outputs.file("${buildDir}/services/saxon-pe/META-INF/services/javax.xml.transform.TransformerFactory")
1006
  doFirst {
1007
    mkdir "${buildDir}/services/saxon-pe/META-INF/services"
1008
  }
1009
  doLast {
1010
    new File("${buildDir}/services/saxon-pe/META-INF/services/javax.xml.transform.TransformerFactory")
1011
      .withWriter("utf-8") { writer ->
1012
        writer.writeLine("com.saxonica.config.ProfessionalTransformerFactory")
1013
      }
1014
  }
1015
}
1016

    
1017
task eej_schemaFactoryMetaInf(
1018
  description: "Create META-INF/services/javax.xml.validation.SchemaFactory for EE"
1019
) {
1020
  outputs.file("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.validation.SchemaFactory")
1021
  doFirst {
1022
    mkdir "${buildDir}/services/saxon-ee/META-INF/services"
1023
  }
1024
  doLast {
1025
    new File("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.validation.SchemaFactory")
1026
      .withWriter("utf-8") { writer ->
1027
        writer.writeLine("com.saxonica.ee.jaxp.SchemaFactoryImpl")
1028
      }
1029
  }
1030
}
1031

    
1032
task eej_MetaInf(
1033
  dependsOn: ["eej_schemaFactoryMetaInf"],
1034
  description: "Create META-INF/services/javax.xml.transform.TransformerFactory for EE"
1035
) {
1036
  outputs.file("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.transform.TransformerFactory")
1037
  doFirst {
1038
    mkdir "${buildDir}/services/saxon-ee/META-INF/services"
1039
  }
1040
  doLast {
1041
    new File("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.transform.TransformerFactory")
1042
      .withWriter("utf-8") { writer ->
1043
        writer.writeLine("com.saxonica.config.EnterpriseTransformerFactory")
1044
      }
1045
  }
1046
}
1047

    
1048
// ============================================================
1049

    
1050
task hejJar(
1051
  type: Jar,
1052
  dependsOn: ["hej_MetaInf", "hejCompile"],
1053
  description: "Build the HE jar file"
1054
) {
1055
  archiveBaseName = "saxon-he-${saxonVersion}"
1056
  manifest {
1057
    attributes "Project-Name": "Saxon-HE"
1058
    attributes "Main-Class": "net.sf.saxon.Transform"
1059
  }
1060
  from ("${buildDir}/services/saxon-he") {
1061
    include "META-INF/**"
1062
  }
1063
  from ("${buildDir}/classes/hej") {
1064
    include "net/**/*.class"
1065
    exclude "net/sf/saxon/option/**"
1066
  }
1067
  from ("src/main/resources") {
1068
    include "net/sf/saxon/data/**"
1069
  }
1070
}
1071

    
1072
// Because the XQJ files are not open source, don't attempt to build
1073
// the jar unless the EE sources are available.
1074
if (file("${projectDir}/src/main/java/com/saxonica/xqj").exists()) {
1075
  task hejJarXqj(
1076
    type: Jar,
1077
    dependsOn: ["eejCompile"],
1078
    description: "Build the XQJ jar file for HE"
1079
  ) {
1080
    archiveBaseName = "saxon-he-xqj-${saxonVersion}"
1081
    from ("${buildDir}/classes/eej") {
1082
      include "com/saxonica/xqj/**/*.class"
1083
      include "javax/xml/xquery/**/*.class"
1084
    }
1085
  }
1086
} else {
1087
  task hejJarXqj(
1088
    description: "Ignore the XQJ file; the sources are unavailable"
1089
  ) {
1090
    doLast {
1091
      println("Ignoring XQJ jar file task; the sources are unavailable")
1092
    }
1093
  }
1094
}
1095

    
1096
task pejJar(
1097
  type: Jar,
1098
  dependsOn: ["pej_MetaInf", "pejCompile"],
1099
  description: "Build the PE jar file"
1100
) {
1101
  archiveBaseName = "saxon-pe-${saxonVersion}"
1102
  manifest {
1103
    attributes "Project-Name": "Saxon-PE"
1104
    attributes "Main-Class": "net.sf.saxon.Transform"
1105
  }
1106
  from ("${buildDir}/services/saxon-pe") {
1107
    include "META-INF/**"
1108
  }
1109
  from ("${buildDir}/classes/pej") {
1110
    include "net/**/*.class"
1111
    include "com/saxonica/**/*.class"
1112
    include "javax/xml/xquery/*.class"
1113
    exclude "**/sql/**/*.class"
1114
    exclude "com/saxonica/CompileStylesheet.class"
1115
    exclude "com/saxonica/CompileStylesheet\$TracingObjectOutputStream.class"
1116
    exclude "com/saxonica/Validate.class"
1117
    exclude "com/saxonica/config/EnterpriseConfiguration.class"
1118
    exclude "com/saxonica/config/EnterpriseConfiguration\$SurrogateSchema.class"
1119
    exclude "com/saxonica/config/EnterpriseTransformerFactory.class"
1120
    exclude "com/saxonica/config/EnterpriseXPathFactory.class"
1121
    exclude "com/saxonica/config/StreamingTransformerFactory.class"
1122
    exclude "com/saxonica/ee/**/*.class"
1123
    exclude "com/saxonica/expr/CastToList.class"
1124
    exclude "com/saxonica/expr/CastToUnion.class"
1125
    exclude "com/saxonica/expr/CastableToList.class"
1126
    exclude "com/saxonica/expr/CastableToUnion.class"
1127
    exclude "com/saxonica/functions/sql/**"
1128
    exclude "net/sf/saxon/option/sql/**"
1129
  }
1130
  from ("src/main/resources") {
1131
    include "net/sf/saxon/data/**"
1132
  }
1133
}
1134

    
1135
task pejJarSql(
1136
  type: Jar,
1137
  dependsOn: ["pejCompile"],
1138
  description: "Build the SQL jar file for PE"
1139
) {
1140
  archiveBaseName = "saxon-pe-sql-${saxonVersion}"
1141
  from ("${buildDir}/classes/pej") {
1142
    include "net/sf/saxon/option/sql/*.class"
1143
    include "com/saxonica/functions/sql/*.class"
1144
  }
1145
}
1146

    
1147
task eejJar(
1148
  type: Jar,
1149
  dependsOn: ["eej_MetaInf", "eejCompile", "asm_unzip"],
1150
  description: "Build the EE jar file"
1151
) {
1152
  archiveBaseName = "saxon-ee-${saxonVersion}"
1153
  manifest {
1154
    attributes "Project-Name": "Saxon-EE"
1155
    attributes "Main-Class": "net.sf.saxon.Transform"
1156
  }
1157
  from ("${buildDir}/services/saxon-ee") {
1158
    include "META-INF/**"
1159
  }
1160
  from ("${buildDir}/classes/eej") {
1161
    include "net/**/*.class"
1162
    include "com/saxonica/**/*.class"
1163
    include "javax/xml/xquery/*.class"
1164
    exclude "org/objectweb/**/*.class"
1165
    exclude "**/sql/**/*.class"
1166
    exclude "com/saxonica/StatsTransform*.class"
1167
    exclude "com/saxonica/functions/sql/**"
1168
    exclude "net/sf/saxon/option/sql/**"
1169
  }
1170
  from ("src/main/resources") {
1171
    include "net/sf/saxon/data/**"
1172
  }
1173
}
1174

    
1175
task eejJarSql(
1176
  type: Jar,
1177
  dependsOn: ["eejCompile"],
1178
  description: "Build the SQL jar file for EE"
1179
) {
1180
  archiveBaseName = "saxon-ee-sql-${saxonVersion}"
1181
  from ("${buildDir}/classes/eej") {
1182
    include "net/sf/saxon/option/sql/*.class"
1183
    include "com/saxonica/functions/sql/*.class"
1184
  }
1185
}
1186

    
1187
// ============================================================
1188

    
1189
task signJars(
1190
  dependsOn: ["hejSignJars", "pejSignJars", "eejSignJars"],
1191
  description: "Sign all the jar files."
1192
) {
1193
  // Just a container to hang dependencies on
1194
}
1195

    
1196
task hejSignJars(
1197
  description: "Sign the HEJ jar files"
1198
) {
1199
  // Just a container to hang dependencies on
1200
}
1201

    
1202
task pejSignJars(
1203
  description: "Sign the PEJ jar files"
1204
) {
1205
  // Just a container to hang dependencies on
1206
}
1207

    
1208
task eejSignJars(
1209
  description: "Sign the EEJ jar files"
1210
) {
1211
  // Just a container to hang dependencies on
1212
}
1213

    
1214
// Create tasks for signing jars...
1215
["he", "pe", "ee"].each { rel ->
1216
  if (canSignJars) {
1217
    Task t = task "${rel}_jJarSignJar"(
1218
      type: Exec,
1219
      dependsOn: ["${rel}jJar"],
1220
      description: "Sign the ${rel.toUpperCase()}J jar file"
1221
    ) {
1222
      inputs.file "${buildDir}/libs/saxon-${rel}-${saxonVersion}.jar"
1223
      def args = signjarArgs +
1224
        ["${buildDir}/libs/saxon-${rel}-${saxonVersion}.jar",
1225
         signkeyNewAlias,
1226
         "-storepass", signkeyPassword]
1227
      commandLine args
1228
    }
1229
    tasks.findByName("${rel}jSignJars").dependsOn t
1230

    
1231
    t = task "${rel}j_JarSignTests"(
1232
      type: Exec,
1233
      dependsOn: ["${rel}jJarTests"],
1234
      description: "Sign the ${rel.toUpperCase()}J test jar file"
1235
    ) {
1236
      inputs.file "${buildDir}/libs/saxon-${rel}-test-${saxonVersion}.jar"
1237
      def args = signjarArgs +
1238
        ["${buildDir}/libs/saxon-${rel}-test-${saxonVersion}.jar",
1239
         signkeyNewAlias,
1240
         "-storepass", signkeyPassword]
1241
      commandLine args
1242
    }
1243
    tasks.findByName("${rel}jSignJars").dependsOn t
1244

    
1245
    t = task "${rel}j_JarSignXqj"(
1246
      type: Exec,
1247
      dependsOn: ["${rel}jJarXqj"],
1248
      description: "Sign the ${rel.toUpperCase()}J XQJ jar file"
1249
    ) {
1250
      inputs.file "${buildDir}/libs/saxon-${rel}-xqj-${saxonVersion}.jar"
1251
      def args = signjarArgs +
1252
        ["${buildDir}/libs/saxon-${rel}-xqj-${saxonVersion}.jar",
1253
         signkeyNewAlias,
1254
         "-storepass", signkeyPassword]
1255
      commandLine args
1256
    }
1257
    tasks.findByName("${rel}jSignJars").dependsOn t
1258

    
1259
    if (rel != 'he') {
1260
      t = task "${rel}j_JarSignSql"(
1261
        type: Exec,
1262
        dependsOn: ["${rel}jJarSql"],
1263
        description: "Sign the ${rel.toUpperCase()} jar file"
1264
      ) {
1265
        inputs.file "${buildDir}/libs/saxon-${rel}-sql-${saxonVersion}.jar"
1266
        def args = signjarArgs +
1267
          ["${buildDir}/libs/saxon-${rel}-sql-${saxonVersion}.jar",
1268
           signkeyNewAlias,
1269
           "-storepass", signkeyPassword]
1270
        commandLine args
1271
      }
1272
      tasks.findByName("${rel}jSignJars").dependsOn t
1273
    }
1274
  } else {
1275
    Task t = task "${rel}j_JarSignJar"(
1276
      description: "Cannot sign the ${rel.toUpperCase()}J jar file"
1277
    ) {
1278
      doLast {
1279
        throw new GradleException("Jar signing is not configured.")
1280
      }
1281
    }
1282
    tasks.findByName("${rel}jSignJars").dependsOn t
1283

    
1284
    t = task "${rel}j_JarSignTests"(
1285
      description: "Cannot sign the ${rel.toUpperCase()}J test jar file"
1286
    ) {
1287
      doLast {
1288
        throw new GradleException("Jar signing is not configured.")
1289
      }
1290
    }
1291
    tasks.findByName("${rel}jSignJars").dependsOn t
1292

    
1293
    t = task "${rel}j_JarSignXqj"(
1294
      description: "Cannot sign the ${rel.toUpperCase()}J XQJ jar file"
1295
    ) {
1296
      doLast {
1297
        throw new GradleException("Jar signing is not configured.")
1298
      }
1299
    }
1300
    tasks.findByName("${rel}jSignJars").dependsOn t
1301

    
1302
    if (rel != 'he') {
1303
      t = task "${rel}j_JarSignSql"(
1304
        description: "Cannot sign the ${rel.toUpperCase()} jar file"
1305
      ) {
1306
        doLast {
1307
          throw new GradleException("Jar signing is not configured.")
1308
        }
1309
      }
1310
      tasks.findByName("${rel}jSignJars").dependsOn t
1311
    }
1312
  }    
1313
}
1314

    
1315
// ============================================================
1316

    
1317
task hejRelease(
1318
  type: Copy,
1319
  dependsOn: ["hejJar", "hejJarXqj", "hejJarTests", "hej_notices"],
1320
  description: "Build the HE release for Java"
1321
) {
1322
  from "${buildDir}/libs"
1323
  into "${buildDir}/releases/hej"
1324
  include "saxon-he-${saxonVersion}.jar"
1325
  include "saxon-he-xqj-${saxonVersion}.jar"
1326
  include "saxon-he-test-${saxonVersion}.jar"
1327
  rename { filename ->
1328
    if (filename.startsWith("saxon-he-test")) {
1329
      filename = "saxon-he-test-${saxonVersion}.jar"
1330
    }
1331
  }
1332
}
1333

    
1334
task pejRelease(
1335
  type: Copy,
1336
  dependsOn: ["pejJar", "pejJarSql", "pejJarTests", "pej_libs", "pej_notices"],
1337
  description: "Build the PE release for Java"
1338
) {
1339
  from "${buildDir}/libs"
1340
  into "${buildDir}/releases/pej"
1341
  include "saxon-pe-${saxonVersion}.jar"
1342
  include "saxon-pe-sql-${saxonVersion}.jar"
1343
  include "saxon-pe-test-${saxonVersion}.jar"
1344
  rename { filename ->
1345
    if (filename.startsWith("saxon-pe-sql")) {
1346
      filename.replace("saxon-pe-sql", "saxon-sql")
1347
    } else {
1348
      filename
1349
    }
1350
  }
1351
}
1352

    
1353
task eejRelease(
1354
  type: Copy,
1355
  dependsOn: ["eejJar", "eejJarSql", "eejJarTests", "eej_libs", "eej_notices"],
1356
  description: "Build the EE release for Java"
1357
) {
1358
  from "${buildDir}/libs"
1359
  into "${buildDir}/releases/eej"
1360
  include "saxon-ee-${saxonVersion}.jar"
1361
  include "saxon-ee-sql-${saxonVersion}.jar"
1362
  include "saxon-ee-test-${saxonVersion}.jar"
1363
  rename { filename ->
1364
    if (filename.startsWith("saxon-ee-sql")) {
1365
      filename.replace("saxon-ee-sql", "saxon-sql")
1366
    } else {
1367
      filename
1368
    }
1369
  }
1370
}
1371

    
1372
if (file("${projectDir}/src/main/java/com").exists()) {
1373
  task javaReleases(
1374
    dependsOn: ["hejRelease", "pejRelease", "eejRelease"],
1375
    description: "Build all of the Java releases"
1376
  ) {
1377
    // Just a container to hang dependencies on
1378
  }
1379
} else {
1380
  // Ignore the EEJ and PEJ releases if the sources aren't available
1381
  task javaReleases(
1382
    dependsOn: ["hejRelease"],
1383
    description: "Build all of the Java releases"
1384
  ) {
1385
    // Just a container to hang dependencies on
1386
  }
1387
}
1388

    
1389
// ============================================================
1390

    
1391
compileTestDrivers.dependsOn "${saxonEdition}j_compileTestDrivers"
1392
runQT3TestDriver.dependsOn "${saxonEdition}j_runQT3TestDriver"
1393
runXslt30TestSuiteDriver.dependsOn "${saxonEdition}j_runXslt30TestSuiteDriver"
1394

    
1395
// ============================================================
1396

    
1397
// Testing task for various Gradle debugging efforts
1398
task helloWorld() {
1399
  doLast {
1400
    println("Hello, world.")
1401
    /*
1402
    configurations.documentation.resolve().each { path ->
1403
      println(path)
1404
    }
1405
     */
1406
  }
1407
}
(8-8/13)