Project

Profile

Help

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

he / build.gradle @ 3dd08c26

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
296
  return false
297
}
298

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

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

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

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

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

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

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

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

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

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

    
390
// ============================================================
391

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

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

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

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

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

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

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

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

    
475
// ============================================================
476

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

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

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

    
525
// ============================================================
526

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

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

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

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

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

    
630
task pej_setupPreprocess(
631
  dependsOn: ["hej_setupPreprocessForPej", "eej_setupPreprocessForPej", "record_branch"],
632
  description: "Copy sources for preprocessing PE"
633
) {
634
  // Just a container to hang dependencies on
635
}
636

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

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

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

    
692
// ============================================================
693

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

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

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

    
749
// ============================================================
750

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

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

    
780
task eej_sources(
781
  type: Copy,
782
  dependsOn: ["eej_preprocess"],
783
  description: "Collect the preprocessed EE sources for compilation"
784
) {
785
  from "${buildDir}/preprocess/eej"
786
  into "${buildDir}/src/eej"
787
}
788

    
789
// ============================================================
790

    
791
task record_branch(
792
  type: Exec,
793
  description: "Records the branch so we can detect switches."
794
) {
795
  def recordBranch = new ByteArrayOutputStream();
796
  commandLine "git", "branch", "--show-current"
797
  standardOutput = recordBranch
798
  doLast {
799
    def output = new FileWriter(new File("build/built-branch"))
800
    output.write(recordBranch.toString("utf-8"))
801
    output.close()
802
  }
803
}
804

    
805
task hejCompile(
806
  type: JavaCompile,
807
  dependsOn: ["hej_sources"],
808
  description: "Compile HE for Saxon/Java"
809
) {
810
  classpath = configurations.compileClasspath
811
  source "${buildDir}/src/hej"
812
  destinationDirectory = new File("${buildDir}/classes/hej")
813
}
814

    
815
task pejCompile(
816
  type: JavaCompile,
817
  dependsOn: ["pej_sources"],
818
  description: "Compile PE for Saxon/Java"
819
) {
820
  classpath = configurations.compileClasspath
821
  source "${buildDir}/src/pej"
822
  destinationDirectory = new File("${buildDir}/classes/pej")
823
}
824

    
825
task eejCompile(
826
  type: JavaCompile,
827
  dependsOn: ["eej_sources"],
828
  description: "Compile EE for Saxon/Java"
829
) {
830
  classpath = configurations.compileClasspath + configurations.jarjarAsm
831
  source "${buildDir}/src/eej"
832
  destinationDirectory = new File("${buildDir}/classes/eej")
833
}
834

    
835
// ============================================================
836

    
837
task hej_copyTestDriverSources(
838
  type: Copy,
839
  description: "Copy test drivers sources for HE"
840
) {
841
  from "src/main/java"
842
  into "${buildDir}/src/testdrivers/hej"
843
  include "net/sf/saxon/testdriver/*.java"
844
}
845

    
846
task pej_copyTestDriverSources(
847
  type: Copy,
848
  description: "Copy test drivers sources for PE"
849
) {
850
  from "src/main/java"
851
  into "${buildDir}/src/testdrivers/pej"
852
  include "com/saxonica/testdriver/QT3TestDriverPE.java"
853
  include "com/saxonica/testdriver/Xslt30TestSuiteDriverPE.java"
854
  include "com/saxonica/testdriver/Licensor.java"
855
  include "net/sf/saxon/testdriver/*.java"
856
}
857

    
858
task eej_copyTestDriverSources(
859
  type: Copy,
860
  description: "Copy test drivers sources for EE"
861
) {
862
  from "src/main/java"
863
  into "${buildDir}/src/testdrivers/eej"
864
  include "com/saxonica/testdriver/**/*.java"
865
  include "net/sf/saxon/testdriver/*.java"
866
}
867

    
868
task hej_copyTestDriverResources(
869
  type: Copy,
870
  description: "Copy test drivers resources for HE"
871
) {
872
  from "src/main/java"
873
  into "${buildDir}/testdriver_classes/hej"
874
  include "net/sf/saxon/testdriver/**"
875
  exclude "net/sf/saxon/testdriver/**/*.java"
876
}
877

    
878
task pej_copyTestDriverResources(
879
  type: Copy,
880
  description: "Copy test drivers resources for PE"
881
) {
882
  from "src/main/java"
883
  into "${buildDir}/testdriver_classes/pej"
884
  include "net/sf/saxon/testdriver/**"
885
  include "com/saxonica/testdriver/**"
886
  exclude "net/sf/saxon/testdriver/**/*.java"
887
  exclude "com/saxonica/testdriver/**/*.java"
888
  exclude "com/saxonica/testdriver/old/**"
889
  exclude "com/saxonica/testdriver/gui/cache.xml"
890
}
891

    
892
task eej_copyTestDriverResources(
893
  type: Copy,
894
  description: "Copy test drivers resources for EE"
895
) {
896
  from "src/main/java"
897
  into "${buildDir}/testdriver_classes/eej"
898
  include "net/sf/saxon/testdriver/**"
899
  include "com/saxonica/testdriver/**"
900
  exclude "net/sf/saxon/testdriver/**/*.java"
901
  exclude "com/saxonica/testdriver/**/*.java"
902
  exclude "com/saxonica/testdriver/old/**"
903
  exclude "com/saxonica/testdriver/gui/cache.xml"
904
}
905

    
906
// ============================================================
907
// These tasks all relate to renaming (re-jarring) the ASM jar files
908
// for EE so that the class names begin com.saxonica. This avoids a
909
// problem where a different version of the ASM libraries is used in
910
// the application that is using Saxon.
911

    
912
task asm_createRules(
913
  description: "Create the jarjar rules file for the ASM libraries"
914
) {
915
  outputs.file("${buildDir}/jarjar-asm.rules")
916
  doLast {
917
    new File("${buildDir}/jarjar-asm.rules")
918
      .withWriter("utf-8") { writer ->
919
        writer.writeLine("rule org.objectweb.** com.saxonica.objectweb.@1")
920
      }
921
  }
922
  doFirst {
923
    mkdir "${buildDir}"
924
  }
925
}
926

    
927
task asm_jarjar(
928
  description: "Placeholder for the ASM jarjar dependencies"
929
) {
930
  // just a task to hang dependencies on
931
}
932

    
933
task asm_unzip(
934
  type: Copy,
935
  description: "Extract classes from the asm-xml-${asmVersion} jar"
936
) {
937
  // This one is from the original ASM
938
  def zipFile = file("lib/asm-${asmVersion}/asm-xml-${asmVersion}.jar")
939
  def outputDir = "${buildDir}/classes/eej"
940
  from zipTree(zipFile)
941
  into outputDir
942
}
943

    
944
["asm", "asm-analysis", "asm-commons", "asm-tree", "asm-util"].each { asm ->
945
  Task t = task "asm_${asm}"(
946
    type: JavaExec,
947
    dependsOn: ["asm_createRules"],
948
    description: "Run jarjar on ${asm}-${asmVersion} classes"
949
) {
950
    inputs.file "lib/asm-${asmVersion}/${asm}-${asmVersion}.jar"
951
    outputs.file "${buildDir}/lib/asm/${asm}-${asmVersion}.jar"
952
    classpath = configurations.preprocessor
953
    main = "com.tonicsystems.jarjar.Main"
954
    args "--rules", "${buildDir}/jarjar-asm.rules",
955
      "lib/asm-${asmVersion}/${asm}-${asmVersion}.jar",
956
      "${buildDir}/lib/asm/${asm}-${asmVersion}.jar"
957
    doFirst {
958
      mkdir "${buildDir}/lib/asm"
959
    }
960
  }
961
  asm_jarjar.dependsOn t
962

    
963
  t = task "asm_unzip${asm}"(
964
    type: Copy,
965
    dependsOn: ["asm_jarjar"],
966
    description: "Extract the classes from the ${asm}-${asmVersion} jar"
967
  ) {
968
    def zipFile = file("${buildDir}/lib/asm/${asm}-${asmVersion}.jar")
969
    def outputDir = "${buildDir}/classes/eej"
970
    from zipTree(zipFile)
971
    into outputDir
972
  }
973
  asm_unzip.dependsOn t
974
}
975

    
976
// ============================================================
977

    
978
task hej_MetaInf(
979
  description: "Create META-INF/services/javax.xml.transform.TransformerFactory for HE"
980
) {
981
  outputs.file("${buildDir}/services/saxon-he/META-INF/services/javax.xml.transform.TransformerFactory")
982
  doFirst {
983
    mkdir "${buildDir}/services/saxon-he/META-INF/services"
984
  }
985
  doLast {
986
    new File("${buildDir}/services/saxon-he/META-INF/services/javax.xml.transform.TransformerFactory")
987
      .withWriter("utf-8") { writer ->
988
        writer.writeLine("net.sf.saxon.TransformerFactoryImpl")
989
      }
990
  }
991
}
992

    
993
task pej_MetaInf(
994
  description: "Create META-INF/services/javax.xml.transform.TransformerFactory for PE"
995
) {
996
  outputs.file("${buildDir}/services/saxon-pe/META-INF/services/javax.xml.transform.TransformerFactory")
997
  doFirst {
998
    mkdir "${buildDir}/services/saxon-pe/META-INF/services"
999
  }
1000
  doLast {
1001
    new File("${buildDir}/services/saxon-pe/META-INF/services/javax.xml.transform.TransformerFactory")
1002
      .withWriter("utf-8") { writer ->
1003
        writer.writeLine("com.saxonica.config.ProfessionalTransformerFactory")
1004
      }
1005
  }
1006
}
1007

    
1008
task eej_schemaFactoryMetaInf(
1009
  description: "Create META-INF/services/javax.xml.validation.SchemaFactory for EE"
1010
) {
1011
  outputs.file("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.validation.SchemaFactory")
1012
  doFirst {
1013
    mkdir "${buildDir}/services/saxon-ee/META-INF/services"
1014
  }
1015
  doLast {
1016
    new File("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.validation.SchemaFactory")
1017
      .withWriter("utf-8") { writer ->
1018
        writer.writeLine("com.saxonica.ee.jaxp.SchemaFactoryImpl")
1019
      }
1020
  }
1021
}
1022

    
1023
task eej_MetaInf(
1024
  dependsOn: ["eej_schemaFactoryMetaInf"],
1025
  description: "Create META-INF/services/javax.xml.transform.TransformerFactory for EE"
1026
) {
1027
  outputs.file("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.transform.TransformerFactory")
1028
  doFirst {
1029
    mkdir "${buildDir}/services/saxon-ee/META-INF/services"
1030
  }
1031
  doLast {
1032
    new File("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.transform.TransformerFactory")
1033
      .withWriter("utf-8") { writer ->
1034
        writer.writeLine("com.saxonica.config.EnterpriseTransformerFactory")
1035
      }
1036
  }
1037
}
1038

    
1039
// ============================================================
1040

    
1041
task hejJar(
1042
  type: Jar,
1043
  dependsOn: ["hej_MetaInf", "hejCompile"],
1044
  description: "Build the HE jar file"
1045
) {
1046
  archiveBaseName = "saxon-he-${saxonVersion}"
1047
  manifest {
1048
    attributes "Project-Name": "Saxon-HE"
1049
    attributes "Main-Class": "net.sf.saxon.Transform"
1050
  }
1051
  from ("${buildDir}/services/saxon-he") {
1052
    include "META-INF/**"
1053
  }
1054
  from ("${buildDir}/classes/hej") {
1055
    include "net/**/*.class"
1056
    exclude "net/sf/saxon/option/**"
1057
  }
1058
  from ("src/main/resources") {
1059
    include "net/sf/saxon/data/**"
1060
  }
1061
}
1062

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

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

    
1126
task pejJarSql(
1127
  type: Jar,
1128
  dependsOn: ["pejCompile"],
1129
  description: "Build the SQL jar file for PE"
1130
) {
1131
  archiveBaseName = "saxon-pe-sql-${saxonVersion}"
1132
  from ("${buildDir}/classes/pej") {
1133
    include "net/sf/saxon/option/sql/*.class"
1134
    include "com/saxonica/functions/sql/*.class"
1135
  }
1136
}
1137

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

    
1166
task eejJarSql(
1167
  type: Jar,
1168
  dependsOn: ["eejCompile"],
1169
  description: "Build the SQL jar file for EE"
1170
) {
1171
  archiveBaseName = "saxon-ee-sql-${saxonVersion}"
1172
  from ("${buildDir}/classes/eej") {
1173
    include "net/sf/saxon/option/sql/*.class"
1174
    include "com/saxonica/functions/sql/*.class"
1175
  }
1176
}
1177

    
1178
// ============================================================
1179

    
1180
task signJars(
1181
  dependsOn: ["hejSignJars", "pejSignJars", "eejSignJars"],
1182
  description: "Sign all the jar files."
1183
) {
1184
  // Just a container to hang dependencies on
1185
}
1186

    
1187
task hejSignJars(
1188
  description: "Sign the HEJ jar files"
1189
) {
1190
  // Just a container to hang dependencies on
1191
}
1192

    
1193
task pejSignJars(
1194
  description: "Sign the PEJ jar files"
1195
) {
1196
  // Just a container to hang dependencies on
1197
}
1198

    
1199
task eejSignJars(
1200
  description: "Sign the EEJ jar files"
1201
) {
1202
  // Just a container to hang dependencies on
1203
}
1204

    
1205
// Create tasks for signing jars...
1206
["he", "pe", "ee"].each { rel ->
1207
  if (canSignJars) {
1208
    Task t = task "${rel}_jJarSignJar"(
1209
      type: Exec,
1210
      dependsOn: ["${rel}jJar"],
1211
      description: "Sign the ${rel.toUpperCase()}J jar file"
1212
    ) {
1213
      inputs.file "${buildDir}/libs/saxon-${rel}-${saxonVersion}.jar"
1214
      def args = signjarArgs +
1215
        ["${buildDir}/libs/saxon-${rel}-${saxonVersion}.jar",
1216
         signkeyNewAlias,
1217
         "-storepass", signkeyPassword]
1218
      commandLine args
1219
    }
1220
    tasks.findByName("${rel}jSignJars").dependsOn t
1221

    
1222
    t = task "${rel}j_JarSignTests"(
1223
      type: Exec,
1224
      dependsOn: ["${rel}jJarTests"],
1225
      description: "Sign the ${rel.toUpperCase()}J test jar file"
1226
    ) {
1227
      inputs.file "${buildDir}/libs/saxon-${rel}-test-${saxonVersion}.jar"
1228
      def args = signjarArgs +
1229
        ["${buildDir}/libs/saxon-${rel}-test-${saxonVersion}.jar",
1230
         signkeyNewAlias,
1231
         "-storepass", signkeyPassword]
1232
      commandLine args
1233
    }
1234
    tasks.findByName("${rel}jSignJars").dependsOn t
1235

    
1236
    t = task "${rel}j_JarSignXqj"(
1237
      type: Exec,
1238
      dependsOn: ["${rel}jJarXqj"],
1239
      description: "Sign the ${rel.toUpperCase()}J XQJ jar file"
1240
    ) {
1241
      inputs.file "${buildDir}/libs/saxon-${rel}-xqj-${saxonVersion}.jar"
1242
      def args = signjarArgs +
1243
        ["${buildDir}/libs/saxon-${rel}-xqj-${saxonVersion}.jar",
1244
         signkeyNewAlias,
1245
         "-storepass", signkeyPassword]
1246
      commandLine args
1247
    }
1248
    tasks.findByName("${rel}jSignJars").dependsOn t
1249

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

    
1275
    t = task "${rel}j_JarSignTests"(
1276
      description: "Cannot sign the ${rel.toUpperCase()}J test 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_JarSignXqj"(
1285
      description: "Cannot sign the ${rel.toUpperCase()}J XQJ 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
    if (rel != 'he') {
1294
      t = task "${rel}j_JarSignSql"(
1295
        description: "Cannot sign the ${rel.toUpperCase()} jar file"
1296
      ) {
1297
        doLast {
1298
          throw new GradleException("Jar signing is not configured.")
1299
        }
1300
      }
1301
      tasks.findByName("${rel}jSignJars").dependsOn t
1302
    }
1303
  }    
1304
}
1305

    
1306
// ============================================================
1307

    
1308
task hej_releaseSetup(
1309
  type: Copy,
1310
  dependsOn: ["hejJar", "hejJarXqj", "hejJarTests", "hej_notices"],
1311
  description: "Build the HE release for Java"
1312
) {
1313
  from "${buildDir}/libs"
1314
  into "${buildDir}/releases/hej"
1315
  include "saxon-he-${saxonVersion}.jar"
1316
  include "saxon-he-xqj-${saxonVersion}.jar"
1317
  include "saxon-he-test-${saxonVersion}.jar"
1318
  rename { filename ->
1319
    if (filename.startsWith("saxon-he-xqj")) {
1320
      filename = "saxon9-xqj.jar"
1321
    } else if (filename.startsWith("saxon-he-test")) {
1322
      filename = "saxon9-test.jar"
1323
    } else {
1324
      filename = "saxon9he.jar"
1325
    }
1326
  }
1327
}
1328

    
1329
task hejRelease(
1330
  type: Zip,
1331
  dependsOn: ["hej_releaseSetup"],
1332
  description: "Make the HE release ZIP file for Java"
1333
) {
1334
  from("${buildDir}/releases/hej")
1335
  archiveFileName = "SaxonHE${version_h}J.zip"
1336
}
1337

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

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

    
1376
task javaReleases(
1377
  dependsOn: ["hejRelease", "pejRelease", "eejRelease"],
1378
  description: "Build all of the Java releases"
1379
) {
1380
  // Just a container to hang dependencies on
1381
}
1382

    
1383
// ============================================================
1384

    
1385
task dockerCoreContainer(
1386
  type: Exec,
1387
  description: "Build the CentOS 8 core container"
1388
) {
1389
  inputs.files("${projectDir}/src/docker/centos8-core")
1390
  commandLine "docker", "build",
1391
    "-t", "${dockerCentos8Core}",
1392
    "${projectDir}/src/docker/centos8-core"
1393
}
1394

    
1395
// In order to build this container, you must specify the location
1396
// of the JDK and the Jet software archive. Use
1397
// -PdockerJdk= to specify the location of the JDK RPM. Use
1398
// -PdockerJet= to specify the location of the Jet archive.
1399
task dockerBuilderContainer(
1400
  type: Exec,
1401
  dependsOn: ["docker_setupBuilder", "dockerCoreContainer"],
1402
  description: "Build the Saxonica builder container"
1403
) {
1404
  inputs.files("${buildDir}/docker/builder")
1405
  commandLine "docker", "build",
1406
    "-t", "${dockerBuildContainer}",
1407
    "${buildDir}/docker/builder"
1408
}
1409

    
1410
task docker_setupBuilder(
1411
  type: Copy,
1412
  dependsOn: ["docker_setupJdk", "docker_setupJet"],
1413
  description: "Setup to build the builder container"
1414
) {
1415
  from "src/docker/builder"
1416
  into "${buildDir}/docker/builder"
1417
}
1418

    
1419
task docker_testJdk(
1420
  description: "Test that the dockerJdk property has been specified"
1421
) {
1422
  doLast {
1423
    if (dockerJdk == "none") {
1424
      throw new GradleException("You must specify the JDK with -PdockerJdk=...")
1425
    }
1426
  }
1427
}
1428

    
1429
task docker_setupJdk(
1430
  type: Copy,
1431
  dependsOn: ["docker_testJdk"],
1432
  description: "Setup the JDK for the builder container"
1433
) {
1434
  from dockerJdk
1435
  into "${buildDir}/docker/builder"
1436
}
1437

    
1438
task docker_testJet(
1439
  description: "Test that the dockerJet property has been specified"
1440
) {
1441
  doLast {
1442
    if (dockerJet == "none") {
1443
      throw new GradleException("You must specify Jet archive with -PdockerJet=...")
1444
    }
1445
  }
1446
}
1447

    
1448
task docker_setupJet(
1449
  type: Copy,
1450
  dependsOn: ["docker_testJet"],
1451
  description: "Setup the Jet archive for the builder container"
1452
) {
1453
  from dockerJet
1454
  into "${buildDir}/docker/builder"
1455
}
1456

    
1457
// ============================================================
1458

    
1459
compileTestDrivers.dependsOn "${saxonEdition}j_compileTestDrivers"
1460
runQT3TestDriver.dependsOn "${saxonEdition}j_runQT3TestDriver"
1461
runXslt30TestSuiteDriver.dependsOn "${saxonEdition}j_runXslt30TestSuiteDriver"
1462

    
1463
// ============================================================
1464

    
1465
// Testing task for various Gradle debugging efforts
1466
task helloWorld() {
1467
  doLast {
1468
    println("Hello, world.")
1469
  }
1470
}
(7-7/12)