-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
175 lines (156 loc) · 4.34 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
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'
task publish(
dependsOn: ['compileXslt', 'copyResources']
) {
// Just a place to hang dependencies
}
if (xsltCompiler == "XX") {
task createPackageJson() {
doLast {
new File("package.json")
.withWriter("utf-8") { writer ->
writer.writeLine("{")
writer.writeLine(" \"name\": \"${projectName}\",")
writer.writeLine(" \"version\": \"${projectVersion}\"")
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", "copyResources"]
) {
inputs.file "${projectDir}/src/main/xsl/dashboard.xsl"
outputs.file "${buildDir}/dist/xsl/dashboard.sef.json"
commandLine "node", "node_modules/xslt3/xslt3.js",
"-t", "-xsl:${projectDir}/src/main/xsl/dashboard.xsl",
"-export:${compileXslt.outputs.getFiles().getSingleFile()}",
"-nogo", "-ns:##html5"
doFirst {
mkdir "${buildDir}/dist/xsl"
}
}
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 compileXslt(
type: JavaExec,
dependsOn: ["copyResources"]
) {
inputs.file "${projectDir}/src/main/xsl/dashboard.xsl"
outputs.file "${buildDir}/dist/xsl/dashboard.sef.json"
classpath = configurations.saxon
mainClass = "com.saxonica.Transform"
args "-t",
"-xsl:${projectDir}/src/main/xsl/dashboard.xsl",
"-export:${compileXslt.outputs.getFiles().getSingleFile()}",
"-target:JS", "-nogo", "-relocate:on", "-ns:##html5"
}
} else {
throw new GradleException("You must provide a license for the XJ compiler.")
}
} else {
throw new GradleException("The xsltCompiler option must be 'XJ' or 'XX'.")
}
task copyResources() {
doLast {
copy {
into "${buildDir}/dist"
from "${projectDir}/src/main"
exclude "xsl"
exclude "html"
}
}
doLast {
copy {
into "${buildDir}/dist"
from "${projectDir}/src/main/html"
}
}
}
// ============================================================
// 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}/dist",
serverPort
doFirst {
println("Starting web server; open http://localhost:${serverPort}/ in your browser")
}
}
// ============================================================
// Download Saxon JS if necessary
task downloadSaxonJs(type: Download) {
src "https://www.saxonica.com/saxon-js/download/SaxonJS-${saxonJsVersion}.zip"
dest "${buildDir}"
doFirst {
mkdir(buildDir)
}
}
downloadSaxonJs.onlyIf {
!file("${buildDir}/SaxonJS-${saxonJsVersion}.zip").exists()
}
task copySaxonJs(type: Copy, dependsOn: ["downloadSaxonJs"]) {
def zipFile = file("${buildDir}/SaxonJS-${saxonJsVersion}.zip")
from zipTree(zipFile)
into "${buildDir}/dist/js"
include "**/*.js"
doFirst {
mkdir "${buildDir}/dist"
}
}
copyResources.dependsOn copySaxonJs