File: docs.gradle

package info (click to toggle)
gradle 4.4.1-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 85,488 kB
  • sloc: java: 319,990; xml: 14,356; javascript: 4,838; cpp: 4,200; ansic: 1,025; sh: 303; makefile: 66; asm: 17; jsp: 17; objc: 10
file content (513 lines) | stat: -rwxr-xr-x 18,102 bytes parent folder | download | duplicates (4)
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513

/*
 * Copyright 2010 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.build.docs.AssembleSamplesDocTask
import org.gradle.build.docs.CacheableAsciidoctorTask
import org.gradle.build.docs.Docbook2Xhtml
import org.gradle.build.docs.ExtractSamplesTask
import org.gradle.build.docs.ExtractSnippetsTask
import org.gradle.build.docs.UserGuideSectionVerifier
import org.gradle.build.docs.UserGuideTransformTask
import org.gradle.build.docs.Xhtml2Pdf
import org.gradle.build.docs.dsl.docbook.AssembleDslDocTask
import org.gradle.build.docs.dsl.source.ExtractDslMetaDataTask
import org.gradle.build.docs.dsl.source.GenerateDefaultImportsTask
import org.gradle.build.docs.releasenotes.*
import org.gradle.build.docs.releasenotes.checks.*
import org.gradle.plugins.pegdown.PegDown

import javax.xml.transform.TransformerFactory
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.stream.StreamSource

apply plugin: 'base'
apply plugin: 'pegdown'
apply plugin: 'jsoup'
apply plugin: 'javascript-base'
apply plugin: 'org.asciidoctor.convert'

repositories {
    javaScript.googleApis()

    ivy {
        name "Google Fonts"
        url "http://themes.googleusercontent.com/static/fonts/"
        layout 'pattern', {
            artifact '[organisation]/v[revision](/[classifier])(.[ext])'
            ivy '[organisation]/v[revision]/ivy(.[ext])'
        }
    }

    maven { url 'https://repo.gradle.org/gradle/gradle-build-internal' }
}

configurations {
    userGuideStyleSheets
    userGuideTask
    jquery
    jqueryTipTip
    fonts
}

dependencies {
    asciidoctor 'org.asciidoctor:asciidoctorj:1.5.6'

    userGuideTask 'xalan:xalan:2.7.1', libraries.xerces
    userGuideTask module('xhtmlrenderer:xhtmlrenderer:R8rc1') {
        dependency 'itext:itext:2.0.8@jar'
    }
    userGuideTask 'xslthl:xslthl:2.0.1@jar'

    userGuideStyleSheets 'docbook:docbook-xsl:1.75.2@zip'
    jquery "jquery:jquery.min:1.8.0@js"
    jqueryTipTip "com.drewwilson.code:jquery.tipTip:1.3:minified@js"

    fonts \
        "lato:regular:6:v0SdcGFAl2aezM9Vq_aFTQ@ttf",
        "lato:regular-italic:6:LqowQDslGv4DmUBAfWa2Vw@ttf",
        "lato:bold:6:DvlFBScY1r-FMtZSYIYoYw@ttf",
        "lato:bold-italic:6:HkF_qI1x_noxlxhrhMQYEKCWcynf_cDxXwCLxiixG1c@ttf",
        "ubuntumono:regular:3:ViZhet7Ak-LRXZMXzuAfkZ0EAVxt0G0biEntp43Qt6E@ttf",
        "ubuntumono:regular-italic:3:KAKuHXAHZOeECOWAHsRKA-LrC4Du4e_yfTJ8Ol60xk0@ttf",
        "ubuntumono:bold:3:ceqTZGKHipo8pJj4molytp_TkvowlIOtbR7ePgFOpF4@ttf",
        "ubuntumono:bold-italic:3:n_d8tv_JOIiYyMXR4eaV9WsGzsqhEorxQDpu60nfWEc@ttf"

    testCompile "org.pegdown:pegdown:1.1.0"
    testCompile libraries.jsoup
    testCompile "org.gebish:geb-spock:0.9.3"
    testCompile('org.seleniumhq.selenium:selenium-htmlunit-driver:2.42.2') {
        exclude group: 'org.apache.httpcomponents'
    }
    testCompile libraries.commons_httpclient
    testCompile 'org.apache.httpcomponents:httpmime:4.4.1'
    testCompile project(":core")
}

ext {
    srcDocsDir = file('src/docs')
    userguideSrcDir = new File(srcDocsDir, 'userguide')
    asciidocSanitizeStylesheet = file("$srcDocsDir/stylesheets/asciidocSanitize.xsl")
    asciidocOutputDir = new File(buildDir, 'asciidoc/userguide')
    dslSrcDir = new File(srcDocsDir, 'dsl')
    docsDir = file("$buildDir/docs")
    userguideDir = new File(docsDir, 'userguide')
    distDocsDir = new File(buildDir, 'distDocs')
    samplesDir = file("$buildDir/samples")
    docbookSrc = new File(project.buildDir, 'src')
    samplesSrcDir = file('src/samples')
}

ext.outputs = [:]
outputs.samples = files(samplesDir) {
    builtBy 'samples'
}
outputs.distDocs = files(distDocsDir) {
    builtBy 'distDocs'
}
outputs.docs = files(docsDir) {
    builtBy 'javadocAll', 'userguide', 'dslHtml', 'releaseNotes'
}

tasks.withType(CacheableAsciidoctorTask) {
    backends = ['docbook']
    separateOutputDirs = false
    options doctype: 'book'
    inputs.file asciidocSanitizeStylesheet withPropertyName "sanitizerStylesheet" withPathSensitivity PathSensitivity.NONE

    extensions {
        inlinemacro (name: "api") {
            parent, target, attributes ->
            def (className, method) = target.split('#', 2) as List
            def content = "<apilink class=\"$className\""
            if (method) {
                // Add space after comma, because we can't have spaces in api: targets
                // Restore Asciidoc's '&hellip;&zwsp;' replacement to the original '...'
                content += " method=\"${method.replaceAll(/,\s*/, ', ').replaceAll(/\&#8230;\&#8203;/, '...')}\""
            }
            content += " />"
            return content
        }
    }

    attributes website: 'http://www.gradle.org'

    doLast {
        outputDir.eachFileMatch(~/.*.xml/) { File file ->
            def contents = file.getText("utf-8")
            try {
                def transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(asciidocSanitizeStylesheet))
                transformer.transform(new StreamSource(new StringReader(contents)), new StreamResult(file))
            } catch (Exception ex) {
                throw new RuntimeException("Couldn't process $file:\n" + contents, ex)
            }
        }
    }
}

