Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 518 lines (446 sloc) 17.9 KB
/*
* 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.gradlebuild.BuildEnvironment
import org.gradle.gradlebuild.ProjectGroups
import org.gradle.gradlebuild.PublicApi
import org.gradle.gradlebuild.docs.PegDown
import org.gradle.gradlebuild.unittestandcompile.ModuleType
import javax.xml.transform.TransformerFactory
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.stream.StreamSource
plugins {
id 'base'
id 'gradlebuild.jsoup'
id 'javascript-base'
id 'org.asciidoctor.convert'
}
repositories {
javaScript.googleApis()
}
configurations {
userGuideStyleSheets
userGuideTask
jquery
jqueryTipTip
cssElements {
// define an outgoing configuration, aimed at consumers looking
// for CSS resources
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage, 'css-resources'))
}
canBeResolved = false
canBeConsumed = true
}
}
dependencies {
userGuideTask 'xalan:xalan:2.7.1', 'xerces:xercesImpl:2.11.0'
userGuideTask 'xhtmlrenderer:xhtmlrenderer:R8rc1'
userGuideTask 'itext:itext:2.0.8'
userGuideTask 'xslthl:xslthl:2.0.1'
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"
testCompile "org.pegdown:pegdown:1.1.0"
testCompile testLibraries.jsoup
testCompile "org.gebish:geb-spock:0.9.3"
testCompile('org.seleniumhq.selenium:selenium-htmlunit-driver:2.42.2')
testCompile libraries.commons_httpclient.coordinates
testCompile "org.apache.httpcomponents:httpmime:${libraries.commons_httpclient.version}"
testCompile project(":core")
}
gradlebuildJava {
moduleType = ModuleType.PLUGIN
}
ext {
srcDocsDir = file('src/docs')
releaseFeaturesFile = file("$srcDocsDir/release/release-features.txt")
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 'source-highlighter': 'prettify',
website: 'http://www.gradle.org',
javaApi: 'https://docs.oracle.com/javase/7/docs/api',
antManual: 'https://ant.apache.org/manual',
gradleVersion: version
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 tokens = fileTree(dir: "src/docs/css/images", include: "*.*").collectEntries {
[it.name, it.bytes.encodeBase64().toString()]
}
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"
}
artifacts {
// declare that the generated css directory is an output of cssElements
cssElements file: css.destinationDir, builtBy: css
}
// TODO This is a hack pending a solution to https://github.com/gradle/gradle/issues/4612
// Don't publish the CSS artifacts when calling uploadArchives
configurations.archives.artifacts.removeAll(configurations.cssElements.artifacts)
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 '**/*.xml'
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)
def generatedResourcesDir = gradlebuildJava.generatedResourcesDir
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-${libraries.groovy.version}/html/gapi"
def mavenApiUrl = "http://maven.apache.org/ref/${libraries.maven3.version}/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 (BuildEnvironment.javaVersion.isJava8Compatible()) {
options.addStringOption 'Xdoclint:syntax,html,reference', '-quiet'
}
options.addStringOption "stylesheetfile", stylesheetFile.absolutePath
source ProjectGroups.INSTANCE.getPublicJavaProjects(project).collect { project -> project.sourceSets.main.allJava }
destinationDir = new File(docsDir, 'javadoc')
classpath = files(ProjectGroups.INSTANCE.getPublicJavaProjects(project).collect {project -> [project.sourceSets.main.compileClasspath, project.sourceSets.main.output] })
PublicApi.includes.each {
include it
}
PublicApi.excludes.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", constructorArgs: [file("src/docs/release/notes.md"), 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())
}
}
}
}
}
task copyReleaseFeatures(type: Copy) {
from releaseFeaturesFile
into generatedResourcesDir
}
sourceSets.main.output.dir generatedResourcesDir, builtBy: [defaultImports, copyReleaseFeatures]
test {
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)
systemProperty "org.gradle.docs.releasefeatures", releaseFeaturesFile
}
task docs {
dependsOn javadocAll, userguide, distDocs, samplesDocs, dslHtml, releaseNotes
description = 'Generates all documentation'
group = 'documentation'
}
task docsZip(type: Zip) {
from project.outputs.docs
}