-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
203 lines (182 loc) · 5.33 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
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)
}
// Set saxonLicenseDir in gradle.properties, or from the
// command line if you have a license in some other place.
if (!hasProperty("saxonLicenseDir")) {
ext.saxonLicenseDir=System.getenv('HOME') + "/java"
}
dependencies {
implementation (
[group: "com.saxonica", name: "Saxon-EE", version: saxonVersion]
)
saxon (
files(saxonLicenseDir)
)
}
defaultTasks 'publish'
// This task runs a simple Python web server. It requires that you
// have python installed. If you don't want to use this server, you
// can use any web server that you want, just configure it to serve
// the files in build/website.
task server(type: Exec, dependsOn: ["publish"]) {
commandLine "${pythonExecutable}",
"-m", "http.server",
"--directory", "${buildDir}/website",
serverPort
doFirst {
println("Starting web server; open http://localhost:${serverPort}/ in your browser")
}
}
task publish(dependsOn: ["copyResources", "compileXslt"]) {
doLast {
println("Pages published in ${buildDir}")
}
}
task copyResources() {
// Just somewhere to hang dependencies
}
["html", "css", "js", "xml"].each { subdir ->
def target = "${buildDir}/website/${subdir}"
if (subdir == "html") {
// html is special
target = "${buildDir}/website"
}
Task t = task "copy_${subdir}"(type: Copy) {
from "${projectDir}/src/main/${subdir}"
into target
doFirst {
mkdir "${buildDir}/website"
}
}
copyResources.dependsOn t
}
if (xsltCompiler == "XX") {
task createPackageJson() {
doLast {
new File("package.json")
.withWriter("utf-8") { writer ->
writer.writeLine("{")
writer.writeLine(" \"name\": \"${helloWorldName}\",")
writer.writeLine(" \"version\": \"${helloWorldVersion}\"")
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", "copy_html"]) {
inputs.file "${projectDir}/src/main/xslt/stylesheet.xsl"
outputs.file "${buildDir}/website/xslt/stylesheet.sef.json"
commandLine "node", "node_modules/xslt3/xslt3.js",
"-t", "-xsl:${projectDir}/src/main/xslt/stylesheet.xsl",
"-export:${buildDir}/website/xslt/stylesheet.sef.json",
"-nogo", "-ns:##html5"
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()) {
// We can compile the stylesheet
task doCompileXslt(type: JavaExec) {
inputs.file "${projectDir}/src/main/xslt/stylesheet.xsl"
outputs.file "${buildDir}/website/xslt/stylesheet.sef.json"
classpath = configurations.saxon
mainClass = "com.saxonica.Transform"
args "-t",
"-xsl:${projectDir}/src/main/xslt/stylesheet.xsl",
"-export:${buildDir}/website/xslt/stylesheet.sef.json",
"-target:JS", "-nogo", "-relocate:on", "-ns:##html5"
doFirst {
mkdir "${buildDir}/website/xslt"
}
}
// Keep the precompiled version up-to-date
task compileXslt(type: Copy, dependsOn: ["doCompileXslt", "copy_html"]) {
from "${buildDir}/website/xslt"
into "${projectDir}/precompiled"
}
} else {
task compileXslt(type: Copy) {
from "${projectDir}/precompiled"
into "${buildDir}/website/xslt"
doFirst {
mkdir "${buildDir}/website/xslt"
}
doLast {
println("**************************************************************************")
println("* Using pre-compiled stylesheets; ignoring any changes to stylesheet.xsl *")
println("**************************************************************************")
}
}
}
} 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