tasks.withType(Docbook2Xhtml) {
    dependsOn userguideStyleSheets
    classpath = configurations.userGuideTask
    stylesheetsDir = userguideStyleSheets.destinationDir
}

tasks.withType(UserGuideTransformTask) {
    dependsOn samples, dslDocbook
    snippetsDir = samples.snippetsDir
    linksFile = dslDocbook.linksFile
    websiteUrl = 'http://www.gradle.org'

    if (name in ["pdfUserguideDocbook"]) {
        // These will only be valid for releases, but that's ok
        javadocUrl = "http://www.gradle.org/docs/${->version}/javadoc"
        dsldocUrl = "http://www.gradle.org/docs/${->version}/dsl"
    } else {
        javadocUrl = '../javadoc'
        dsldocUrl = '../dsl'
    }
}

tasks.withType(AssembleDslDocTask) {
    classDocbookDir = dslSrcDir
}

task configureCss {
    doLast {
        def images = fileTree(dir: "src/docs/css/images", include: "*.*").files.collectEntries {
            [it.name, it.bytes.encodeBase64().toString()]
        }

        def fonts = configurations.fonts.resolvedConfiguration.resolvedArtifacts.collectEntries {
            def id = it.moduleVersion.id
            ["${id.group}-${id.name}".toString(), it.file.bytes.encodeBase64().toString()]
        }

        ext.tokens = images + fonts
        css.inputs.property 'tokens', tokens
        css.filter ReplaceTokens, tokens: tokens
    }
}

