-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
338 lines (316 loc) · 11.7 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
import org.neo4j.doc.build.xslt.XsltTask
import org.neo4j.doc.build.docbook.DocBookPlugin
buildscript {
ext {
asciidoctorjVersion = '1.5.6'
asciidoctorjPdfVersion = '1.5.0-alpha.16'
asciidoctorjDiagramVersion = '1.5.4.1'
asciidoctorGroovyDslVersion = '1.0.0.Alpha2'
catalogDir = "$projectDir/docbook/catalog"
}
repositories {
jcenter()
}
dependencies {
classpath "org.asciidoctor:asciidoctorj:$asciidoctorjVersion"
classpath "org.asciidoctor:asciidoctorj-pdf:$asciidoctorjPdfVersion"
classpath "org.asciidoctor:asciidoctorj-diagram:$asciidoctorjDiagramVersion"
classpath "org.asciidoctor:asciidoctorj-groovy-dsl:$asciidoctorGroovyDslVersion"
classpath 'net.sf.docbook:docbook-xsl:1.79.1:ns-resources@zip'
classpath fileTree(dir: "${rootProject.projectDir}/lib", include: '*.jar')
classpath files(catalogDir)
}
}
plugins {
id 'base'
id 'org.neo4j.doc.build.saxon' version '1.0-alpha01'
id 'org.neo4j.doc.build.docbook' version '1.0-alpha03'
}
if (!project.hasProperty('graphAlgoVersion')) { ext.graphAlgoVersion = '3.4.0.0' }
if (!project.hasProperty('neo4jVersion')) { ext.neo4jVersion = '3.4.10' }
ext {
versionParts = graphAlgoVersion.split('-')
versionParts = neo4jVersion.split('-')
versions = [
'graphAlgo' : graphAlgoVersion,
'graphAlgoDocs' : versionParts[0].split('\\.')[0..1].join('.'),
]
if (1 < versionParts.size()) { versions.graphAlgoDocs += '-preview' }
docsBaseUri = "https://neo4j.com/docs"
crossReferenceBase = [
'operations-manual' : "${docsBaseUri}/operations-manual/current",
'developer-manual' : "${docsBaseUri}/developer-manual/current",
'getting-started' : "${docsBaseUri}/getting-started/current",
'graph-algorithms' : "${docsBaseUri}/graph-algorithms/${versions.graphAlgoDocs}",
'java-reference' : "${docsBaseUri}/java-reference/current",
'rest-docs' : "${docsBaseUri}/rest-docs/current",
'kerberos-add-on' : "${docsBaseUri}/add-on/kerberos/current"
]
asciidoctorAttributes = [
'common': [
'doctype' : 'book',
'icons' : 'font',
'attribute-missing' : 'warn',
'docs-version' : versions.graphAlgoDocs,
'common-license-page-uri': "$docsBaseUri/license/",
],
'docbook': [
'imagesdir' : 'images',
],
'html': [
'stylesdir' : 'css',
'linkcss' : '',
'imagesdir' : 'images',
],
'pdf': [
'source-highlighter': 'rouge',
'toc' : '',
'showlinks' : '',
'nonhtmloutput' : '',
]
]
asciidocSourceDir = "$projectDir/asciidoc"
distDir = "$buildDir/distributions"
docId = 'getting-started'
runCommand = { strList ->
assert ( strList instanceof String ||
( strList instanceof List && strList.each{ it instanceof String } ) \
)
def proc = strList.execute()
// proc.in.eachLine { line -> println line }
proc.out.close()
proc.waitFor()
// print "[INFO] ( "
// if(strList instanceof List) {
// strList.each { print "${it} " }
// } else {
// print strList
// }
// println " )"
if (proc.exitValue()) {
println "gave the following error: "
println "[ERROR] ${proc.getErrorStream()}"
}
assert !proc.exitValue()
}
}
def getAsciidoctor() {
if (!project.hasProperty('adoc')) {
org.asciidoctor.groovydsl.AsciidoctorExtensions.extensions {
block(name: 'queryresult', contexts: [':listing']) {
parent, reader, attributes ->
createBlock(parent, 'listing', reader.readLines(), attributes + ['role': 'queryresult'], [:])
}
}
ext.adoc = org.asciidoctor.Asciidoctor.Factory.create()
// asciidoctor.requireLibrary("asciidoctor-diagram")
}
ext.adoc
}
task docbook {
description 'Build DocBook.'
ext.sourceDir = asciidocSourceDir
ext.sourceFile = file("$sourceDir/index.adoc")
ext.outputDir = "$buildDir/docbook/${versions.graphAlgoDocs}"
inputs.dir sourceDir
outputs.dir outputDir
doLast {
def attrs = asciidoctorAttributes.common + asciidoctorAttributes.docbook
def opts = org.asciidoctor.OptionsBuilder.options()
.backend('docbook5')
.safe(org.asciidoctor.SafeMode.UNSAFE)
.toDir(file(outputDir))
.mkDirs(true)
.attributes(attrs)
getAsciidoctor().convertFile(sourceFile, opts.get())
}
doLast {
copy {
from(projectDir) {
include 'images/**'
}
into outputDir
}
}
finalizedBy 'preprocess'
}
preprocess {
dependsOn docbook
def sourceFile = "${buildDir}/docbook/${versions.graphAlgoDocs}/index.xml"
input sourceFile
outFile sourceFile
parameters([
"book-id": "$docId"
])
}
task makeToc(type: XsltTask, dependsOn: docbook) {
description 'Create a table of contents aka complete content map.'
ext.sourceDir = docbook.outputDir
ext.sourceFile = "$sourceDir/index.xml"
ext.outputFile = "$buildDir/docbook/${versions.graphAlgoDocs}/toc.xml"
def outputDir = "$buildDir/docbook/${versions.graphAlgoDocs}/_trash"
def url = DocBookPlugin.getClassLoader().getResource("xsl/create-toc/xhtml/maketoc.xsl")
stylesheet url
input sourceFile
outFile outputFile
sourceSaxParser "org.apache.xml.resolver.tools.ResolvingXMLReader"
stylesheetSaxParser "org.apache.xml.resolver.tools.ResolvingXMLReader"
uriResolver "org.apache.xml.resolver.tools.CatalogResolver"
usingUrls true
usingClasspathUrls true
if (hasProperty('traceDocbook')) { verbose true }
parameters([
"base.dir": "${outputDir}",
"chunk.section.depth": "8",
"chunk.first.sections": "1",
"use.id.as.dirname": "1",
])
}
html {
dependsOn docbook
ext.sourceDir = docbook.outputDir
ext.sourceFile = "$sourceDir/index.xml"
ext.outputDir = "$buildDir/html/${versions.graphAlgoDocs}"
ext.contentMap = "$projectDir/docbook/content-map.xml"
inputs.file sourceFile
inputs.dir 'css'
inputs.dir 'images'
inputs.dir 'javascript'
outputs.dir outputDir
def libraryLinks = [
"Operations_Manual=${crossReferenceBase['operations-manual']}",
"Developer_Manual=${crossReferenceBase['developer-manual']}/",
"Getting_Started=${crossReferenceBase['getting-started']}/",
"Graph_Algorithms=${crossReferenceBase['graph-algorithms']}/",
"Java_Reference=${crossReferenceBase['java-reference']}/",
].join(" ")
def scripts = [
'//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js',
'//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js',
'//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.js',
'//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/addon/runmode/runmode.min.js',
'//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/mode/cypher/cypher.min.js',
'javascript/colorize.js',
'javascript/tabs-for-chunked.js',
'javascript/mp-nav.js',
'javascript/versionswitcher.js',
'javascript/version.js',
'//s3-eu-west-1.amazonaws.com/alpha.neohq.net/docs/new-manual/assets/search.js',
].join(" ")
def styles = [
'//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css',
'//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css',
'//fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,300italic',
'//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.css',
'//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/theme/neo.min.css',
'css/chunked-base.css',
'css/extra.css'
].join(" ")
stylesheet "classpath:xsl/chunk-from-toc/xhtml/chunktoc.xsl"
input sourceFile
// Stylesheet parameters
parameters ([
"base.dir": "${outputDir}",
"html.ext": ".html",
"make.clean.html": "1",
"chunker.output.method": "html",
"chunker.output.indent": "yes",
"use.id.as.dirname": "1",
"neo.documentation.library.links": libraryLinks,
"generate.toc": "''",
"header.rule": "0",
"neo.newsearch": "1",
"html.script": scripts,
"html.stylesheet": styles,
"chunk.toc": "${contentMap}",
"current.docid": "$docId",
])
doLast {
copy {
from(docbook.outputDir) {
include 'images/**'
}
from(projectDir) {
include 'javascript/**'
include 'css/**'
}
into outputDir
}
}
}
task asciidoctorHtml {
description 'Build HTML'
ext.sourceDir = asciidocSourceDir
ext.sourceFile = file("$sourceDir/index.adoc")
ext.outputDir = "$buildDir/asciidoctor-html/${versions.graphAlgoDocs}"
inputs.dir sourceDir
outputs.dir outputDir
doLast {
def attrs = asciidoctorAttributes.common + asciidoctorAttributes.html
def opts = org.asciidoctor.OptionsBuilder.options()
.backend('html5')
.safe(org.asciidoctor.SafeMode.UNSAFE)
.toDir(file(outputDir))
.mkDirs(true)
.attributes(attrs)
getAsciidoctor().convertFile(sourceFile, opts.get())
}
doLast {
copy {
from(projectDir) {
include 'images/**'
}
into outputDir
}
}
}
task packageHtml(type: Tar, dependsOn: html) {
description 'Package HTML for distribution.'
baseName 'graph-algorithms'
extension 'tar.gz'
version versions.graphAlgoDocs
compression = Compression.GZIP
from { html }
into "$baseName/$version"
destinationDir file(distDir)
}
task pdf {
description 'Build PDF.'
ext.sourceDir = asciidocSourceDir
ext.sourceFile = file("$sourceDir/index.adoc")
ext.outputDir = "$buildDir/pdf"
ext.outputFilename = "neo4j-graph-algorithms-${versions.graphAlgoDocs}.pdf"
ext.outputFile = "$outputDir/$outputFilename"
ext.imagesDir = "$outputDir/images"
ext.imagesOutDir = imagesDir
inputs.dir sourceDir
outputs.file outputFile
doFirst {
copy {
from (projectDir) {
include 'images/*'
}
into(outputDir)
}
}
doLast {
// asciidoctor-diagram 1.5.4.1 breaks asciidoctor-pdf: using OptionsBuilder#toFile() (-o, --out-file), the file path
// is created as a directory, and 'imagesoutdir' is resolved wrongly.
// Work around by using #toDir (-D, --destination-dir) and manually renaming the output file.
// See https://github.com/asciidoctor/asciidoctor-pdf/issues/842
def attrs = asciidoctorAttributes.common + asciidoctorAttributes.pdf + [
'imagesdir' : imagesDir.toString(),
'imagesoutdir' : imagesOutDir.toString(),
]
def opts = org.asciidoctor.OptionsBuilder.options()
.backend('pdf')
.safe(org.asciidoctor.SafeMode.UNSAFE)
// .toFile(file(outputFile)) // workaround
.toDir(file(outputDir)) // workaround
.mkDirs(true)
.attributes(attrs)
getAsciidoctor().convertFile(sourceFile, opts.get())
file("$outputDir/index.pdf").renameTo(outputFile) // workaround
}
}
// vim: set fdm=expr: