-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
232 lines (209 loc) · 6.29 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
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://dev.saxonica.com/maven"
}
}
dependencies {
classpath group: "com.saxonica", name: "Saxon-EE", version: saxonVersion
}
}
plugins {
id "java"
id "de.undercouch.download" version "4.0.4"
}
import de.undercouch.gradle.tasks.download.Download
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://dev.saxonica.com/maven"
}
}
configurations.all {
resolutionStrategy {
force 'xml-apis:xml-apis:1.4.01'
}
}
configurations {
saxon.extendsFrom(implementation)
}
// Where can we find a Saxon license (for the XJ compiler)
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: "com.saxonica", name: "Saxon-EE", version: saxonVersion]
)
saxon (
files(saxonLicenseDir)
)
}
defaultTasks 'publish'
task publish(dependsOn: ["copyResources", "compileXslt", "compilePrint"]) {
// nop
}
// I want the XSLT source to contain a version number, but I'm never
// going to remember to update it there, so I check that the version
// in the source is the same as the version in gradle.properties
task dist(
type: Exec,
description: "Check that the slidesJSversions match"
) {
inputs.file "${projectDir}/gradle.properties"
inputs.file "${projectDir}/src/main/js/start.js"
outputs.file "${buildDir}/version"
def getVersion = new ByteArrayOutputStream();
commandLine "grep", "const SlidesJSVersion", "${projectDir}/src/main/js/start.js"
standardOutput = getVersion
doLast {
def xslVersion = getVersion.toString("utf-8")
def pos = xslVersion.indexOf("\"");
xslVersion = xslVersion.substring(pos+1);
pos = xslVersion.indexOf("\"");
xslVersion = xslVersion.substring(0, pos);
def output = new FileWriter(new File("${buildDir}/version"))
output.write(xslVersion)
output.close()
if (xslVersion != slidesJSversion) {
throw new GradleException("Versions don't match: ${xslVersion} != ${slidesJSversion}")
}
}
doFirst {
mkdir buildDir
}
}
task copyResources(type: Copy) {
into "${buildDir}/website"
from ("${projectDir}/src/main") {
exclude "xslt/**"
}
doFirst {
mkdir "${buildDir}/website"
}
}
if (xsltCompiler == "XX") {
task createPackageJson() {
doLast {
new File("package.json")
.withWriter("utf-8") { writer ->
writer.writeLine("{")
writer.writeLine(" \"name\": \"SlidesJS\",")
writer.writeLine(" \"version\": \"${slidesJSversion}\"")
writer.writeLine("}")
}
}
}
createPackageJson.onlyIf {
!file("package.json").exists()
}
task installXslt3(type: Exec, dependsOn: ["createPackageJson"]) {
commandLine "npm", "install", "xslt3"
}
installXslt3.onlyIf {
!file("node_modules/xslt3/xslt3.js").exists()
}
task compileXslt(type: Exec, dependsOn: ["installXslt3"]) {
inputs.file "${projectDir}/src/main/xslt/slides.xsl"
outputs.file "${buildDir}/website/xslt/slides.sef.json"
commandLine "node", "node_modules/xslt3/xslt3.js",
"-t", "-xsl:${projectDir}/src/main/xslt/slides.xsl",
"-export:${buildDir}/website/xslt/slides.sef.json",
"-nogo", "-ns:##html5", "-relocate:on"
doFirst {
mkdir "${buildDir}/website/xslt"
}
}
task compilePrint(type: Exec, dependsOn: ["installXslt3", "copyResources"]) {
inputs.file "${projectDir}/src/main/xslt/print.xsl"
inputs.file "${projectDir}/src/main/index.html"
outputs.file "${buildDir}/website/print.html"
commandLine "node", "node_modules/xslt3/xslt3.js",
"-t", "-s:${projectDir}/src/main/index.html",
"-xsl:${projectDir}/src/main/xslt/print.xsl",
"-o:${buildDir}/website/print.html"
doFirst {
mkdir "${buildDir}/website/xslt"
}
}
task cleanupNode() {
doLast {
delete "package.json"
delete "package-lock.json"
delete "node_modules"
}
}
clean.dependsOn cleanupNode
} else if (xsltCompiler == "XJ") {
if (file(saxonLicenseDir + "/saxon-license.lic").exists()) {
task compileXslt(type: JavaExec) {
inputs.file "${projectDir}/src/main/xslt/slides.xsl"
outputs.file "${buildDir}/website/xslt/slides.sef.json"
classpath = configurations.saxon
mainClass = "com.saxonica.Transform"
args "-t",
"-xsl:${projectDir}/src/main/xslt/slides.xsl",
"-export:${buildDir}/website/xslt/slides.sef.json",
"-target:JS", "-nogo", "-relocate:on", "-ns:##html5"
doFirst {
mkdir "${buildDir}/website/xslt"
}
}
task compilePrint(type: JavaExec, dependsOn: ["copyResources"]) {
inputs.file "${projectDir}/src/main/xslt/print.xsl"
inputs.file "${projectDir}/src/main/index.html"
outputs.file "${buildDir}/website/print.html"
classpath = configurations.saxon
mainClass = "com.saxonica.Transform"
args "-t",
"-s:${projectDir}/src/main/index.html",
"-xsl:${projectDir}/src/main/xslt/print.xsl",
"-o:${buildDir}/website/print.html"
doFirst {
mkdir "${buildDir}/website/xslt"
}
}
} else {
task compileXslt() {
doLast {
println("************************************************************")
println("* You must have a Saxon EE license to use the XJ compiler. *")
println("************************************************************")
}
}
task compilePrint() {
// nop
}
}
} else {
throw new GradleException("The xsltCompiler option must be 'XJ' or 'XX'.")
}
// ============================================================
// Download Saxon JS if necessary
task downloadSaxonJs(type: Download) {
src "https://www.saxonica.com/saxon-js/download/Saxon-JS-${saxonJsVersion}.zip"
dest "${buildDir}"
doFirst {
mkdir(buildDir)
}
}
downloadSaxonJs.onlyIf {
!file("${buildDir}/Saxon-JS-${saxonJsVersion}.zip").exists()
}
task copySaxonJs(type: Copy, dependsOn: ["downloadSaxonJs"]) {
def zipFile = file("${buildDir}/Saxon-JS-${saxonJsVersion}.zip")
from zipTree(zipFile)
into "${buildDir}/website/js"
include "**/*.js"
doFirst {
mkdir "${buildDir}/website"
}
}
copyResources.dependsOn copySaxonJs