task css(type: Sync, dependsOn: configureCss) {
    into "$buildDir/css"
    from "src/docs/css"
    include "*.css"
    include "*.svg"
}

ext.cssFiles = fileTree(css.destinationDir) {
    builtBy css
}

task samples(type: ExtractSnippetsTask) {
    samples = samplesSrcDir
    destDir = samplesDir
    excludes = ['userguideOutput/**',
                '**/readme.xml',
                '**/build/**',
                '**/.gradle/**']
    nonFiltered = [ 'userguide/tutorial/antLoadfileResources/**',
                    'native-binaries/cunit/libs/**',
                    'native-binaries/google-test/libs/**' ]
    snippetsDir = new File(buildDir, 'snippets')
}

task userguideStyleSheets(type: Copy) {
    File stylesheetsDir = new File(srcDocsDir, 'stylesheets')
    into new File(buildDir, 'stylesheets')
    from(stylesheetsDir) {
        include '*.xsl'
    }
    from(cssFiles)
    from({ zipTree(configurations.userGuideStyleSheets.singleFile) }) {
        // Remove the prefix
        eachFile { fcd -> fcd.path = fcd.path.replaceFirst('^docbook-xsl-[0-9\\.]+/', '') }
    }
}

tasks.remove(asciidoctor)

task userguideAsciidoc(type: CacheableAsciidoctorTask) {
    sourceDir = userguideSrcDir
    sources { include '*.adoc' }
    outputDir = asciidocOutputDir
    inputs.file { defaultImports.importsDestFile } withPropertyName 'defaultImports' withPathSensitivity PathSensitivity.NONE

    // we pull the default-imports from here:
    resources {
        from(generatedResourcesDir)
        include "**/*.txt"
    }
}

task samplesDocbook(type: AssembleSamplesDocTask) {
    source samplesSrcDir
    include '**/readme.xml'
    destFile = new File(docbookSrc, 'samplesList.xml')
}

task samplesDocs(type: Docbook2Xhtml) {
    source samplesDocbook
    destFile = new File(samples.destDir, 'readme.html')
    stylesheetName = 'standaloneHtml.xsl'
}

task dslMetaData(type: ExtractDslMetaDataTask) {
    source { javadocAll.source }
    destFile = new File(docbookSrc, 'dsl-meta-data.bin')
}

task dslDocbook(type: AssembleDslDocTask, dependsOn: [dslMetaData]) {
    sources = fileTree(dir: dslSrcDir, includes: ['*.xml'])
    sourceFile = new File(dslSrcDir, 'dsl.xml')
    classMetaDataFile = dslMetaData.destFile
    pluginsMetaDataFile = new File(dslSrcDir, 'plugins.xml')
    destFile = new File(docbookSrc, 'dsl.xml')
    linksFile = new File(docbookSrc, 'api-links.bin')
}

task defaultImports(type: GenerateDefaultImportsTask, dependsOn: dslMetaData) {
    metaDataFile = dslMetaData.destFile
    importsDestFile = new File(generatedResourcesDir, "default-imports.txt")
    mappingDestFile = new File(generatedResourcesDir, "api-mapping.txt")
    // These are part of the API, but not the DSL
    excludePackage 'org.gradle.tooling.**'
    excludePackage 'org.gradle.testfixtures.**'

    // Tweak the imports due to some inconsistencies introduced before we automated the default-imports generation
    excludePackage 'org.gradle.plugins.ide.eclipse.model'
    excludePackage 'org.gradle.plugins.ide.idea.model'
    excludePackage 'org.gradle.api.tasks.testing.logging'

    // TODO - rename some incubating types to remove collisions and then remove these exclusions
    excludePackage 'org.gradle.plugins.binaries.model'

    // Exclude classes that were moved in a different package but the deprecated ones are not removed yet
    excludePackage 'org.gradle.platform.base.test'
}

task dslStandaloneDocbook(type: UserGuideTransformTask, dependsOn: [dslDocbook]) {
    sourceFile = dslDocbook.destFile
    destFile = new File(docbookSrc, 'dsl-standalone.xml')
    dsldocUrl = '.'
}

