Project

Profile

Help

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

he / build.gradle @ 2699858e

1
buildscript {
2
  repositories {
3
    mavenLocal()
4
    mavenCentral()
5
  }
6
}
7

    
8
plugins {
9
  id "java"
10
  id "maven-publish"
11
  id "signing"
12
//  id "com.cdsap.talaiot" version "1.3.5"
13
}
14

    
15
import org.gradle.internal.os.OperatingSystem;
16

    
17
apply plugin: 'java'
18

    
19
repositories {
20
  mavenLocal()
21
  mavenCentral()
22
  maven { url = "https://org.apache.maven" }
23
  maven { url "https://dev.saxonica.com/maven" }
24
}
25

    
26
configurations.all {
27
  resolutionStrategy {
28
    force 'xml-apis:xml-apis:1.4.01'
29
  }
30
}
31

    
32
configurations {
33
  preprocessor.extendsFrom(runtimeOnly)
34
  jarjarAsm.extendsFrom(implementation)
35
  testDrivers.extendsFrom(testImplementation)
36
  ikvm.extendsFrom(implementation)
37
  compileDotNet.extendsFrom(implementation)
38
  asmDotNet.extendsFrom(implementation)
39
}
40

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

    
51
dependencies {
52
  preprocessor (
53
    [group: 'com.igormaznitsa', name: 'jcp', version: '7.0.4'],
54
    [group: 'com.tonicsystems', name: 'jarjar', version: '0.6' ],
55
    [group: 'com.saxonica', name: 'Saxon-EE', version: '10.3' ],
56
    files(saxonLicenseDir)
57
  )
58
  implementation (
59
    [group: 'org.apache.ws.commons.axiom', name: 'axiom-dom', version: '1.2.15'],
60
    [group: 'xom', name: 'xom', version: '1.3.5'],
61
    [group: 'org.jdom', name: 'jdom', version: '1.1.3'],
62
    [group: 'org.jdom', name: 'jdom2', version: '2.0.6'],
63
    [group: 'org.lucee', name: 'dom4j', version: '1.6.1'],
64
    [group: 'xml-resolver', name: 'xml-resolver', version: '1.2' ],
65
    [group: 'com.ibm.icu', name: 'icu4j', version: icu4jVersion ],
66
    [group: 'jline', name: 'jline', version: '2.14.6' ],
67
    [group: 'org.jetbrains', name: 'annotations', version: '20.1.0' ],
68
    // PE and EE
69
    [group: 'javax.mail', name: 'javax.mail-api', version: mailVersion ],
70
    [group: 'com.sun.mail', name: 'javax.mail', version: mailVersion ],
71
    [group: 'org.ccil.cowan.tagsoup', name: 'tagsoup', version: tagsoupVersion],
72
  )
73
  jarjarAsm (
74
    fileTree(dir: "${buildDir}/lib/asm")
75
  )
76
  ikvm (
77
    fileTree(dir: "${ikvmDir}/stubs")
78
  )
79
  compileDotNet (
80
    fileTree(dir: "${ikvmDir}/stubs"),
81
    fileTree(dir: "${ikvmDir}/classpath")
82
  )
83
  asmDotNet (
84
    fileTree(dir: "${ikvmDir}/stubs"),
85
    fileTree(dir: "${ikvmDir}/classpath"),
86
    fileTree(dir: "lib/asm-${asmVersion}")
87
  )
88
  testImplementation (
89
    [group: 'junit', name: 'junit', version: '4.12'],
90
    [group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.4.2'],
91
    [group: 'org.apache.ant', name: 'ant', version: '1.10.9' ],
92
    files("${buildDir}/classes/eej"),
93
    files("lib/Tidy.jar")
94
  )
95
  testRuntimeOnly (
96
    [group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.4.2'],
97
    [group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.4.2'],
98
    [group: 'org.apache.ant', name: 'ant', version: '1.10.9' ],
99
    files("${buildDir}/classes/eej")
100
  )
101
}
102

    
103
sourceSets {
104
  main {
105
    java {
106
      exclude "**/*.java"
107
    }
108
  }
109
}
110

    
111
test {
112
  useJUnitPlatform()
113
}
114

    
115
/*
116
talaiot {
117
  metrics {
118
    performanceMetrics = false
119
  }
120
  publishers {
121
    taskDependencyGraphPublisher {
122
      gexf = false
123
      dot = true
124
      html = false
125
    }
126
  }
127
}
128
*/
129

    
130
ext {
131
  systemOs = OperatingSystem.current()
132
  icu4jJar = null
133
  tagsoupJar = null
134
  mailJar = null
135
  resolverJar = null
136
}
137

    
138
def version_h = saxonVersion.replace(".", "-")
139

    
140
// ============================================================
141
// Find jar files that need to be part of the build or release
142
//
143
def filesep = System.getProperty("file.separator")
144
icu4jJar = "${filesep}icu4j-${icu4jVersion}.jar"
145
tagsoupJar = "${filesep}tagsoup-${tagsoupVersion}.jar"
146
mailJar = "${filesep}javax.mail-${mailVersion}.jar"
147
resolverJar = "${filesep}xml-resolver-1.2.jar"
148
configurations.compileClasspath.each { cp ->
149
  if (cp.toString().endsWith(icu4jJar)) {
150
    icu4jJar = cp.toString()
151
  }
152
  if (cp.toString().endsWith(tagsoupJar)) {
153
    tagsoupJar = cp.toString()
154
  }
155
  if (cp.toString().endsWith(mailJar)) {
156
    mailJar = cp.toString()
157
  }
158
  if (cp.toString().endsWith(resolverJar)) {
159
    resolverJar = cp.toString()
160
  }
161
}
162

    
163
apply from: "build-n.gradle"
164
apply from: "build-c.gradle"
165
apply from: "build-doc.gradle"
166

    
167
def pathExists(pathname) {
168
  // Returns true iff pathame is an existing file or directory
169
  try {
170
    // This may throw an error for a Windows pathname, c:/path/to/thing
171
    if (file(pathname).exists()) {
172
      return true;
173
    }
174
  } catch (GradleException e) {
175
    // I don't care
176
  }
177

    
178
  if (OperatingSystem.current().isWindows()) {
179
    try {
180
      // If we're on Windows, try to make c:/path/to/thing work
181
      if (file("file:///${pathname}").exists()) {
182
        return true;
183
      }
184
    } catch (GradleException e) {
185
      // I don't care
186
    }
187
  }
188

    
189
  return false
190
}
191

    
192
// ============================================================
193
// One of the features of Gradle is that you can construct tasks
194
// dynamically during the "configure" phase. This is a feature because
195
// it avoids a lot of tedious repetition of nearly identical tasks. It
196
// has the unfortunate consequence that understanding the tasks
197
// involved becomes harder. I've tried to use this feature sparingly.
198

    
199
["h", "p", "e"].each { initial ->
200
  def release = initial + "e"
201
  def Release = initial.toUpperCase() + "e"
202
  def RELEASE = release.toUpperCase()
203

    
204
  if (release != "he") {
205
    Task libs = task "${release}j_libs"(
206
      description: "Dependency to make sure library files are copie for ${RELEASE}"
207
    ) {
208
      // Just a container to hang dependencies on
209
    }
210

    
211
    Task icu4j = task "${release}j_icu4j"(
212
      type: Copy,
213
      description: "Copy the ICU4J jar into the ${RELEASE} release directory"
214
    ) {
215
      from "${icu4jJar}"
216
      into "${buildDir}/releases/${release}j"
217
    }
218
    libs.dependsOn icu4j
219
  }
220

    
221
  task "${release}j_notices"(
222
    type: Copy,
223
    description: "Copy the notices into the ${RELEASE} release directory"
224
  ) {
225
    into "${buildDir}/releases/${release}j"
226
    from ("src/docs") {
227
      exclude "saxon9"
228
      exclude "tools"
229
      exclude "saxonc-doc"
230
      exclude "welcome"
231
      exclude "notices/APACHE-ANT.txt"
232
      exclude "notices/APACHE-RESOLVER.txt"
233
      exclude "notices/APACHE-TAGSOUP.txt"
234
      exclude "notices/APACHE-XERCES.txt"
235
      exclude "notices/ASM.txt"
236
      exclude "notices/FRIJTERS.txt"
237
      exclude "notices/GPL+CLASSPATH.txt"
238
      exclude "notices/ICU-J.txt"
239
      exclude "notices/LEGAL.txt"
240
    }
241
  }
242

    
243
  task "${release}j_copyTestDrivers"(
244
    dependsOn: ["${release}j_copyTestDriverSources",
245
                "${release}j_copyTestDriverResources"],
246
    description: "Copy test driver sources and resources for ${RELEASE}"
247
  ) {
248
    // Just a container to hang dependencies on
249
  }
250
}
251

    
252
// ============================================================
253

    
254
task "hej_compileTestDrivers"(
255
  type: JavaCompile,
256
  dependsOn: ["hej_copyTestDrivers", "hejCompile"],
257
  description: "Compile the test classes for HE"
258
) {
259
  classpath = configurations.testDrivers + files("${buildDir}/classes/hej")
260
  source = "${buildDir}/src/testdrivers/hej"
261
  destinationDirectory = new File("${buildDir}/classes/hej/testdrivers")
262
}
263

    
264
task "pej_compileTestDrivers"(
265
  type: JavaCompile,
266
  dependsOn: ["pej_copyTestDrivers", "pejCompile", "eejCompile"],
267
  description: "Compile the test classes for PE"
268
) {
269
  classpath = configurations.testDrivers \
270
              + files("${buildDir}/classes/pej") \
271
              + files("${buildDir}/classes/eej")
272
  source = "${buildDir}/src/testdrivers/pej"
273
  destinationDirectory = new File("${buildDir}/classes/pej/testdrivers")
274
}
275

    
276
task "eej_compileTestDrivers"(
277
  type: JavaCompile,
278
  dependsOn: ["eej_copyTestDrivers", "eejCompile", "eejCompile"],
279
  description: "Compile the test classes for EE"
280
) {
281
  classpath = configurations.testDrivers \
282
              + files("${buildDir}/classes/eej")
283
  source = "${buildDir}/src/testdrivers/eej"
284
  destinationDirectory = new File("${buildDir}/classes/eej/testdrivers")
285
}
286

    
287
task hejJarTests(
288
  type: Jar,
289
  dependsOn: ["hejCompile", "hej_compileTestDrivers"],
290
  description: "Create the tests jar file for HE"
291
) {
292
  archiveBaseName = "saxon-he-test-${saxonVersion}"
293
  manifest {
294
    attributes "Project-Name": "Saxon-HE-TestDriver"
295
    attributes "Main-Class": "com.saxonica.testdriver.gui.TestDriverGui"
296
  }
297
  from ("${buildDir}/classes/hej/testdrivers") {
298
    include "net/sf/saxon/testdriver/**"
299
  }
300
}
301

    
302
task pejJarTests(
303
  type: Jar,
304
  dependsOn: ["pejCompile", "pej_compileTestDrivers"],
305
  description: "Create the tests jar file for PE"
306
) {
307
  archiveBaseName = "saxon-pe-test-${saxonVersion}"
308
  manifest {
309
    attributes "Project-Name": "Saxon-PE-TestDriver"
310
    attributes "Main-Class": "com.saxonica.testdriver.gui.TestDriverGui"
311
  }
312
  from ("${buildDir}/classes/pej/testdrivers") {
313
    include "net/sf/saxon/testdriver/**"
314
    include "com/saxonica/testdriver/**"
315
    exclude "com/saxonica/testdriver/ee/**"
316
  }
317
}
318

    
319
task eejJarTests(
320
  type: Jar,
321
  dependsOn: ["eejCompile", "eej_compileTestDrivers"],
322
  description: "Create the tests jar file for EE"
323
) {
324
  archiveBaseName = "saxon-ee-test-${saxonVersion}"
325
  manifest {
326
    attributes "Project-Name": "Saxon-EE-TestDriver"
327
    attributes "Main-Class": "com.saxonica.testdriver.gui.TestDriverGui"
328
  }
329
  from ("${buildDir}/classes/eej/testdrivers") {
330
    include "net/sf/saxon/testdriver/**"
331
    include "com/saxonica/testdriver/**"
332
  }
333
}
334

    
335
// ============================================================
336

    
337
task hej_sampleConfig(
338
  type: JavaExec,
339
  description: "Construct the configuration file XSD"
340
) {
341
  inputs.files fileTree(dir: "${projectDir}/tools/featureKeys")
342
  inputs.files "${projectDir}/src/samples/config/config-raw.xsd"
343
  outputs.file "${projectDir}/src/samples/config/config.xsd"
344
  classpath = configurations.preprocessor
345
  main = "net.sf.saxon.Transform"
346
  args "${projectDir}/tools/featureKeys/FeatureKeys.xml",
347
    "-xsl:${projectDir}/tools/featureKeys/FeatureKeysToSchema.xsl",
348
    "-o:${projectDir}/src/samples/config/config.xsd",
349
    "FeatureKeys=FeatureKeys.xml",
350
    "AdditionalFeatures=AdditionalFeatures.xml",
351
    "ConfigSchema=${projectDir}/src/samples/config/config-raw.xsd"
352
}
353

    
354
// There's no real dependency here, but I'm not sure how the
355
// samples directory should be integrated into the build.
356
task hej_featureKeys(
357
  type: JavaExec,
358
  dependsOn: ["hej_sampleConfig"],
359
  description: "Construct the feature keys for HE"
360
) {
361
  inputs.files fileTree(dir: "${projectDir}/tools/featureKeys")
362
  outputs.file "${projectDir}/src/main/java/net/sf/saxon/lib/Feature.java"
363
  outputs.file "${projectDir}/src/main/java/net/sf/saxon/lib/FeatureCode.java"
364
  outputs.file "${projectDir}/src/main/java/net/sf/saxon/lib/FeatureKeys.java"
365
  classpath = configurations.preprocessor
366
  main = "net.sf.saxon.Transform"
367
  args "${projectDir}/tools/featureKeys/FeatureKeys.xml",
368
    "-xsl:${projectDir}/tools/featureKeys/FeatureKeysToJava.xsl",
369
    "-o:${projectDir}/src/main/java/net/sf/saxon/lib/establish-an-output-base-uri"
370
}
371

    
372
task hej_setupPreprocess(
373
  type: Copy,
374
  dependsOn: ["hej_featureKeys"],
375
  description: "Copy HE sources for preprocessing HE"
376
) {
377
  from "${projectDir}/src/main/java"
378
  into "${buildDir}/filtered/hej"
379
  include "net/sf/saxon/**/*.java"
380
  include "net/sf/saxon/**/package.html"
381
  include "net/sf/saxon/data/**"
382
  exclude "javax/xml/xquery/*.java"
383
  exclude "**/dotnet/**"
384
  exclude "net/sf/saxon/testdriver/**"
385
  exclude "net/sf/saxon/option/sql/**"
386
  exclude "net/sf/saxon/option/cpp/**"
387
  exclude "net/sf/saxon/jetonnet/**"
388
}
389

    
390
task hej_setupPreprocessForPej(
391
  type: Copy,
392
  description: "Copy HE sources for preprocessing PE"
393
) {
394
  from "${projectDir}/src/main/java"
395
  into "${buildDir}/filtered/pej"
396
  include "net/sf/saxon/**/*.java"
397
  include "javax/xml/xquery/*.java"
398
  exclude "**/dotnet/**"
399
  include "net/sf/saxon/**/package.html"
400
  exclude "net/sf/saxon/testdriver/**"
401
  exclude "net/sf/saxon/option/cpp/**"
402
  exclude "net/sf/saxon/jetonnet/**"
403
  include "net/sf/saxon/data/**"
404
}
405

    
406
task eej_setupPreprocessForPej(
407
  type: Copy,
408
  description: "Copy EE sources for preprocessing PE"
409
) {
410
  from "${projectDir}/src/main/java"
411
  into "${buildDir}/filtered/pej"
412
  include "com/saxonica/**/*.java"
413
  exclude "com/saxonica/functions/extfn/cpp/*.java"
414
  exclude "com/saxonica/testdriver/**"
415
  exclude "com/saxonica/testdriver/ee/**/*.java"
416
  exclude "com/saxonica/testdriver/old/**/*.java"
417
  exclude "com/saxonica/ee/**"
418
  exclude "com/saxonica/config/EnterpriseConfiguration.java"
419
  exclude "com/saxonica/expr/CastToUnion.java"
420
  exclude "com/saxonica/expr/CastableToUnion.java"
421
  exclude "com/saxonica/expr/DotNetExtensionFunctionCall.java"
422
  exclude "com/saxonica/config/ee/**"
423
  exclude "com/saxonica/js/**"
424
  exclude "com/saxonica/config/DotNetExtensionLibrary.java"
425
  exclude "com/saxonica/config/DotNetExtensionFunctionFactory.java"
426
  exclude "com/saxonica/config/DotNetPlatformPE.java"
427
  exclude "com/saxonica/config/JavaPlatformEE.java"
428
  exclude "com/saxonica/config/NativePlatformPE.java"
429
  exclude "com/saxonica/Validate.java"
430
  exclude "com/saxonica/config/EnterpriseTransformerFactory.java"
431
  exclude "com/saxonica/config/StreamingTransformerFactory.java"
432
  exclude "com/saxonica/config/EnterpriseXPathFactory.java"
433
  exclude "com/saxonica/config/DynamicLoaderEE.java"
434
  exclude "com/saxonica/config/StandardSchemaResolver.java"
435
  exclude "com/saxonica/jaxp/SchemaFactoryImpl11.java"
436
  exclude "com/saxonica/functions/extfn/NativeCall.java"
437
}
438

    
439
task pej_setupPreprocess(
440
  dependsOn: ["hej_setupPreprocessForPej", "eej_setupPreprocessForPej"],
441
  description: "Copy sources for preprocessing PE"
442
) {
443
  // Just a container to hang dependencies on
444
}
445

    
446
task hej_setupPreprocessForEej(
447
  type: Copy,
448
  description: "Copy HE sources for EE build"
449
) {
450
  from "${projectDir}/src/main/java"
451
  into "${buildDir}/filtered/eej"
452
  include "net/sf/saxon/**/*.java"
453
  include "javax/xml/xquery/*.java"
454
  exclude "**/dotnet/**"
455
  include "net/sf/saxon/**/package.html"
456
  exclude "net/sf/saxon/testdriver/**"
457
  exclude "net/sf/saxon/option/cpp/**"
458
  exclude "net/sf/saxon/jetonnet/**"
459
  exclude "net/sf/saxon/jetonnet/**"
460
  include "net/sf/saxon/data/**"
461
}
462

    
463
// Rename org.objectweb to com.saxonica.objectweb in the bytecode sources
464
task eej_setupPreprocessBytecode(
465
  type: Copy,
466
  description: "Copy bytecode sources and fix imports"
467
) {
468
  from "${projectDir}/src/main/java"
469
  into "${buildDir}/filtered/eej"
470
  include "com/saxonica/ee/bytecode/**/*.java"
471
  filter { line ->
472
    line.contains("org.objectweb")
473
      ? line.replaceAll("org.objectweb", "com.saxonica.objectweb")
474
      : line
475
  }
476
}
477

    
478
// N.B. bytecode is explicitly excluded, see eej_setupPreprocessBytecode
479
task eej_setupPreprocess(
480
  type: Copy,
481
  dependsOn: ["hej_setupPreprocessForEej", "eej_setupPreprocessBytecode"],
482
  description: "Copy sources for preprocessing EE"
483
) {
484
  from "${projectDir}/src/main/java"
485
  into "${buildDir}/filtered/eej"
486
  include "com/saxonica/**/*.java"
487
  exclude "com/saxonica/ee/bytecode/**/*.java"
488
  exclude "com/saxonica/functions/extfn/cpp/*.java"
489
  exclude "com/saxonica/testdriver/**/*.java"
490
  exclude "com/saxonica/config/DotNetExtensionFunctionFactory.java"
491
  exclude "com/saxonica/config/DotNetExtensionLibrary.java"
492
  exclude "com/saxonica/config/DotNetPlatformPE.java"
493
  exclude "com/saxonica/config/NativePlatformPE.java"
494
  exclude "com/saxonica/expr/DotNetExtensionFunctionCall.java"
495
  exclude "com/saxonica/functions/extfn/NativeCall.java"
496
  include "com/saxonica/**/package.html"
497
  exclude "com/saxonica/js/**"
498
}
499

    
500
// ============================================================
501

    
502
task hej_preprocess(
503
  type: JavaExec,
504
  dependsOn: ["hej_setupPreprocess"],
505
  description: "Preprocess HE sources"
506
) {
507
  inputs.files fileTree(dir: "${buildDir}/filtered/hej")
508
  outputs.files fileTree(dir: "${buildDir}/preprocess/hej")
509
  classpath = configurations.preprocessor
510
  main = "com.igormaznitsa.jcp.JcpPreprocessor"
511
  args "/c",
512
    "/i:${buildDir}/filtered/hej", "/o:${buildDir}/preprocess/hej",
513
    "/p:EE=false", "/p:PE=false", "/p:DOTNET=false",
514
    "/p:OPT=false", "/p:SAXONC=false", "/p:BYTECODE=false"
515
  doFirst {
516
    mkdir "${buildDir}/preprocess/hej"
517
  }
518
}
519

    
520
task pej_preprocess(
521
  type: JavaExec,
522
  dependsOn: ["pej_setupPreprocess"],
523
  description: "Preprocess HE sources"
524
) {
525
  inputs.files fileTree(dir: "${buildDir}/filtered/pej")
526
  outputs.files fileTree(dir: "${buildDir}/preprocess/pej")
527
  classpath = configurations.preprocessor
528
  main = "com.igormaznitsa.jcp.JcpPreprocessor"
529
  args "/c",
530
    "/i:${buildDir}/filtered/pej", "/o:${buildDir}/preprocess/pej",
531
    "/p:EE=false", "/p:PE=true", "/p:DOTNET=false", "/p:HOF=true",
532
    "/p:OPT=false", "/p:SAXONC=false", "/p:BYTECODE=false"
533
  doFirst {
534
    mkdir "${buildDir}/preprocess/pej"
535
  }
536
}
537

    
538
task eej_preprocess(
539
  type: JavaExec,
540
  dependsOn: ["eej_setupPreprocess", "asm_jarjar"],
541
  description: "Preprocess EE sources"
542
) {
543
  inputs.files fileTree(dir: "${buildDir}/filtered/eej")
544
  outputs.files fileTree(dir: "${buildDir}/preprocess/eej")
545
  classpath = configurations.preprocessor
546
  main = "com.igormaznitsa.jcp.JcpPreprocessor"
547
  args "/c",
548
    "/i:${buildDir}/filtered/eej", "/o:${buildDir}/preprocess/eej",
549
    "/p:EE=true", "/p:PE=false", "/p:DOTNET=false", "/p:HOF=true",
550
    "/p:OPT=false", "/p:SAXONC=false", "/p:BYTECODE=true",
551
    "/p:STREAM=true", "/p:PACKAGES=true", "/p:SCHEMA=true"
552
  doFirst {
553
    mkdir "${buildDir}/preprocess/eej"
554
  }
555
}
556

    
557
// ============================================================
558

    
559
task hej_sources(
560
  type: Copy,
561
  dependsOn: ["hej_preprocess"],
562
  description: "Collect the preprocessed HE sources for compilation"
563
) {
564
  from "${buildDir}/preprocess/hej"
565
  into "${buildDir}/src/hej"
566
  filter { line ->
567
    line.contains("import com.saxonica") ? null : line.replaceFirst("\\s++\$", "")
568
  }
569
}
570

    
571
task pej_sources(
572
  type: Copy,
573
  dependsOn: ["pej_preprocess"],
574
  description: "Collect the preprocessed PE sources for compilation"
575
) {
576
  from "${buildDir}/preprocess/pej"
577
  into "${buildDir}/src/pej"
578
  filter { line ->
579
    if (line.contains("import com.saxonica.ee")
580
        || line.contains("import com.saxonica.config.ee")) {
581
      null
582
    } else {
583
      line.replaceFirst("\\s++\$", "")
584
    }
585
  }
586
}
587

    
588
task eej_sources(
589
  type: Copy,
590
  dependsOn: ["eej_preprocess"],
591
  description: "Collect the preprocessed EE sources for compilation"
592
) {
593
  from "${buildDir}/preprocess/eej"
594
  into "${buildDir}/src/eej"
595
}
596

    
597
// ============================================================
598

    
599
task hejCompile(
600
  type: JavaCompile,
601
  dependsOn: ["hej_sources"],
602
  description: "Compile HE for Saxon/Java"
603
) {
604
  classpath = configurations.compileClasspath
605
  source "${buildDir}/src/hej"
606
  destinationDirectory = new File("${buildDir}/classes/hej")
607
}
608
compileJava.dependsOn hejCompile
609

    
610
task pejCompile(
611
  type: JavaCompile,
612
  dependsOn: ["pej_sources"],
613
  description: "Compile PE for Saxon/Java"
614
) {
615
  classpath = configurations.compileClasspath
616
  source "${buildDir}/src/pej"
617
  destinationDirectory = new File("${buildDir}/classes/pej")
618
}
619
compileJava.dependsOn pejCompile
620

    
621
task eejCompile(
622
  type: JavaCompile,
623
  dependsOn: ["eej_sources"],
624
  description: "Compile EE for Saxon/Java"
625
) {
626
  classpath = configurations.compileClasspath + configurations.jarjarAsm
627
  source "${buildDir}/src/eej"
628
  destinationDirectory = new File("${buildDir}/classes/eej")
629
}
630
compileJava.dependsOn eejCompile
631

    
632
// ============================================================
633

    
634
task hej_copyTestDriverSources(
635
  type: Copy,
636
  description: "Copy test drivers sources for HE"
637
) {
638
  from "src/main/java"
639
  into "${buildDir}/src/testdrivers/hej"
640
  include "net/sf/saxon/testdriver/*.java"
641
}
642

    
643
task pej_copyTestDriverSources(
644
  type: Copy,
645
  description: "Copy test drivers sources for PE"
646
) {
647
  from "src/main/java"
648
  into "${buildDir}/src/testdrivers/pej"
649
  include "net/sf/saxon/testdriver/*.java"
650
  include "com/saxonica/testdriver/ee/*.java"
651
  include "com/saxonica/testdriver/gui/**"
652
  include "com/saxonica/testdriver/QT3TestDriverPE.java"
653
  include "com/saxonica/testdriver/XMarkBenchmark.java"
654
  include "com/saxonica/testdriver/Xslt30TestSuiteDriverEE.java"
655
  include "com/saxonica/testdriver/Xslt30TestSuiteDriverPE.java"
656
  include "com/saxonica/testdriver/ee/SchemaTestSuiteDriver.java"
657
  include "com/saxonica/testdriver/Licensor.java"
658
}
659

    
660
task eej_copyTestDriverSources(
661
  type: Copy,
662
  description: "Copy test drivers sources for EE"
663
) {
664
  from "src/main/java"
665
  into "${buildDir}/src/testdrivers/eej"
666
  include "com/saxonica/testdriver/ee/*.java"
667
  include "com/saxonica/testdriver/gui/**"
668
  include "com/saxonica/testdriver/QT3TestDriverPE.java"
669
  include "com/saxonica/testdriver/XMarkBenchmark.java"
670
  include "com/saxonica/testdriver/Xslt30TestSuiteDriverEE.java"
671
  include "com/saxonica/testdriver/Xslt30TestSuiteDriverPE.java"
672
  include "com/saxonica/testdriver/ee/SchemaTestSuiteDriver.java"
673
  include "com/saxonica/testdriver/Licensor.java"
674
  include "net/sf/saxon/testdriver/*.java"
675
}
676

    
677
task hej_copyTestDriverResources(
678
  type: Copy,
679
  description: "Copy test drivers resources for HE"
680
) {
681
  from "src/main/java"
682
  into "${buildDir}/classes/hej/testdrivers"
683
  include "net/sf/saxon/testdriver/**"
684
  exclude "net/sf/saxon/testdriver/**/*.java"
685
}
686

    
687
task pej_copyTestDriverResources(
688
  type: Copy,
689
  description: "Copy test drivers resources for PE"
690
) {
691
  from "src/main/java"
692
  into "${buildDir}/classes/pej/testdrivers"
693
  include "net/sf/saxon/testdriver/**"
694
  include "com/saxonica/testdriver/**"
695
  exclude "net/sf/saxon/testdriver/**/*.java"
696
  exclude "com/saxonica/testdriver/**/*.java"
697
  exclude "com/saxonica/testdriver/old/**"
698
  exclude "com/saxonica/testdriver/gui/cache.xml"
699
}
700

    
701
task eej_copyTestDriverResources(
702
  type: Copy,
703
  description: "Copy test drivers resources for EE"
704
) {
705
  from "src/main/java"
706
  into "${buildDir}/classes/eej/testdrivers"
707
  include "net/sf/saxon/testdriver/**"
708
  include "com/saxonica/testdriver/**"
709
  exclude "net/sf/saxon/testdriver/**/*.java"
710
  exclude "com/saxonica/testdriver/**/*.java"
711
  exclude "com/saxonica/testdriver/old/**"
712
  exclude "com/saxonica/testdriver/gui/cache.xml"
713
}
714

    
715
// ============================================================
716
// These tasks all relate to renaming (re-jarring) the ASM jar files
717
// for EE so that the class names begin com.saxonica. This avoids a
718
// problem where a different version of the ASM libraries is used in
719
// the application that is using Saxon.
720

    
721
task asm_createRules(
722
  description: "Create the jarjar rules file for the ASM libraries"
723
) {
724
  outputs.file("${buildDir}/jarjar-asm.rules")
725
  doLast {
726
    new File("${buildDir}/jarjar-asm.rules")
727
      .withWriter("utf-8") { writer ->
728
        writer.writeLine("rule org.objectweb.** com.saxonica.objectweb.@1")
729
      }
730
  }
731
  doFirst {
732
    mkdir "${buildDir}"
733
  }
734
}
735

    
736
task asm_jarjar(
737
  description: "Placeholder for the ASM jarjar dependencies"
738
) {
739
  // just a task to hang dependencies on
740
}
741

    
742
task asm_unzip(
743
  type: Copy,
744
  description: "Extract classes from the asm-xml-${asmVersion} jar"
745
) {
746
  // This one is from the original ASM
747
  def zipFile = file("lib/asm-${asmVersion}/asm-xml-${asmVersion}.jar")
748
  def outputDir = "${buildDir}/classes/eej"
749
  from zipTree(zipFile)
750
  into outputDir
751
}
752

    
753
["asm", "asm-analysis", "asm-commons", "asm-tree", "asm-util"].each { asm ->
754
  Task t = task "asm_${asm}"(
755
    type: JavaExec,
756
    dependsOn: ["asm_createRules"],
757
    description: "Run jarjar on ${asm}-${asmVersion} classes"
758
) {
759
    inputs.file "lib/asm-${asmVersion}/${asm}-${asmVersion}.jar"
760
    outputs.file "${buildDir}/lib/asm/${asm}-${asmVersion}.jar"
761
    classpath = configurations.preprocessor
762
    main = "com.tonicsystems.jarjar.Main"
763
    args "--rules", "${buildDir}/jarjar-asm.rules",
764
      "lib/asm-${asmVersion}/${asm}-${asmVersion}.jar",
765
      "${buildDir}/lib/asm/${asm}-${asmVersion}.jar"
766
    doFirst {
767
      mkdir "${buildDir}/lib/asm"
768
    }
769
  }
770
  asm_jarjar.dependsOn t
771

    
772
  t = task "asm_unzip${asm}"(
773
    type: Copy,
774
    dependsOn: ["asm_jarjar"],
775
    description: "Extract the classes from the ${asm}-{$asmVersion} jar"
776
  ) {
777
    def zipFile = file("${buildDir}/lib/asm/${asm}-${asmVersion}.jar")
778
    def outputDir = "${buildDir}/classes/eej"
779
    from zipTree(zipFile)
780
    into outputDir
781
  }
782
  asm_unzip.dependsOn t
783
}
784

    
785
// ============================================================
786

    
787
task hej_MetaInf(
788
  description: "Create META-INF/services/javax.xml.transform.TransformerFactory for HE"
789
) {
790
  outputs.file("${buildDir}/services/saxon-he/META-INF/services/javax.xml.transform.TransformerFactory")
791
  doFirst {
792
    mkdir "${buildDir}/services/saxon-he/META-INF/services"
793
  }
794
  doLast {
795
    new File("${buildDir}/services/saxon-he/META-INF/services/javax.xml.transform.TransformerFactory")
796
      .withWriter("utf-8") { writer ->
797
        writer.writeLine("net.sf.saxon.TransformerFactoryImpl")
798
      }
799
  }
800
}
801

    
802
task pej_MetaInf(
803
  description: "Create META-INF/services/javax.xml.transform.TransformerFactory for PE"
804
) {
805
  outputs.file("${buildDir}/services/saxon-pe/META-INF/services/javax.xml.transform.TransformerFactory")
806
  doFirst {
807
    mkdir "${buildDir}/services/saxon-pe/META-INF/services"
808
  }
809
  doLast {
810
    new File("${buildDir}/services/saxon-pe/META-INF/services/javax.xml.transform.TransformerFactory")
811
      .withWriter("utf-8") { writer ->
812
        writer.writeLine("com.saxonica.config.ProfessionalTransformerFactory")
813
      }
814
  }
815
}
816

    
817
task eej_schemaFactoryMetaInf(
818
  description: "Create META-INF/services/javax.xml.validation.SchemaFactory for EE"
819
) {
820
  outputs.file("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.validation.SchemaFactory")
821
  doFirst {
822
    mkdir "${buildDir}/services/saxon-ee/META-INF/services"
823
  }
824
  doLast {
825
    new File("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.validation.SchemaFactory")
826
      .withWriter("utf-8") { writer ->
827
        writer.writeLine("com.saxonica.ee.jaxp.SchemaFactoryImpl")
828
      }
829
  }
830
}
831

    
832
task eej_MetaInf(
833
  dependsOn: ["eej_schemaFactoryMetaInf"],
834
  description: "Create META-INF/services/javax.xml.transform.TransformerFactory for EE"
835
) {
836
  outputs.file("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.transform.TransformerFactory")
837
  doFirst {
838
    mkdir "${buildDir}/services/saxon-ee/META-INF/services"
839
  }
840
  doLast {
841
    new File("${buildDir}/services/saxon-ee/META-INF/services/javax.xml.transform.TransformerFactory")
842
      .withWriter("utf-8") { writer ->
843
        writer.writeLine("com.saxonica.config.EnterpriseTransformerFactory")
844
      }
845
  }
846
}
847

    
848
// ============================================================
849

    
850
task hejJar(
851
  type: Jar,
852
  dependsOn: ["hej_MetaInf", "hejCompile"],
853
  description: "Build the HE jar file"
854
) {
855
  archiveBaseName = "saxon-he-${saxonVersion}"
856
  manifest {
857
    attributes "Project-Name": "Saxon-HE"
858
    attributes "Main-Class": "net.sf.saxon.Transform"
859
  }
860
  from ("${buildDir}/services/saxon-he") {
861
    include "META-INF/**"
862
  }
863
  from ("${buildDir}/classes/hej") {
864
    include "net/**/*.class"
865
    exclude "net/sf/saxon/option/**"
866
  }
867
  from ("src/main/java") {
868
    include "net/sf/saxon/data/**"
869
  }
870
}
871

    
872
// Because the XQJ files are not open source, don't attempt to build
873
// the jar unless the EE sources are available.
874
if (file("${projectDir}/src/main/java/com/saxonica/xqj").exists()) {
875
  task hejJarXqj(
876
    type: Jar,
877
    dependsOn: ["eejCompile"],
878
    description: "Build the XQJ jar file for HE"
879
  ) {
880
    archiveBaseName = "saxon-he-xqj-${saxonVersion}"
881
    from ("${buildDir}/classes/eej") {
882
      include "com/saxonica/xqj/**/*.class"
883
      include "javax/xml/xquery/**/*.class"
884
    }
885
  }
886
} else {
887
  task hejJarXqj(
888
    description: "Ignore the XQJ file; the sources are unavailable"
889
  ) {
890
    doLast {
891
      println("Ignoring XQJ jar file task; the sources are unavailable")
892
    }
893
  }
894
}
895

    
896
task pejJar(
897
  type: Jar,
898
  dependsOn: ["pej_MetaInf", "pejCompile"],
899
  description: "Build the PE jar file"
900
) {
901
  archiveBaseName = "saxon-pe-${saxonVersion}"
902
  manifest {
903
    attributes "Project-Name": "Saxon-PE"
904
    attributes "Main-Class": "net.sf.saxon.Transform"
905
  }
906
  from ("${buildDir}/services/saxon-pe") {
907
    include "META-INF/**"
908
  }
909
  from ("${buildDir}/classes/pej") {
910
    include "net/**/*.class"
911
    include "com/saxonica/**/*.class"
912
    include "javax/xml/xquery/*.class"
913
    exclude "**/sql/**/*.class"
914
    exclude "com/saxonica/CompileStylesheet.class"
915
    exclude "com/saxonica/CompileStylesheet\$TracingObjectOutputStream.class"
916
    exclude "com/saxonica/Validate.class"
917
    exclude "com/saxonica/config/EnterpriseConfiguration.class"
918
    exclude "com/saxonica/config/EnterpriseConfiguration\$SurrogateSchema.class"
919
    exclude "com/saxonica/config/EnterpriseTransformerFactory.class"
920
    exclude "com/saxonica/config/EnterpriseXPathFactory.class"
921
    exclude "com/saxonica/config/StreamingTransformerFactory.class"
922
    exclude "com/saxonica/ee/**/*.class"
923
    exclude "com/saxonica/expr/CastToList.class"
924
    exclude "com/saxonica/expr/CastToUnion.class"
925
    exclude "com/saxonica/expr/CastableToList.class"
926
    exclude "com/saxonica/expr/CastableToUnion.class"
927
    exclude "com/saxonica/functions/sql/**"
928
    exclude "net/sf/saxon/option/sql/**"
929
  }
930
  from ("src/main/java") {
931
    include "net/sf/saxon/data/**"
932
  }
933
}
934

    
935
task pejJarSql(
936
  type: Jar,
937
  dependsOn: ["pejCompile"],
938
  description: "Build the SQL jar file for PE"
939
) {
940
  archiveBaseName = "saxon-pe-sql-${saxonVersion}"
941
  from ("${buildDir}/classes/pej") {
942
    include "net/sf/saxon/option/sql/*.class"
943
    include "com/saxonica/functions/sql/*.class"
944
  }
945
}
946

    
947
task eejJar(
948
  type: Jar,
949
  dependsOn: ["eej_MetaInf", "eejCompile", "asm_unzip"],
950
  description: "Build the EE jar file"
951
) {
952
  archiveBaseName = "saxon-ee-${saxonVersion}"
953
  manifest {
954
    attributes "Project-Name": "Saxon-EE"
955
    attributes "Main-Class": "net.sf.saxon.Transform"
956
  }
957
  from ("${buildDir}/services/saxon-ee") {
958
    include "META-INF/**"
959
  }
960
  from ("${buildDir}/classes/eej") {
961
    include "net/**/*.class"
962
    include "com/saxonica/**/*.class"
963
    include "javax/xml/xquery/*.class"
964
    include "org/objectweb/**/*.class"
965
    exclude "**/sql/**/*.class"
966
    exclude "com/saxonica/StatsTransform*.class"
967
    exclude "com/saxonica/functions/sql/**"
968
    exclude "net/sf/saxon/option/sql/**"
969
  }
970
  from ("src/main/java") {
971
    include "net/sf/saxon/data/**"
972
  }
973
}
974

    
975
task eejJarSql(
976
  type: Jar,
977
  dependsOn: ["eejCompile"],
978
  description: "Build the SQL jar file for EE"
979
) {
980
  archiveBaseName = "saxon-ee-sql-${saxonVersion}"
981
  from ("${buildDir}/classes/eej") {
982
    include "net/sf/saxon/option/sql/*.class"
983
    include "com/saxonica/functions/sql/*.class"
984
  }
985
}
986

    
987
// ============================================================
988

    
989
task hej_releaseSetup(
990
  type: Copy,
991
  dependsOn: ["hejJar", "hejJarXqj", "hejJarTests", "hej_notices"],
992
  description: "Build the HE release for Java"
993
) {
994
  from "${buildDir}/libs"
995
  into "${buildDir}/releases/hej"
996
  include "saxon-he-${saxonVersion}.jar"
997
  include "saxon-he-xqj-${saxonVersion}.jar"
998
  include "saxon-he-test-${saxonVersion}.jar"
999
  rename { filename ->
1000
    if (filename.startsWith("saxon-he-xqj")) {
1001
      filename = "saxon9-xqj.jar"
1002
    } else if (filename.startsWith("saxon-he-test")) {
1003
      filename = "saxon9-test.jar"
1004
    } else {
1005
      filename = "saxon9he.jar"
1006
    }
1007
  }
1008
}
1009

    
1010
task hejRelease(
1011
  type: Zip,
1012
  dependsOn: ["hej_releaseSetup"],
1013
  description: "Make the HE release ZIP file for Java"
1014
) {
1015
  from("${buildDir}/releases/hej")
1016
  archiveFileName = "SaxonHE${version_h}J.zip"
1017
}
1018

    
1019
task pejRelease(
1020
  type: Copy,
1021
  dependsOn: ["pejJar", "pejJarSql", "pejJarTests", "pej_libs", "pej_notices"],
1022
  description: "Build the PE release for Java"
1023
) {
1024
  from "${buildDir}/libs"
1025
  into "${buildDir}/releases/pej"
1026
  include "saxon-pe-${saxonVersion}.jar"
1027
  include "saxon-pe-sql-${saxonVersion}.jar"
1028
  include "saxon-pe-test-${saxonVersion}.jar"
1029
  rename { filename ->
1030
    if (filename.startsWith("saxon-pe-sql")) {
1031
      filename.replace("saxon-pe-sql", "saxon-sql")
1032
    } else {
1033
      filename
1034
    }
1035
  }
1036
}
1037

    
1038
task eejRelease(
1039
  type: Copy,
1040
  dependsOn: ["eejJar", "eejJarSql", "eejJarTests", "eej_libs", "eej_notices"],
1041
  description: "Build the EE release for Java"
1042
) {
1043
  from "${buildDir}/libs"
1044
  into "${buildDir}/releases/eej"
1045
  include "saxon-ee-${saxonVersion}.jar"
1046
  include "saxon-ee-sql-${saxonVersion}.jar"
1047
  include "saxon-ee-test-${saxonVersion}.jar"
1048
  rename { filename ->
1049
    if (filename.startsWith("saxon-ee-sql")) {
1050
      filename.replace("saxon-ee-sql", "saxon-sql")
1051
    } else {
1052
      filename
1053
    }
1054
  }
1055
}
1056

    
1057
task javaReleases(
1058
  dependsOn: ["hejRelease", "pejRelease", "eejRelease"],
1059
  description: "Build all of the Java releases"
1060
) {
1061
  // Just a container to hang dependencies on
1062
}
1063

    
1064
// ============================================================
1065

    
1066
task dockerCoreContainer(
1067
  type: Exec,
1068
  description: "Build the CentOS 8 core container"
1069
) {
1070
  inputs.files("${projectDir}/src/docker/centos8-core")
1071
  commandLine "docker", "build",
1072
    "-t", "${dockerCentos8Core}",
1073
    "${projectDir}/src/docker/centos8-core"
1074
}
1075

    
1076
// In order to build this container, you must specify the location
1077
// of the JDK and the Jet software archive. Use
1078
// -PdockerJdk= to specify the location of the JDK RPM. Use
1079
// -PdockerJet= to specify the location of the Jet archive.
1080
task dockerBuilderContainer(
1081
  type: Exec,
1082
  dependsOn: ["docker_setupBuilder", "dockerCoreContainer"],
1083
  description: "Build the Saxonica builder container"
1084
) {
1085
  inputs.files("${buildDir}/docker/builder")
1086
  commandLine "docker", "build",
1087
    "-t", "${dockerBuildContainer}",
1088
    "${buildDir}/docker/builder"
1089
}
1090

    
1091
task docker_setupBuilder(
1092
  type: Copy,
1093
  dependsOn: ["docker_setupJdk", "docker_setupJet"],
1094
  description: "Setup to build the builder container"
1095
) {
1096
  from "src/docker/builder"
1097
  into "${buildDir}/docker/builder"
1098
}
1099

    
1100
task docker_testJdk(
1101
  description: "Test that the dockerJdk property has been specified"
1102
) {
1103
  doLast {
1104
    if (dockerJdk == "none") {
1105
      throw new GradleException("You must specify the JDK with -PdockerJdk=...")
1106
    }
1107
  }
1108
}
1109

    
1110
task docker_setupJdk(
1111
  type: Copy,
1112
  dependsOn: ["docker_testJdk"],
1113
  description: "Setup the JDK for the builder container"
1114
) {
1115
  from dockerJdk
1116
  into "${buildDir}/docker/builder"
1117
}
1118

    
1119
task docker_testJet(
1120
  description: "Test that the dockerJet property has been specified"
1121
) {
1122
  doLast {
1123
    if (dockerJet == "none") {
1124
      throw new GradleException("You must specify Jet archive with -PdockerJet=...")
1125
    }
1126
  }
1127
}
1128

    
1129
task docker_setupJet(
1130
  type: Copy,
1131
  dependsOn: ["docker_testJet"],
1132
  description: "Setup the Jet archive for the builder container"
1133
) {
1134
  from dockerJet
1135
  into "${buildDir}/docker/builder"
1136
}
1137

    
1138
// ============================================================
1139

    
1140
// Testing task for various Gradle debugging efforts
1141
task helloWorld() {
1142
  doLast {
1143
    println("Hello, world.")
1144
  }
1145
}
1146

    
(7-7/12)