forked from Saxonica/weblog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
230 lines (198 loc) · 5.53 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
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://dev.saxonica.com/maven" }
}
dependencies {
classpath group: 'net.sf.saxon', name: 'Saxon-HE', version: saxonVersion
}
}
plugins {
id "java"
id 'com.nwalsh.gradle.saxon.saxon-gradle' version '0.10.2'
}
import com.nwalsh.gradle.saxon.SaxonXsltTask
repositories {
mavenLocal()
mavenCentral()
}
configurations.all {
resolutionStrategy {
force 'xml-apis:xml-apis:1.4.01'
}
}
configurations {
saxonee.extendsFrom(implementation)
validateRuntime.extendsFrom(implementation)
projectImplementationClasspath.extendsFrom(implementation)
projectRuntimeClasspath.extendsFrom(runtimeOnly)
}
dependencies {
implementation (
[group: 'net.sf.saxon', name: 'Saxon-HE', version: saxonVersion],
)
}
ext {
linkCheck = "true".equals(project.property('linkCheck'))
}
defaultTasks 'publishWeblog'
def weblogAuthors = ['announcements': 'announcements',
'mike': 'michael-kay',
'oneil': 'oneil-delpratt',
'norm': 'norm-tovey-walsh']
def gitRef(post) {
def ref = ""
def proc = "git log -1 --format=\"%aI %h\" src/${post}".execute()
proc.in.eachLine { line ->
ref = line
}
proc.err.eachLine { line ->
println(line)
}
proc.waitFor()
ref
}
def heAvailable=true
def eeAvailable=false
def peAvailable=false
configurations.saxonee.each { it ->
def filename = it.toString().toLowerCase()
eeAvailable = eeAvailable || filename.contains("saxon-ee")
peAvailable = peAvailable || filename.contains("saxon-pe")
}
configurations.compileClasspath.each { it ->
def filename = it.toString().toLowerCase()
eeAvailable = eeAvailable || filename.contains("saxon-ee")
peAvailable = peAvailable || filename.contains("saxon-pe")
}
if (saxonEE == "true" && !(eeAvailable || peAvailable)) {
println("Request for SAXON EE ignored; neither EE nor PE appear to be available")
}
// This is all a complete hack that I worked out by trial and error
def EXCP="${projectDir}/build/classes/java/main"
if (saxonEE != "false" && (eeAvailable || peAvailable)) {
configurations.saxonee.each { it ->
EXCP += ":" + it
}
} else {
configurations.compileClasspath.each { it ->
EXCP += ":" + it
}
}
task publishHtml() {
// nop
}
def weblogPosts = [:]
weblogAuthors.each { item ->
def author = item.key
def basepath = "${projectDir}/src/${author}/"
def baselen = basepath.length()
fileTree(dir: "src/${author}").each { file ->
def path = file.toString().substring(baselen)
if (path ==~ /(\d+)\/(\d+)\/.*\.html$/) {
// A proper string, not a Groovy GString
def key = "${author}/${path}".toString()
weblogPosts.put(key, file.toString())
def taskId = key.replace("/", "_").replace("-", "_")
Task t = task "${taskId}"(type: SaxonXsltTask, dependsOn: ["updateNavigation"]) {
inputs.file "${buildDir}/navigation.xml"
inputs.file "${projectDir}/xslt/format.xsl"
input file.toString()
output "${buildDir}/docs/${key}"
stylesheet "${projectDir}/xslt/post.xsl"
}
publishHtml.dependsOn t
}
}
}
def everythingElse = []
fileTree(dir: "src/").each { file ->
def baselen = "${projectDir}/src".length() + 1
def path = file.toString().substring(baselen)
if (!weblogPosts.containsKey(path)) {
everythingElse += path
}
}
task configureEnvironment() {
def envVars = [:]
envVars['SAXON_CP'] = EXCP
envVars['VERBOSE'] = verbose
tasks.withType(Exec) {
environment << envVars
}
}
task copyResources(type: Copy) {
from "src/"
into "${buildDir}/docs/"
include everythingElse
doFirst {
mkdir "${buildDir}/docs"
}
}
task updateNavigation(type: SaxonXsltTask) {
inputs.files weblogPosts.values()
stylesheet "${projectDir}/xslt/navigate.xsl"
output "${buildDir}/navigation.xml"
args(["-it"])
}
task atomize(type: SaxonXsltTask, dependsOn: ["updateNavigation"]) {
input "${buildDir}/navigation.xml"
stylesheet "${projectDir}/xslt/atom.xsl"
output "${buildDir}/docs/atom.xml"
}
weblogAuthors.each { item ->
def blog = item.key
def aid = item.value
task "atomize-${blog}"(type: SaxonXsltTask, dependsOn: ["updateNavigation"]) {
input "${buildDir}/navigation.xml"
stylesheet "${projectDir}/xslt/atom.xsl"
output "${buildDir}/docs/${blog}/atom.xml"
parameters([
'author-id': aid
])
}
atomize.dependsOn("atomize-${blog}")
}
task gitData(type: Exec) {
inputs.files fileTree(dir: "src")
inputs.file "bin/git-data"
outputs.file "build/git-data.txt"
commandLine "bin/git-data", "${buildDir}/git-data.txt"
doFirst {
mkdir("build")
}
}
task sitemap(type: SaxonXsltTask, dependsOn: ["gitData"]) {
inputs.file "${buildDir}/git-data.txt"
stylesheet "${projectDir}/xslt/sitemap.xsl"
output "${buildDir}/docs/sitemap.xml"
args(['-it'])
}
task publishWeblog(
type: SaxonXsltTask,
dependsOn: ["copyResources", "atomize",
"publishHtml", "sitemap"]
) {
outputs.file "${buildDir}/docs/index.html"
outputs.file "${buildDir}/docs/archive.html"
input "${buildDir}/navigation.xml"
stylesheet "${projectDir}/xslt/indexes.xsl"
if (linkCheck) {
doLast {
exec {
commandLine pythonExecutable,
'bin/linkcheck.py', '--debug', '-s', 'build/docs'
}
}
}
}
task server(type: Exec, dependsOn: ["publishWeblog"]) {
commandLine pythonExecutable,
"-m", "http.server",
"--directory", "${buildDir}/docs",
serverPort
doFirst {
println("Starting web server; open http://localhost:${serverPort}/ in your browser")
}
}