task dslHtml(type: Docbook2Xhtml) {
    group = "Documentation"
    source dslStandaloneDocbook
    destDir = new File(docsDir, 'dsl')
    stylesheetName = 'dslHtml.xsl'
    resources = cssFiles + fileTree(dslSrcDir) {
        include '*.js'
    }
    ext.entryPoint = "$destDir/index.html"
}

task checkSectionIds(type: UserGuideSectionVerifier) {
    dependsOn userguideAsciidoc
    docbookFiles = files(
        fileTree(userguideSrcDir) { include "**/*.xml" },
        userguideAsciidoc.outputs.files
    )
}

[configureCss, samples, samplesDocbook]*.mustRunAfter(checkSectionIds)

task extractSamples(type: ExtractSamplesTask) {
    // We need default imports since it is included by userguide.xml
    // We need samplesList.xml (generated by samplesDocbook) since it is included by userguide.xml
    // Both files are not an input since they do not affect the generated samples.xml
    dependsOn defaultImports, samplesDocbook, userguideAsciidoc
    sourceFile = new File(userguideSrcDir, 'userguide.xml')
    destFile = new File(docbookSrc, 'samples.xml')
}

// This is used in the distribution and for the online version
task userguideDocbook(type: UserGuideTransformTask) {
    destFile = new File(docbookSrc, 'userguide.xml')
    dependsOn checkSectionIds
}

// This is used for the PDF, where we need absolute links to the javadoc etc.
task pdfUserguideDocbook(type: UserGuideTransformTask) {
    destFile = new File(docbookSrc, 'remoteUserguide.xml')
}

configure([userguideDocbook, pdfUserguideDocbook]) {
    // The master userguide.xml pulls these files in via xi:include, making them input
    includes = files(
        samplesDocbook,
        defaultImports.importsDestFile,
        fileTree(dir: userguideSrcDir, includes: ['*.xml']),
        userguideAsciidoc.outputs.files
    )

    dependsOn samples, samplesDocbook, defaultImports

    sourceFile new File(userguideSrcDir, 'userguide.xml')
}

def imageFiles = fileTree(userguideSrcDir) {
    include 'img/*.png'
    include 'img/*.gif'
    include 'img/*.jpg'
}
def resourceFiles = imageFiles + cssFiles

task userguideHtml(type: Docbook2Xhtml) {
    group = "Documentation"
    source userguideDocbook
    destDir = userguideDir
    stylesheetName = 'userGuideHtml.xsl'
    resources = resourceFiles
    ext.entryPoint = "$destDir/userguide.html"
}

task userguideSingleHtml(type: Docbook2Xhtml) {
    group = "Documentation"
    source userguideDocbook
    destFile = new File(userguideDir, 'userguide_single.html')
    stylesheetName = 'userGuideSingleHtml.xsl'
    resources = resourceFiles
    ext.entryPoint = destFile
}

task pdfUserguideXhtml(type: Docbook2Xhtml) {
    source pdfUserguideDocbook
    destFile = new File(buildDir, 'tmp/userguidePdf/userguidePdf.html')
    stylesheetName = 'userGuidePdf.xsl'
    resources = resourceFiles
    ext.entryPoint = destFile
}

task userguidePdf(type: Xhtml2Pdf, dependsOn: pdfUserguideXhtml) {
    sourceFile = pdfUserguideXhtml.destFile
    destFile = new File(userguideDir, 'userguide.pdf')
    classpath = configurations.userGuideTask
    resources = resourceFiles
}

def javaApiUrl = "https://docs.oracle.com/javase/7/docs/api"
def groovyApiUrl = "http://docs.groovy-lang.org/docs/groovy-${versions.groovy}/html/gapi"
def mavenApiUrl = "http://maven.apache.org/ref/${versions.maven}/maven-model/apidocs"

