You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by pa...@apache.org on 2016/11/19 22:50:18 UTC
[17/35] zest-java git commit: build: move website & manual build
logic to ManualPlugin in buildSrc
build: move website & manual build logic to ManualPlugin in buildSrc
Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/a766fe1a
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/a766fe1a
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/a766fe1a
Branch: refs/heads/develop
Commit: a766fe1aef728e7ad94ba06ce33358d77e27e3ed
Parents: b3be18d
Author: Paul Merlin <pa...@apache.org>
Authored: Sat Nov 19 14:16:34 2016 +0100
Committer: Paul Merlin <pa...@apache.org>
Committed: Sat Nov 19 14:16:34 2016 +0100
----------------------------------------------------------------------
.../zest/gradle/doc/DocumentationTask.groovy | 157 +++++++++++--------
.../apache/zest/gradle/doc/ManualPlugin.groovy | 115 ++++++++++++++
manual/build.gradle | 76 +--------
3 files changed, 211 insertions(+), 137 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a766fe1a/buildSrc/src/main/groovy/org/apache/zest/gradle/doc/DocumentationTask.groovy
----------------------------------------------------------------------
diff --git a/buildSrc/src/main/groovy/org/apache/zest/gradle/doc/DocumentationTask.groovy b/buildSrc/src/main/groovy/org/apache/zest/gradle/doc/DocumentationTask.groovy
index 3c37465..0587e83 100644
--- a/buildSrc/src/main/groovy/org/apache/zest/gradle/doc/DocumentationTask.groovy
+++ b/buildSrc/src/main/groovy/org/apache/zest/gradle/doc/DocumentationTask.groovy
@@ -20,9 +20,14 @@ package org.apache.zest.gradle.doc
import groovy.io.FileType
import groovy.transform.CompileStatic
import groovy.transform.TypeCheckingMode
-import org.apache.zest.gradle.release.ReleaseSpecExtension;
+import java.security.MessageDigest
+import org.apache.zest.gradle.ZestExtension
+import org.apache.zest.gradle.release.ReleaseSpecExtension
+import org.apache.zest.gradle.tasks.ExecLogged
+import org.gradle.api.Action;
import org.gradle.api.DefaultTask
import org.gradle.api.file.CopySpec
+import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
@@ -37,23 +42,21 @@ class DocumentationTask extends DefaultTask
{
@Input def String docName
@Input def String docType
- void setDocName( String docName ) { this.docName = docName }
- void setDocType( String docType ) { this.docType = docType }
@InputDirectory def File getCommonResourcesDir() { project.file( 'src/resources' ) }
@InputDirectory def File getConfigDir() { project.file( 'src/conf' ) }
- @InputDirectory def File getDocsDir() { project.file( 'src/docs') }
- @InputDirectory def File getSrcMainDir() { project.file( 'src/main') }
- @InputDirectory def File getXslDir() { project.file( 'src/xsl') }
+ @InputDirectory def File getDocsDir() { project.file( 'src/docs' ) }
+ @InputDirectory def File getSrcMainDir() { project.file( 'src/main' ) }
+ @InputDirectory def File getXslDir() { project.file( 'src/xsl' ) }
@InputDirectory def File getBuildSrcDir() { project.rootProject.file( 'buildSrc/src' ) }
@InputFiles def getSubProjectsDocsDirs() { project.rootProject.subprojects.collect { p -> p.file( 'src/docs' ) } }
@InputFiles def getSubProjectsTestDirs() { project.rootProject.subprojects.collect { p -> p.file( 'src/test' ) } }
- @OutputDirectory def File getOutputDir() { project.file( "${project.buildDir}/docs/${docName}/" ) }
+ @OutputDirectory def File getOutputDir() { project.file( "${ project.buildDir }/docs/${ docName }/" ) }
- def File getTempAsciidocDir() { project.file( "${project.buildDir}/tmp-asciidoc" ) }
- def File getTempDir() { project.file( "${project.buildDir}/tmp/docs/${docName}") }
+ @Internal def File getTempAsciidocDir() { project.file( "${ project.buildDir }/tmp-asciidoc" ) }
+ @Internal def File getTempDir() { project.file( "${ project.buildDir }/tmp/docs/${ docName }" ) }
@TaskAction
def void generate()
@@ -73,13 +76,14 @@ class DocumentationTask extends DefaultTask
def void installAsciidocFilters()
{
- def digester = java.security.MessageDigest.getInstance( 'SHA' )
+ def digester = MessageDigest.getInstance( 'SHA' )
def filtersDir = project.rootProject.file( 'buildSrc/src/asciidoc/filters' )
def userHome = new File( System.getProperty( 'user.home' ) )
def dotAsciidocFiltersDir = new File( userHome, '.asciidoc/filters' )
def installSnippets = false
- filtersDir.eachFileRecurse( groovy.io.FileType.FILES ) { originalFile ->
- def targetFile = new File( dotAsciidocFiltersDir, (originalFile.toURI() as String) - (filtersDir.toURI() as String) )
+ filtersDir.eachFileRecurse( FileType.FILES ) { originalFile ->
+ def targetFile = new File( dotAsciidocFiltersDir,
+ ( originalFile.toURI() as String ) - ( filtersDir.toURI() as String ) )
if( !targetFile.exists() )
{
installSnippets = true
@@ -102,16 +106,18 @@ class DocumentationTask extends DefaultTask
spec.into dotAsciidocFiltersDir
}
dotAsciidocFiltersDir.eachFileRecurse( FileType.FILES ) { file ->
- if( file.name.endsWith( '.py' ) ) {
- chmod(file, '755')
+ if( file.name.endsWith( '.py' ) )
+ {
+ chmod( file, '755' )
}
}
println "Zest Asciidoc Filters Installed!"
}
}
- @CompileStatic(TypeCheckingMode.SKIP)
- def void chmod(File file, String permissions) {
+ @CompileStatic( TypeCheckingMode.SKIP )
+ def void chmod( File file, String permissions )
+ {
ant.chmod( file: file.absolutePath, perm: permissions )
}
@@ -128,30 +134,38 @@ class DocumentationTask extends DefaultTask
def void generateAsciidocAccordingToReleaseSpecification()
{
+ def zest = project.extensions.getByType( ZestExtension )
project.copy { CopySpec spec ->
spec.from docsDir
spec.into tempAsciidocDir
spec.include '**'
}
- if( project.version != '0' && !project.version.toString().contains( 'SNAPSHOT' ) ) {
+ if( zest.releaseVersion )
+ {
def licenseFile = new File( tempAsciidocDir, 'userguide/libraries.txt' )
def extensionsFile = new File( tempAsciidocDir, 'userguide/extensions.txt' )
def toolsFile = new File( tempAsciidocDir, 'userguide/tools.txt' )
[ licenseFile, extensionsFile, toolsFile ].each { asciidocFile ->
def filteredFileContent = ''
asciidocFile.readLines().each { line ->
- if( line.startsWith( 'include::' ) ) {
+ if( line.startsWith( 'include::' ) )
+ {
def approved = false
- def releaseApprovedProjects = project.rootProject.extensions.getByType( ReleaseSpecExtension ).approvedProjects
- releaseApprovedProjects.collect{it.projectDir}.each { approvedProjectDir ->
- if( line.contains( "${approvedProjectDir.parentFile.name}/${approvedProjectDir.name}" ) ) {
+ def releaseApprovedProjects = project.rootProject.extensions.
+ getByType( ReleaseSpecExtension ).approvedProjects
+ releaseApprovedProjects.collect { it.projectDir }.each { approvedProjectDir ->
+ if( line.contains( "${ approvedProjectDir.parentFile.name }/${ approvedProjectDir.name }" ) )
+ {
approved = true
}
}
- if( approved ) {
+ if( approved )
+ {
filteredFileContent += "$line\n"
}
- } else {
+ }
+ else
+ {
filteredFileContent += "$line\n"
}
}
@@ -162,32 +176,34 @@ class DocumentationTask extends DefaultTask
def void generateXDoc()
{
- project.exec { ExecSpec spec ->
+ def outLog = getLogFile( 'adoc-2-docbook', 'stdout' )
+ def errLog = getLogFile( 'adoc-2-docbook', 'stderr' )
+ ExecLogged.execLogged( project, outLog, errLog, { ExecSpec spec ->
spec.executable = 'asciidoc'
spec.workingDir = '..'
def commonResourcesPath = relativePath( project.rootDir, commonResourcesDir )
def asciidocConfigPath = relativePath( project.rootDir, new File( configDir, 'asciidoc.conf' ) )
def docbookConfigPath = relativePath( project.rootDir, new File( configDir, 'docbook45.conf' ) )
def linkimagesConfigPath = relativePath( project.rootDir, new File( configDir, 'linkedimages.conf' ) )
- def xdocOutputPath = relativePath( project.rootDir, new File( tempDir, 'xdoc-temp.xml' ) )
+ def xdocOutputPath = relativePath( project.rootDir, new File( tempDir, 'xdoc-temp.xml' ) )
def asciidocIndexPath = relativePath( project.rootDir, new File( tempAsciidocDir, "$docName/index.txt" ) )
spec.args = [
- '--attribute', 'revnumber=' + project.version,
- '--attribute', 'level1=' + (docType.equals('article') ? 1 : 0),
- '--attribute', 'level2=' + (docType.equals('article') ? 2 : 1),
- '--attribute', 'level3=' + (docType.equals('article') ? 3 : 2),
- '--attribute', 'level4=' + (docType.equals('article') ? 4 : 3),
- '--attribute', 'importdir=' + commonResourcesPath,
- '--backend', 'docbook',
- '--attribute', 'docinfo1',
- '--doctype', docType,
- '--conf-file=' + asciidocConfigPath,
- '--conf-file=' + docbookConfigPath,
- '--conf-file=' + linkimagesConfigPath,
- '--out-file', xdocOutputPath,
- asciidocIndexPath
+ '--attribute', 'revnumber=' + project.version,
+ '--attribute', 'level1=' + ( docType == 'article' ? 1 : 0 ),
+ '--attribute', 'level2=' + ( docType == 'article' ? 2 : 1 ),
+ '--attribute', 'level3=' + ( docType == 'article' ? 3 : 2 ),
+ '--attribute', 'level4=' + ( docType == 'article' ? 4 : 3 ),
+ '--attribute', 'importdir=' + commonResourcesPath,
+ '--backend', 'docbook',
+ '--attribute', 'docinfo1',
+ '--doctype', docType,
+ '--conf-file=' + asciidocConfigPath,
+ '--conf-file=' + docbookConfigPath,
+ '--conf-file=' + linkimagesConfigPath,
+ '--out-file', xdocOutputPath,
+ asciidocIndexPath
]
- }
+ } as Action<? super ExecSpec> )
}
def void generateChunkedHtml()
@@ -202,61 +218,74 @@ class DocumentationTask extends DefaultTask
spec.into outputDir
spec.include '**'
}
-
- project.exec { ExecSpec spec ->
+ def outLog = getLogFile( 'docbook-2-chunked-html', 'stdout' )
+ def errLog = getLogFile( 'docbook-2-chunked-html', 'stderr' )
+ ExecLogged.execLogged( project, outLog, errLog, { ExecSpec spec ->
def xsltFile = "$docsDir/$docName/xsl/chunked.xsl"
def outputPath = relativePath( project.projectDir, outputDir ) + '/'
spec.executable = 'xsltproc'
spec.args = [
- '--nonet',
- '--noout',
- '--output', outputPath,
- xsltFile,
- "$tempDir/xdoc-temp.xml"
+ '--nonet',
+ '--noout',
+ '--output', outputPath,
+ xsltFile,
+ "$tempDir/xdoc-temp.xml"
]
- }
+ } as Action<? super ExecSpec> )
}
def void generateSingleHtml()
{
- project.exec { ExecSpec spec ->
+ def outLog = getLogFile( 'docbook-2-html', 'stdout' )
+ def errLog = getLogFile( 'docbook-2-html', 'stderr' )
+ ExecLogged.execLogged( project, outLog, errLog, { ExecSpec spec ->
// XML_CATALOG_FILES=
String xsltFile = "$xslDir/xhtml.xsl"
spec.executable = 'xsltproc'
spec.args = [
- '--nonet',
- '--noout',
- '--output', "$outputDir/${docName}.html",
- xsltFile,
- "$tempDir/xdoc-temp.xml"
+ '--nonet',
+ '--noout',
+ '--output', "$outputDir/${ docName }.html",
+ xsltFile,
+ "$tempDir/xdoc-temp.xml"
]
- }
+ } as Action<? super ExecSpec> )
}
def void generatePdf()
{
// $ xsltproc --nonet ../docbook-xsl/fo.xsl article.xml > article.fo
- // $ fop article.fo article.pdf
- project.exec { ExecSpec spec ->
+ def outLog = getLogFile( 'docbook-2-fo', 'stdout' )
+ def errLog = getLogFile( 'docbook-2-fo', 'stderr' )
+ ExecLogged.execLogged( project, outLog, errLog, { ExecSpec spec ->
String xsltFile = "$xslDir/fo.xsl"
spec.executable = 'xsltproc'
spec.args = [
'--nonet',
- '--output', "$tempDir/${docName}.fo",
+ '--output', "$tempDir/${ docName }.fo",
xsltFile,
"$tempDir/xdoc-temp.xml"
]
- }
- project.exec { ExecSpec spec ->
+ } as Action<? super ExecSpec> )
+
+ // $ fop article.fo article.pdf
+ outLog = getLogFile( 'fo-2-pdf', 'stdout' )
+ errLog = getLogFile( 'fo-2-pdf', 'stderr' )
+ ExecLogged.execLogged( project, outLog, errLog, { ExecSpec spec ->
spec.executable = 'fop'
spec.args = [
- "$tempDir/${docName}.fo",
- "$outputDir/${docName}.pdf"
+ "$tempDir/${ docName }.fo",
+ "$outputDir/${ docName }.pdf"
]
- }
+ } as Action<? super ExecSpec> )
+ }
+
+ private File getLogFile( String step, String stream )
+ {
+ return project.file( "${ project.buildDir }/tmp/${ name }/${ step }-${ stream }.log" )
}
- def String relativePath( File root, File target )
+ private static String relativePath( File root, File target )
{
new File( root.toURI().relativize( target.toURI() ).toString() ).path
}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a766fe1a/buildSrc/src/main/groovy/org/apache/zest/gradle/doc/ManualPlugin.groovy
----------------------------------------------------------------------
diff --git a/buildSrc/src/main/groovy/org/apache/zest/gradle/doc/ManualPlugin.groovy b/buildSrc/src/main/groovy/org/apache/zest/gradle/doc/ManualPlugin.groovy
new file mode 100644
index 0000000..690f6e6
--- /dev/null
+++ b/buildSrc/src/main/groovy/org/apache/zest/gradle/doc/ManualPlugin.groovy
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.zest.gradle.doc
+
+import groovy.transform.CompileStatic
+import org.apache.zest.gradle.TaskGroups
+import org.apache.zest.gradle.ZestExtension
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.Task
+import org.gradle.api.tasks.Copy
+
+@CompileStatic
+class ManualPlugin implements Plugin<Project>
+{
+ static class TaskNames
+ {
+ static final String WEBSITE = "website"
+ static final String ARCHIVE_WEBSITE = "archiveWebsite"
+ static final String COPY_WEBSITE = "copyWebsite"
+ static final String MANUALS = "manuals"
+ }
+
+ @Override
+ void apply( final Project project )
+ {
+ def zest = project.extensions.getByType( ZestExtension )
+ project.tasks.create( TaskNames.WEBSITE, DocumentationTask ) { DocumentationTask task ->
+ task.group = TaskGroups.DOCUMENTATION
+ task.description = 'Generates documentation website'
+ task.dependsOn project.rootProject.allprojects.findResults { Project p ->
+ p.tasks.findByName AsciidocBuildInfoPlugin.TASK_NAME
+ }
+ task.onlyIf { isAsciidocInstalled( project, zest ) }
+ task.docName = 'website'
+ task.docType = 'article'
+ }
+ project.tasks.create( TaskNames.ARCHIVE_WEBSITE, Copy ) { Copy task ->
+ task.group = TaskGroups.DOCUMENTATION
+ task.description = 'Copy website to ../zest-web'
+ task.dependsOn TaskNames.WEBSITE
+ task.onlyIf { isAsciidocInstalled( project, zest ) }
+ if( zest.developmentVersion )
+ {
+ task.into "$project.rootProject.projectDir/../zest-web/site/content/java/develop"
+ }
+ else
+ {
+ task.into "$project.rootProject.projectDir/../zest-web/site/content/java/$project.version"
+ }
+ task.from "$project.buildDir/docs/website/"
+ }
+ project.tasks.create( TaskNames.COPY_WEBSITE, Copy ) { Copy task ->
+ task.group = TaskGroups.RELEASE
+ task.description = 'Copy website to ../zest-web LATEST'
+ task.dependsOn TaskNames.ARCHIVE_WEBSITE
+ task.onlyIf { zest.releaseVersion }
+ task.from "$project.rootProject.projectDir/../zest-web/site/content/java/$project.version/"
+ task.into "$project.rootProject.projectDir/../zest-web/site/content/java/latest/"
+ }
+ project.tasks.create( TaskNames.MANUALS ) { Task task ->
+ task.group = TaskGroups.DOCUMENTATION
+ task.description = 'Generates all documentation'
+ task.dependsOn TaskNames.COPY_WEBSITE
+ task.onlyIf { isAsciidocInstalled( project, zest ) }
+ }
+ }
+
+ private static Boolean asciidocInstalled = null
+
+ // Force when building a release version
+ // Skip if skipAsciidocIfAbsent property is set
+ // Skip if asciidoc is not found in PATH when building a development version
+ private static boolean isAsciidocInstalled( Project project, ZestExtension zest )
+ {
+ if( asciidocInstalled == null )
+ {
+ def skipAsciidocIfAbsent = project.findProperty 'skipAsciidocIfAbsent'
+ if( !skipAsciidocIfAbsent && zest.releaseVersion )
+ {
+ project.logger.info 'Asciidoc tasks forced for building a release version, hope you have Asciidoc installed'
+ asciidocInstalled = true
+ }
+ else
+ {
+ def pathDirs = System.getenv( 'PATH' ).split( File.pathSeparator )
+ def asciidocCandidates = pathDirs.collect( { String path ->
+ new File( path, 'asciidoc' )
+ } ).flatten() as List<File>
+ asciidocInstalled = asciidocCandidates.findAll( { it.isFile() } )
+ if( !asciidocInstalled )
+ {
+ project.logger.lifecycle 'WARNING Asciidoc not found in PATH, manual tasks will skip\n' +
+ ' Please install http://www.methods.co.nz/asciidoc/'
+ }
+ }
+ }
+ return asciidocInstalled
+ }
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/a766fe1a/manual/build.gradle
----------------------------------------------------------------------
diff --git a/manual/build.gradle b/manual/build.gradle
index 9c10a2d..b41ed37 100644
--- a/manual/build.gradle
+++ b/manual/build.gradle
@@ -14,11 +14,10 @@
* 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.zest.gradle.doc.AsciidocBuildInfoPlugin
-import org.apache.zest.gradle.doc.DocumentationTask
+import org.apache.zest.gradle.doc.ManualPlugin
+
+apply plugin: ManualPlugin
description = "Apache Zest\u2122 Manuals and Website."
@@ -31,72 +30,3 @@ dependencies {
runtime( libraries.slf4j_simple )
}
-//task userguide( type: DocumentationTask ) {
-// docName = 'userguide'
-// docType = 'book'
-//}
-//
-//task recipes( type: DocumentationTask ) {
-// docName = 'recipes'
-// docType = 'article'
-//}
-//
-//task referenceManual( type: DocumentationTask ) {
-// docName = 'reference'
-// docType = 'book'
-//}
-
-
-task website( type: DocumentationTask,
- dependsOn: rootProject.allprojects.tasks.flatten().
- findAll { it.name == AsciidocBuildInfoPlugin.TASK_NAME } ) {
- docName 'website'
- docType 'article'
-}
-
-task archiveWebsite( type: Copy ) {
- dependsOn website
- if( rootProject.version == '0' || rootProject.version.contains( "SNAPSHOT" ) )
- {
- into( "$rootProject.projectDir/../zest-web/site/content/java/develop" )
- }
- else
- {
- into( "$rootProject.projectDir/../zest-web/site/content/java/$version" )
- }
- from( 'build/docs/website/' )
-}
-
-task copyWebsite( type: Copy ) {
- dependsOn archiveWebsite
- if( rootProject.version != '0' && !rootProject.version.contains( "SNAPSHOT" ) )
- {
- from( "$rootProject.projectDir/../zest-web/site/content/java/$version/" )
- into( "$rootProject.projectDir/../zest-web/site/content/java/latest/" )
- }
-}
-
-task manuals() {
- dependsOn copyWebsite
-// dependsOn userguide
-// dependsOn referenceManual
-// dependsOn recipes
-}
-
-// Skip if asciidoc is not found in PATH when building a 0 or SNAPSHOT version,
-// or if skipAsciidocIfAbsent property is set and asciidoc is not found in PATH
-[ website, archiveWebsite, copyWebsite, manuals ]*.onlyIf {
- def skipAsciidocIfAbsent = rootProject.findProperty 'skipAsciidocIfAbsent'
- def pathDirs = System.getenv( 'PATH' ).split( File.pathSeparator )
- def present = pathDirs.collect( { new File( it, 'asciidoc' ) } ).flatten().findAll( { it.isFile() } )
- if( !skipAsciidocIfAbsent && version != '0' && !version.contains( 'SNAPSHOT' ) )
- {
- project.logger.debug 'Asciidoc tasks forced because version is no-0 and no-SNAPSHOT, hope you have Asciidoc installed'
- return true
- }
- if( !present )
- {
- project.logger.warn 'Asciidoc not found in PATH, manual tasks will skip, please install http://www.methods.co.nz/asciidoc/'
- }
- present
-}