forked from docbook/xslTNG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
1915 lines (1685 loc) · 55.1 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://dev.saxonica.com/maven" }
}
apply from: 'properties.gradle'
configurations.all {
resolutionStrategy {
exclude group: 'xml-apis', module: 'xml-apis'
exclude group: 'xerces', module: 'xercesImpl'
force "${saxonGroup}:${saxonEdition}:${saxonVersion}",
"org.xmlresolver:xmlresolver:${xmlresolverVersion}"
}
}
dependencies {
classpath group: saxonGroup, name: saxonEdition, version: saxonVersion
classpath group: 'com.drewnoakes', name: 'metadata-extractor', version: metadataExtractorVersion
classpath group: 'com.nwalsh', name: 'sinclude', version: sincludeVersion
classpath group: 'org.xmlresolver', name: 'xmlresolver', version: xmlresolverVersion
classpath group: 'org.docbook', name: 'schemas-docbook', version: docbookVersion
classpath group: 'org.docbook', name: 'schemas-publishers', version: docbookVersion
}
}
plugins {
id "java"
id "groovy"
id "maven-publish"
id "signing"
// The com.nwalsh.gradle.saxon.saxon-gradle plugin is loaded in buildSrc
// The com.nwalsh.gradle.relaxng.validate plugin is loaded in buildSrc
// The com.nwalsh.gradle.relaxng.translate plugin is loaded in buildSrc
id "de.undercouch.download" version "4.0.4"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
}
}
import static groovy.io.FileType.DIRECTORIES
import org.gradle.internal.os.OperatingSystem;
import com.nwalsh.gradle.saxon.SaxonXsltTask
import com.nwalsh.gradle.relaxng.validate.RelaxNGValidateTask
import com.nwalsh.gradle.relaxng.translate.RelaxNGTranslateTask
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.security.MessageDigest
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.util.zip.ZipOutputStream
import java.util.zip.ZipEntry
import de.undercouch.gradle.tasks.download.Download
import org.docbook.xsltng.gradle.TestUtils
import org.docbook.xsltng.gradle.TestGenerator
repositories {
mavenLocal()
mavenCentral()
maven { url "https://dev.saxonica.com/maven" }
}
apply from: 'properties.gradle'
configurations.all {
resolutionStrategy {
exclude group: 'xml-apis', module: 'xml-apis'
exclude group: 'xerces', module: 'xercesImpl'
force "${saxonGroup}:${saxonEdition}:${saxonVersion}",
"org.xmlresolver:xmlresolver:${xmlresolverVersion}"
}
}
configurations {
validateRuntime.extendsFrom(testImplementation)
projectImplementationClasspath.extendsFrom(implementation)
projectRuntimeClasspath.extendsFrom(runtimeOnly)
}
ext {
requireCompileSuccess = !"false".equals(project.property('requireCompileSuccess'))
epubMediaTypes = [
"css": "text/css",
"ttf": "font/ttf",
"woff": "font/woff",
"jpg": "image/jpeg",
"jpeg": "image/jpeg",
"png": "image/png",
"gif": "image/gif",
"svg": "image/svg"
]
computedGitRef = null
extraParams = [:]
fProjectDir = projectDir.toString()
uProjectDir = TestUtils.fixWindowsPath(fProjectDir)
fBuildDir = buildDir.toString()
uBuildDir = TestUtils.fixWindowsPath(fBuildDir)
XSPEC = OperatingSystem.current().isWindows() ? 'xspec.bat' : 'xspec.sh'
}
project.properties.keySet().each { key ->
if (key.startsWith("ep_")) {
println("SETTING ${key.substring(3)}")
extraParams[key.substring(3)] = project.properties.get(key).trim()
}
}
// Set saxonLicenseDir in gradle.properties, or from the
// command line if you have a license in some other place.
if (!hasProperty("saxonLicenseDir")) {
if (System.getenv("SAXON_LICENSE_DIR") != null) {
ext.saxonLicenseDir=System.getenv('SAXON_LICENSE_DIR')
} else {
ext.saxonLicenseDir=System.getenv('HOME') + "/java"
}
}
dependencies {
implementation (
[group: saxonGroup, name: saxonEdition, version: saxonVersion],
[group: 'com.drewnoakes', name: 'metadata-extractor', version: metadataExtractorVersion],
[group: 'org.relaxng', name: 'jing', version: jingVersion ],
[group: 'org.relaxng', name: 'trang', version: jingVersion ],
[group: 'org.xmlresolver', name: 'xmlresolver', version: xmlresolverVersion],
[group: 'com.nwalsh', name: 'sinclude', version: sincludeVersion ],
[group: 'org.w3c', name: 'epubcheck', version: '5.0.1'],
files("${projectDir}/buildSrc/build/classes/java/main"),
files(saxonLicenseDir)
)
testImplementation (
[group: 'junit', name: 'junit', version: '4.13'],
[group: 'org.docbook', name: 'schemas-docbook', version: docbookVersion],
[group: 'org.docbook', name: 'schemas-publishers', version: docbookVersion]
)
}
defaultTasks 'report'
def docbookXsltArgs = ['-init:org.docbook.xsltng.extensions.Register']
// If this is running on the CI infrastructure and it's not
// a tagged build, add -SNAPSHOT to the version.
if (System.getenv()["CIWORKFLOW"] == "yes"
&& (System.getenv()["CI_TAG"] == null || System.getenv()["CI_TAG"] == "")
&& !xslTNGversion.contains('SNAPSHOT')) {
xslTNGversion = xslTNGversion + "-SNAPSHOT"
}
// I'm not sure I want to generate *all* the PDF files.
// This is a kind of random list...
def pdfTests = ['article.003', 'book.001', 'book.003',
'calloutlist.001', 'changebars.001', 'mediaobject.001'];
class SummarizeTestResults extends DefaultTask {
@Input
String[] resultFiles = []
@TaskAction
def docheck() {
resultFiles.each { driver ->
def base = driver.substring(0, driver.length() - 6)
println(base)
}
}
}
class CheckTextFile extends DefaultTask {
@Input
String checkFile = null
@TaskAction
def docheck() {
def pass = true
new File(checkFile).eachLine { line ->
if (line.endsWith("failed") && !line.equals("0 failed")) {
pass = false
}
println(line)
}
if (!pass) {
if ((project.findProperty('requireTestSuccess') ?: "true") != "false") {
throw new GradleException("Failing tests!")
}
println("WARNING: Some tests failed")
}
}
}
def gitRef() {
// Depending on the state of your repo, this can be time consuming,
// so don't bother unless you're demanding complete success...
if (computedGitRef != null) {
return computedGitRef
}
def ref = null;
if (requireCompileSuccess) {
def gitRepo = new File(".git")
if (gitRepo.exists() && gitRepo.isDirectory()) {
def command = ['git', 'rev-parse', '--short', '--verify', 'HEAD']
ProcessBuilder pb = new ProcessBuilder().command(command)
pb.directory(projectDir)
Process proc = pb.start()
def reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null
while ((line = reader.readLine()) != null) {
if (ref == null) {
ref = line
}
}
reader = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
while ((line = reader.readLine()) != null) {
println(line)
}
proc.waitFor()
}
} else {
ref = "SNAPSHOT"
}
computedGitRef = ref
if (ref == null) {
ref = "Unknown"
println("This doesn't appear to be a git clone; using VERSION-ID: ${ref}")
} else {
println("Using git ref as VERSION-ID: ${ref}")
}
return ref
}
def pygmentize = findPygmentize()
def findPygmentize() {
def path = System.getenv()["PATH"] == null ? System.getenv()["Path"] : System.getenv()["PATH"]
def script = null
def pathsep = System.getProperty("path.separator")
def pygmentize = OperatingSystem.current().isWindows() ? 'pygmentize.exe' : 'pygmentize'
path.split(pathsep).each { segment ->
if (script == null) {
def testfile = new File("${segment}/${pygmentize}")
if (testfile.exists() && testfile.canExecute()) {
script = testfile.toString()
}
if (segment.endsWith("/.pyenv/shims")) {
// Ok, we found pyenv, now can we find pygmentize?
def pyenv = new File("${segment.substring(0, segment.length() - 6)}/versions")
def versions = []
pyenv.traverse(type: DIRECTORIES, maxDepth: 0) { dir ->
testfile = new File("${dir}/bin/${pygmentize}")
if (testfile.exists() && testfile.canExecute()) {
script = testfile.toString()
}
}
}
}
}
if (script == null) {
println("Could not find pygmentize")
script = "" // nevermind
} else {
println("Using Pygments from ${script}")
}
return script
}
// This is all a complete hack that I worked out by trial and error
def EXCP="${projectDir}/build/classes/java/main"
configurations.validateRuntime.each { it ->
EXCP += System.getProperty("path.separator") + it
}
// Set system properties
System.setProperty("org.docbook.xsltng.extensions.verbose", verbose)
System.setProperty("org.docbook.extensions.pygmentize", pygmentize)
println("Using Java version ${System.getProperty('java.version')}")
task configureEnvironment() {
def envVars = [:]
envVars['TEST_DIR'] = buildDir
envVars['SAXON_CP'] = EXCP
envVars['PYGMENTIZE'] = pygmentize
envVars['VERBOSE'] = verbose
tasks.withType(Exec) {
environment << envVars
}
}
task setupXSpec(type: Download) {
src "https://github.com/xspec/xspec/archive/v${xspecVersion}.zip"
dest file("${buildDir}/xspec-${xspecVersion}.zip")
doFirst {
mkdir(buildDir)
}
doLast {
copy {
from zipTree("${buildDir}/xspec-${xspecVersion}.zip")
into buildDir
}
}
doLast {
copy {
from "${projectDir}/src/test/resources/xspec"
into "${buildDir}/xspec-${xspecVersion}/src/common"
include "uri-utils.xsl"
}
}
doLast {
copy {
from "${projectDir}/src/test/resources/xspec"
into "${buildDir}/xspec-${xspecVersion}/bin"
include "xspec.sh"
include "xspec.bat"
}
}
onlyIf { !file("${buildDir}/xspec-${xspecVersion}/README.md").exists() }
}
task setupXsltExplorer(type: Download) {
outputs.file "${buildDir}/xsltexplorer-${xsltExplorerVersion}/xslt/explorer.xsl"
src "https://github.com/ndw/xsltexplorer/releases/download/${xsltExplorerVersion}/xsltexplorer-${xsltExplorerVersion}.zip"
dest file("${buildDir}/xsltexplorer-${xsltExplorerVersion}.zip")
doFirst {
mkdir(buildDir)
}
doLast {
copy {
from zipTree("${buildDir}/xsltexplorer-${xsltExplorerVersion}.zip")
into buildDir
}
}
onlyIf { !file("${buildDir}/xsltexplorer-${xsltExplorerVersion}/README.org").exists() }
}
task copyResources(type: Copy,
dependsOn: ['copyTestMedia', 'zipStageResources',
'zipStageMisc']) {
from "${buildDir}/stage/zip/resources"
into "${buildDir}/actual"
exclude "scss/**"
}
def pkglist = ["net.sf.saxon:Saxon-HE:${saxonVersion}",
"com.drewnoakes:metadata-extractor:${metadataExtractorVersion}",
"org.relaxng:jing:${jingVersion}",
"org.xmlresolver:xmlresolver:${xmlresolverVersion}",
"com.nwalsh:sinclude:${sincludeVersion}"]
task copyBin(type: Copy) {
def packages = ""
pkglist.each { pkg ->
if (packages != "") {
packages += ",\n "
}
packages = packages + "\"${pkg}\""
}
from "${projectDir}/src/bin"
into "${buildDir}/bin"
exclude '.mypy_cache/**'
rename("docbook.py", "docbook")
filter { String line ->
if (line.indexOf("@@") >= 0) {
line = line
.replace("\"@@PACKAGE_LIST@@\"", packages)
.replace("@@VERSION@@", xslTNGversion)
}
line
}
}
task copyDocker(type: Copy) {
def commands = ""
pkglist.each { pkg ->
commands += "RUN mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get \\\n"
commands += " -Dartifact=${pkg}\n"
}
from "${projectDir}/src/docker"
into "${buildDir}/docker"
filter { String line ->
if (line.indexOf("@@") >= 0) {
line = line
.replace("@@MAVEN-COMMANDS@@", commands)
.replace("@@VERSION@@", xslTNGversion)
}
line
}
}
task copyReportResources(
dependsOn: ['copyExpectedMedia', 'zipStageResources', 'zipStageMisc']
) {
doLast {
copy {
from "${projectDir}/src/test/resources"
include "css/**"
include "js/**"
into "${buildDir}/report"
filter { String line ->
if (line.indexOf("@@") >= 0) {
line = line
.replace("@@TITLE@@", xslTNGtitle)
.replace("@@VERSION@@", xslTNGversion)
}
line
}
}
}
doLast {
copy {
from "${buildDir}/stage/zip/resources"
into "${buildDir}/report/expected"
exclude "scss/**"
}
}
}
task copyTestMedia(type: Copy) {
from "${projectDir}/src/test/resources"
into "${buildDir}/actual"
include "media/**"
}
task copyExpectedMedia(type: Copy) {
from "${projectDir}/src/test/resources"
into "${buildDir}/report/expected"
include "media/**"
}
task allExpectedDocuments() {
// Just something to hang dependencies on
}
task allExpectedPdfDocuments() {
// Just something to hang dependencies on
}
task reportExpectedHTML() {
// Just something to hang dependencies on
}
task validateAll() {
// Just something to hang dependencies on
}
task generateLocales() {
// Just something to hang dependencies on
}
task actualResults() {
// Just somewhere to hang dependencies
}
// ============================================================
// Generate tasks to generate the locale files
fileTree(dir: "${projectDir}/src/main/locale",
include: "*.xml").each { xml ->
// Work out the base filename of the test
def base = TestUtils.fixWindowsPath(xml.toString())
def pos = base.lastIndexOf("/")
if (pos > 0) {
base = base.substring(pos+1)
}
Task t = task "locale_${base}"(
type: SaxonXsltTask
) {
input xml
stylesheet "${uProjectDir}/src/main/xslt/modules/xform-locale.xsl"
output "${uBuildDir}/xslt/locale/${base}"
if (base != 'en.xml') {
parameters(
'fallback.locale': "${uProjectDir}/src/main/locale/en.xml"
)
}
}
generateLocales.dependsOn t
}
task makeVersion(type: SaxonXsltTask) {
input "${uProjectDir}/tools/version.xsl"
stylesheet "${uProjectDir}/tools/version.xsl"
output "${uBuildDir}/xslt/VERSION.xsl"
parameters(
'version': xslTNGversion,
'gitref': gitRef()
)
}
task copyXslt(dependsOn: ['copyResources', 'makeVersion',
'generateLocales', 'compileJava']) {
inputs.files fileTree(dir: "${projectDir}/src/main/xslt")
outputs.files fileTree(dir: "${buildDir}/xslt")
outputs.files fileTree(dir: "${buildDir}/xspec-xslt")
doLast {
copy {
from "${projectDir}/src/main/xslt"
into "${buildDir}/xslt"
exclude "xspec-driver.xsl"
exclude "alt-*.xsl"
}
}
doLast {
copy {
from "${projectDir}/src/main/xslt"
into "${buildDir}/xspec-xslt"
include "xspec-driver.xsl"
include "alt-*.xsl"
}
}
}
task testStandalone(type: SaxonXsltTask) {
// The output of this test doesn't matter; it simply assures that
// the standalone-functions.xsl file hasn't accidentally become
// dependent on other stylesheets so it isn't properly standalone
inputs.dir "${buildDir}/xslt"
input "${projectDir}/src/test/resources/xml/article.001.xml"
stylesheet "${projectDir}/tools/standalone.xsl"
output "${buildDir}/tmp/standalone.xml"
}
task makeXslt(type: SaxonXsltTask, dependsOn: ["copyXslt"]) {
input "${projectDir}/src/guide/xml/ref-params.xml"
stylesheet "${projectDir}/tools/generate-parameters.xsl"
output "${buildDir}/xslt/param.xsl"
finalizedBy = [ 'testStandalone' ]
}
task makeUriList(
dependsOn: ["makeXslt", "zipStageResources","zipStageDocker",
"zipStageXslt", "zipStageBin"]
) {
inputs.files fileTree(dir: "${buildDir}/xslt", excludes: ["xspec-*.xsl"])
inputs.files fileTree("${buildDir}/stage/zip")
outputs.file "${buildDir}/resources/main/org/docbook/xsltng/etc/uris.xml"
doFirst {
mkdir "${buildDir}/resources/main/org/docbook/xsltng/etc"
}
doLast {
def prefix = '/org/docbook/xsltng'
new File("${buildDir}/resources/main/org/docbook/xsltng/etc/uris.xml").withWriter("utf-8") { writer ->
writer.writeLine("<catalog>")
def pos = "${buildDir}".length()
fileTree(dir: "${buildDir}/xslt", excludes: ["xspec-*.xsl"]).each { file ->
writer.writeLine(" <uri name='${prefix}${file.getAbsolutePath().substring(pos)}'/>")
}
pos = "${buildDir}/stage/zip".length()
fileTree(dir: "${buildDir}/stage/zip/resources", exclude: ['scss/**']).each { file ->
writer.writeLine(" <uri name='${prefix}${file.getAbsolutePath().substring(pos)}'/>")
}
writer.writeLine("</catalog>")
}
}
}
// ============================================================
task formattingTests() {
// Just somewhere to hang dependencies. I used to put these
// dependencies directly on 'test', but that had the consequence
// that running a single unit test ran all of the formatting
// tests.
}
task testJarMain(type: Exec, dependsOn: jar) {
commandLine "java",
"-jar", "${uBuildDir}/libs/docbook-xslTNG-${xslTNGversion}.jar",
"${uProjectDir}/src/test/resources/xml/article.001.xml",
"-o:/dev/null"
}
formattingTests.dependsOn testJarMain
task testDocBookPy(type: Exec, dependsOn: ["jar", "copyBin", "copyDocker"]) {
commandLine "python3", "${buildDir}/bin/docbook",
"${projectDir}/src/test/resources/xml/article.001.xml",
"-xsl:${buildDir}/xslt/docbook.xsl",
"-o:/dev/null"
}
formattingTests.dependsOn testDocBookPy
task testSummary(
type: SaxonXsltTask,
dependsOn: ['xspecTests', "makeXslt"]
) {
inputs.files fileTree(dir: buildDir, include: "*-result.xml")
stylesheet "${uProjectDir}/tools/test-results.xsl"
output "${uBuildDir}/test-results.txt"
args(["-it"])
}
task requirePassingTests(
type: CheckTextFile,
dependsOn: ['formattingTests', 'testSummary']
) {
checkFile = "${buildDir}/test-results.txt"
}
test.dependsOn requirePassingTests
task reportResults(type: Copy, dependsOn: ['testSummary']) {
from "build"
include "*-result.*"
include "*-compiled.xsl"
into "${buildDir}/report"
}
task coverageReport(type: SaxonXsltTask,
dependsOn: ['testSummary', 'copyReportResources']) {
input "${uBuildDir}/default-result.xml"
stylesheet "${uProjectDir}/tools/coverage-report.xsl"
output "${uBuildDir}/report/coverage-report.html"
}
formattingTests.dependsOn reportResults
formattingTests.dependsOn coverageReport
// Use Exec so that it runs the same version of Saxon as the tests.
task report(dependsOn: ['xspecTests']) {
inputs.files fileTree(dir: buildDir, include: "*-result.xml")
inputs.file("${projectDir}/tools/report.xsl")
outputs.file("${buildDir}/report/index.html")
finalizedBy testSummary
doLast {
copy {
from "${projectDir}/src/test/resources"
include "css/**"
include "js/**"
into "${buildDir}/report"
filter { String line ->
if (line.indexOf("@@") >= 0) {
line = line
.replace("@@TITLE@@", xslTNGtitle)
.replace("@@VERSION@@", xslTNGversion)
}
line
}
}
}
doLast {
copy {
from "${projectDir}/src/website/resources"
include "img/**"
include "media/**"
exclude "olinkdb/**"
into "${buildDir}/report"
}
}
doLast {
copy {
from "${projectDir}/src/test/resources"
include "xml/**"
include "expected/**"
filter { String line ->
if (line.indexOf("@@") >= 0) {
line = line
.replace("@@TITLE@@", xslTNGtitle)
.replace("@@VERSION@@", xslTNGversion)
}
line
}
into "${buildDir}/report"
}
}
doLast {
copy {
from "${buildDir}/validated"
into "${buildDir}/report/xml"
}
}
doLast {
copy {
from "build"
include "*-result.*"
include "*-compiled.xsl"
into "${buildDir}/report"
}
}
doLast {
exec {
commandLine "java",
"-Dorg.docbook.xsltng.extensions.verbose=${verbose}",
"-Dorg.docbook.extensions.pygmentize=${pygmentize}",
"-cp", EXCP, "net.sf.saxon.Transform",
"-init:org.docbook.xsltng.extensions.Register",
"${buildDir}/default-result.xml",
"-xsl:tools/report.xsl",
"-o:${buildDir}/report/index.html"
}
}
}
// ============================================================
task cleanXSpec() {
doLast {
fileTree(dir: buildDir, exclude: ["xspec-" + xspecVersion + ".zip",
"xspec-" + xspecVersion + "/**",
"docbook-" + docbookVersion + ".zip",
"docbook-" + docbookVersion + "/**"])
.each { artifact ->
artifact.delete()
}
}
}
clean.dependsOn cleanXSpec
// ============================================================
task zipStagePygments() {
if (pygmentize == "") {
doLast {
println("Without pygmentize, zip file resources will be incomplete.")
}
} else {
doFirst {
mkdir "${buildDir}/stage/zip/resources/css"
}
doLast {
exec {
commandLine "python3", "${uProjectDir}/tools/generate-pygments.py",
"--version", xslTNGversion, "--title", xslTNGtitle,
"--output", "${buildDir}/stage/zip/resources/css/pygments.css"
}
}
}
}
task compileSass() {
inputs.files fileTree("${projectDir}/src/main/scss")
outputs.files fileTree("${buildDir}/css")
doLast {
exec {
commandLine 'sass', '--style', 'expanded',
'--no-source-map', '--no-charset',
"${fProjectDir}/src/main/scss/docbook-screen.scss:${buildDir}/css/docbook.css",
"${fProjectDir}/src/main/scss/docbook-paged.scss:${buildDir}/css/docbook-paged.css",
"${fProjectDir}/src/main/scss/docbook-epub.scss:${buildDir}/css/docbook-epub.css",
"${fProjectDir}/src/main/scss/toc.scss:${buildDir}/css/docbook-toc.css",
"${fProjectDir}/src/main/scss/vendor-ahf-portrait.scss:${buildDir}/css/vendor-ahf-portrait.css",
"${fProjectDir}/src/main/scss/vendor-ahf-landscape.scss:${buildDir}/css/vendor-ahf-landscape.css",
"${fProjectDir}/src/main/scss/vendor-weasyprint.scss:${buildDir}/css/vendor-weasyprint.css"
}
}
doLast {
exec {
commandLine 'sass', '--style', 'compressed',
'--no-source-map', '--no-charset',
"${fProjectDir}/src/main/scss/docbook-screen.scss:${buildDir}/css/docbook.min.css",
"${fProjectDir}/src/main/scss/docbook-paged.scss:${buildDir}/css/docbook-paged.min.css",
"${fProjectDir}/src/main/scss/docbook-epub.scss:${buildDir}/css/docbook-epub.min.css",
"${fProjectDir}/src/main/scss/toc.scss:${buildDir}/css/docbook-toc.min.css",
"${fProjectDir}/src/main/scss/vendor-ahf-portrait.scss:${buildDir}/css/vendor-ahf-portrait.min.css",
"${fProjectDir}/src/main/scss/vendor-ahf-landscape.scss:${buildDir}/css/vendor-ahf-landscape.min.css",
"${fProjectDir}/src/main/scss/vendor-weasyprint.scss:${buildDir}/css/vendor-weasyprint.min.css"
}
}
doLast {
["docbook", "docbook-paged", "docbook-epub", "docbook-toc",
"vendor-ahf-landscape", "vendor-ahf-portrait", "vendor-weasyprint"].each { base ->
[".css", ".min.css"].each { ext ->
String fn = "${base}${ext}"
File css = new File("${buildDir}/css/${fn}")
def lines = []
def reader = new BufferedReader(new FileReader(css))
String line = null
while ((line = reader.readLine()) != null) {
lines.add(line)
}
reader.close()
def writer = new PrintStream(css)
writer.print("/")
writer.print("* ${xslTNGtitle} version ${xslTNGversion}, https://xsltng.docbook.org *")
if (ext == ".css") {
writer.println("/");
} else {
writer.print("/");
}
lines.each { ln ->
writer.println(ln);
}
writer.close();
}
}
}
}
task zipStageResources(dependsOn: ["zipStagePygments", "compileSass"]) {
doLast {
copy {
from "${buildDir}/css"
into "${buildDir}/stage/zip/resources/css"
}
}
doLast {
copy {
from "${projectDir}/src/main/scss"
into "${buildDir}/stage/zip/resources/scss"
}
}
// Copy png files without filtering them
doLast {
copy {
from "${projectDir}/src/main/web"
include "css/*.png"
into "${buildDir}/stage/zip/resources"
}
}
// Copy and filter text resources
doLast {
copy {
from "${projectDir}/src/main/web"
include 'css/**'
include 'js/**'
exclude 'css/*.png'
if (pygmentize != "") {
exclude 'css/pygments.css'
}
into "${buildDir}/stage/zip/resources"
filter { String line ->
if (line.indexOf("@@") >= 0) {
line = line
.replace("@@TITLE@@", xslTNGtitle)
.replace("@@VERSION@@", xslTNGversion)
}
line
}
}
}
}
task zipStageSamples(dependsOn: ["zipStageResources"]) {
doLast {
copy {
from "${buildDir}/stage/zip/resources"
into "${buildDir}/stage/zip/samples"
exclude "scss/**"
}
}
doLast {
copy {
from "${projectDir}/src/main/samples"
into "${buildDir}/stage/zip/samples"
}
}
}
task zipStageXslt(type: Copy, dependsOn: ['makeXslt']) {
from "${buildDir}/xslt"
into "${buildDir}/stage/zip/xslt"
}
task zipStageMisc(type: Copy, dependsOn: ["zipStageSamples"]) {
from "."
into "${buildDir}/stage/zip"
include "README.md"
include "LICENSE"
}
task zipStageLib(dependsOn: ['jar', 'copyLib']) {
doLast {
copy {
from "${buildDir}/libs"
into "${buildDir}/stage/zip/libs"
include "docbook-xslTNG-${xslTNGversion}.jar"
}
}
doLast {
copy {
from "${buildDir}/libs/lib"
into "${buildDir}/stage/zip/libs/lib"
}
}
}
task zipStageBin(type: Copy, dependsOn: ['copyBin']) {
from "${buildDir}/bin"
into "${buildDir}/stage/zip/bin"
}
task zipStageDocker(type: Copy, dependsOn: ['copyDocker']) {
from "${buildDir}/docker"
into "${buildDir}/stage/zip/docker"
}
task zipStageCatalog(
type: SaxonXsltTask,
dependsOn: ['makeUriList', 'zipStageXslt', "stageJar", "processResources"]
) {
input TestUtils.fixWindowsPath(makeUriList.outputs.files.getSingleFile().toString())
stylesheet "${uProjectDir}/src/main/resources/org/docbook/xsltng/etc/make-catalog.xsl"
output "${uBuildDir}/stage/zip/xslt/catalog.xml"
parameters(
'version': xslTNGversion
)
}
task zipStage(type: Copy, dependsOn: ['zipStageBin', 'zipStageDocker', 'zipStageLib',
'zipStageMisc', 'zipStageCatalog']) {
// nop
}
task releaseArtifacts(type: Copy, dependsOn: ['zipStage']) {
from "${buildDir}/stage/zip"
into "${buildDir}/release"
exclude "bin/**"
exclude "libs/**"
exclude "samples/**"
exclude "docker/**"
}
task zipDist(type: Zip, dependsOn: ['zipStage']) {
from("${buildDir}/stage/zip")
into "${xslTNGbaseName}-${xslTNGversion}"
archiveFileName = "${xslTNGbaseName}-${xslTNGversion}.zip"
}
task zipDistNoSaxon(type: Zip, dependsOn: ['zipStage']) {
from("${buildDir}/stage/zip")
exclude "libs/lib/Saxon*"
into "${xslTNGbaseName}-nosaxon-${xslTNGversion}"
archiveFileName = "${xslTNGbaseName}-nosaxon-${xslTNGversion}.zip"
}
task relnotes(
description: "Checks for release notes",
) {
doLast {
BufferedReader guide = new BufferedReader(new FileReader("${projectDir}/src/guide/xml/changelog.xml"))
boolean found = false
String line = guide.readLine()
while (line != null) {
if (line.contains("<productnumber>${xslTNGversion}<")) {
found = true;
break;
}
line = guide.readLine()
}
guide.close();
if (!found) {
println("************************************************************")
println("There are no release notes for xslTNG version ${xslTNGversion}")
println("************************************************************")
if (requireCompileSuccess && !xslTNGversion.contains('SNAPSHOT')) {
throw new GradleException("No release notes for ${xslTNGversion}")
}
}
}