Project

Profile

Help

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

he / build.gradle @ 05591ffc

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: 'net.sf.saxon', name: 'Saxon-HE', 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
  version_h = saxonVersion.replace(".", "-")
137
}
138

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

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

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

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

    
188
  return false
189
}
190

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

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

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

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

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

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

    
251
// ============================================================
252

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

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

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

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

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

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

    
334
// ============================================================
335

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

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

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

    
389
task hej_setupPreprocessForPej(
390
  type: Copy,
391
  dependsOn: ["hej_featureKeys"],
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
  dependsOn: ["hej_featureKeys"],
449
  description: "Copy HE sources for EE build"
450
) {
451
  from "${projectDir}/src/main/java"
452
  into "${buildDir}/filtered/eej"
453
  include "net/sf/saxon/**/*.java"
454
  include "javax/xml/xquery/*.java"
455
  exclude "**/dotnet/**"
456
  include "net/sf/saxon/**/package.html"
457
  exclude "net/sf/saxon/testdriver/**"
458
  exclude "net/sf/saxon/option/cpp/**"
459
  exclude "net/sf/saxon/jetonnet/**"
460
  exclude "net/sf/saxon/jetonnet/**"
461
  include "net/sf/saxon/data/**"
462
}
463

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

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

    
501
// ============================================================
502

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

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

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

    
558
// ============================================================
559

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

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

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

    
598
// ============================================================
599

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

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

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

    
633
// ============================================================
634

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

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

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

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

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

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

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

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

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

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

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

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

    
786
// ============================================================
787

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

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

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

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

    
849
// ============================================================
850

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

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

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

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

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

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

    
988
// ============================================================
989

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

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

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

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

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

    
1065
// ============================================================
1066

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

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

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

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

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

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

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

    
1139
// ============================================================
1140

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

    
(7-7/12)