Project

Profile

Help

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

he / build.gradle @ 00082f6f

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", "rev-parse", "--abbrev-ref", "HEAD"
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
    include "com/saxonica/js/**"
523
  }
524
}
525

    
526
// ============================================================
527

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

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

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

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

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

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

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

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

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

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

    
696
// ============================================================
697

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

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

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

    
753
// ============================================================
754

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

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

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

    
793
// ============================================================
794

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

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

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

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

    
842
// ============================================================
843

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

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

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

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

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

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

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

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

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

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

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

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

    
984
// ============================================================
985

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

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

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

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

    
1047
// ============================================================
1048

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

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

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

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

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

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

    
1186
// ============================================================
1187

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

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

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

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

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

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

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

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

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

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

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

    
1314
// ============================================================
1315

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

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

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

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

    
1388
// ============================================================
1389

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

    
1394
// ============================================================
1395

    
1396
// Testing task for various Gradle debugging efforts
1397
task helloWorld() {
1398
  doLast {
1399
    println("Hello, world.")
1400
  }
1401
}
(8-8/13)