task javadocAll(type: Javadoc) {
    ext.stylesheetFile = file("src/docs/css/javadoc.css")
    inputs.file stylesheetFile withPropertyName "stylesheetFile" withPathSensitivity PathSensitivity.NAME_ONLY

    group = 'documentation'
    options.encoding = 'utf-8'
    options.docEncoding = 'utf-8'
    options.charSet = 'utf-8'
    if (javaVersion.isJava8Compatible()) {
        options.addStringOption 'Xdoclint:syntax,html,reference', '-quiet'
    }
    options.addStringOption "stylesheetfile", stylesheetFile.absolutePath
    source publicGroovyProjects.collect {project -> project.sourceSets.main.allJava }
    destinationDir = new File(docsDir, 'javadoc')
    classpath = files(publicGroovyProjects.collect {project -> [project.sourceSets.main.compileClasspath, project.sourceSets.main.output] })
    publicApiIncludes.each {
        include it
    }
    publicApiExcludes.each {
        exclude it
    }
    options.links(javaApiUrl, groovyApiUrl, mavenApiUrl)
    title = "Gradle API $version"
    ext.entryPoint = "$destinationDir/index.html"
}

task checkstyleApi(type: Checkstyle) {
    source javadocAll.source
    configFile = new File(checkstyle.configDir, "checkstyle-api.xml")
    classpath = files()
    reports.xml.destination = file("$checkstyle.reportsDir/checkstyle-api.xml")
}

task distDocs(type: Docbook2Xhtml) {
    dependsOn userguideAsciidoc
    source new File(asciidocOutputDir, 'gettingStarted.xml')
    destFile = new File(distDocsDir, 'getting-started.html')
    stylesheetName = 'standaloneHtml.xsl'
}

task userguide {
    dependsOn userguideHtml, userguideSingleHtml, userguidePdf
    description = 'Generates the userguide'
    group = 'documentation'
}

task editReleaseNotes() {
    group = "release notes"
    doLast {
        Class.forName("java.awt.Desktop").newInstance().edit(file("src/docs/release/notes.md"))
    }
}

task releaseNotesMarkdown(type: PegDown) {
    group = "release notes"
    markdownFile = file("src/docs/release/notes.md")
    destination = new File(buildDir, "release-notes-raw/release-notes.html")
}

task releaseNotes(type: Copy) {
    group = "release notes"
    ext.fileName = "release-notes.html"
    into "$docsDir"
    from releaseNotesMarkdown
    jsoup.plugins "src/transforms/release-notes.gradle"
    filter(ReplaceTokens, tokens: [version: project.version.toString(), baseVersion: rootProject.baseVersion])
    ext.entryPoint = file("$docsDir/$fileName")
}

tasks.addRule("view«Doc Task Name» - Opens entry point") { String taskName ->
    if (taskName.startsWith("view")) {
        def realTaskName = (taskName - "view")
        realTaskName = realTaskName[0].toLowerCase() + realTaskName[1..-1]
        def task = tasks.findByName(realTaskName)
        if (task && task.hasProperty("entryPoint")) {
            tasks.create(taskName) {
                dependsOn task
                doLast {
                    Class.forName("java.awt.Desktop").newInstance().browse(file(task.entryPoint).toURI())
                }
            }
        }
    }
}

sourceSets.main.output.dir generatedResourcesDir, builtBy: defaultImports

['test', 'java9Test'].each {
    tasks[it].configure {
        dependsOn releaseNotes
        inputs.files releaseNotesMarkdown.markdownFile withPropertyName "releaseNotesSource" withPathSensitivity PathSensitivity.NONE
        inputs.dir releaseNotes.destinationDir withPropertyName "releaseNotesRendered" withPathSensitivity PathSensitivity.NONE
        inputs.property "systemProperties", [:]
        systemProperty "org.gradle.docs.releasenotes.source", releaseNotesMarkdown.markdownFile
        systemProperty "org.gradle.docs.releasenotes.rendered", new File(releaseNotes.destinationDir, releaseNotes.fileName)
    }
}

task docs {
    dependsOn javadocAll, userguide, distDocs, samplesDocs, dslHtml, releaseNotes
    description = 'Generates all documentation'
    group = 'documentation'
}

task docsZip(type: Zip) {
    from project.outputs.docs
}