build: groovy @CompileStatic buildSrc ModuleReleaseSpecification left untouched for now because of its use of XmlSlurper
Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/b398234b Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/b398234b Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/b398234b Branch: refs/heads/develop Commit: b398234b3818716c4c7d39bb0a2d5ceb178cbeba Parents: 11e8235 Author: Paul Merlin <[email protected]> Authored: Sun Nov 6 01:06:23 2016 +0100 Committer: Paul Merlin <[email protected]> Committed: Sun Nov 6 01:06:23 2016 +0100 ---------------------------------------------------------------------- .../src/main/groovy/AsciidocBuildInfo.groovy | 4 +- buildSrc/src/main/groovy/VersionClass.groovy | 27 ++++-- buildSrc/src/main/groovy/Xslt.groovy | 33 ++++--- .../zest/gradle/plugin/Documentation.groovy | 99 +++++++++++--------- 4 files changed, 92 insertions(+), 71 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-java/blob/b398234b/buildSrc/src/main/groovy/AsciidocBuildInfo.groovy ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/groovy/AsciidocBuildInfo.groovy b/buildSrc/src/main/groovy/AsciidocBuildInfo.groovy index b72c9dd..6a9a77c 100644 --- a/buildSrc/src/main/groovy/AsciidocBuildInfo.groovy +++ b/buildSrc/src/main/groovy/AsciidocBuildInfo.groovy @@ -18,13 +18,15 @@ * */ +import groovy.transform.CompileStatic import org.gradle.api.Project import org.gradle.api.Plugin +@CompileStatic class AsciidocBuildInfo implements Plugin<Project> { - final static TASK_NAME = 'makeAsciidocBuildInfo' + final static String TASK_NAME = 'makeAsciidocBuildInfo' AsciidocBuildInfo() { http://git-wip-us.apache.org/repos/asf/zest-java/blob/b398234b/buildSrc/src/main/groovy/VersionClass.groovy ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/groovy/VersionClass.groovy b/buildSrc/src/main/groovy/VersionClass.groovy index c82799f..b8c8a92 100644 --- a/buildSrc/src/main/groovy/VersionClass.groovy +++ b/buildSrc/src/main/groovy/VersionClass.groovy @@ -18,10 +18,20 @@ * */ +import groovy.transform.CompileStatic import org.gradle.api.Project import org.gradle.api.Plugin +import org.gradle.api.Task +import org.gradle.api.file.SourceDirectorySet import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.plugins.JavaPluginConvention +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.bundling.Jar +// TODO:perf Build only one for the whole project +// TODO:perf Remove the build date, maybe not for release versions +// TODO:release Put git data in with placeholders for dev versions +@CompileStatic class VersionClass implements Plugin<Project> { @@ -35,7 +45,7 @@ class VersionClass implements Plugin<Project> def genSrc = 'generated-src/version' def generatedSrcDir = new File(project.buildDir, genSrc) - def makeVersionClassTask = project.task('makeVersionClass') << { + Task makeVersionClassTask = project.task('makeVersionClass') << { def now = new Date() def tmpGroup = project.name if( tmpGroup.startsWith("org.apache.zest.core")) @@ -73,14 +83,13 @@ public interface BuildVersion """) f.close() } - project.sourceSets { - version { - java { - srcDir project.buildDir.name + '/' + genSrc + '/java' + def sourceSets = project.convention.getPlugin(JavaPluginConvention).sourceSets + sourceSets.create("version") { SourceSet sourceSet -> + sourceSet.java { SourceDirectorySet dirSet -> + dirSet.srcDir project.buildDir.name + '/' + genSrc + '/java' } - } } - makeVersionClassTask.getInputs().files(project.sourceSets.main.getAllSource()) + makeVersionClassTask.getInputs().files(sourceSets.getByName('main').allSource) makeVersionClassTask.getOutputs().file(generatedSrcDir) if( project.getBuildFile() != null && project.getBuildFile().exists() ) { @@ -88,8 +97,8 @@ public interface BuildVersion } project.getTasks().getByName('compileJava').dependsOn('compileVersionJava') project.getTasks().getByName('compileVersionJava').dependsOn('makeVersionClass') - project.getTasks().getByName('jar') { - from project.sourceSets.version.output + project.getTasks().getByName('jar') { Jar task -> + task.from sourceSets.getByName('version').output } } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/b398234b/buildSrc/src/main/groovy/Xslt.groovy ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/groovy/Xslt.groovy b/buildSrc/src/main/groovy/Xslt.groovy index ff9107f..3414350 100644 --- a/buildSrc/src/main/groovy/Xslt.groovy +++ b/buildSrc/src/main/groovy/Xslt.groovy @@ -54,9 +54,9 @@ * */ -import org.gradle.api.InvalidUserDataException +import groovy.transform.CompileStatic +import org.gradle.api.file.EmptyFileVisitor import org.gradle.api.tasks.SourceTask -import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.Optional import org.gradle.api.tasks.InputFile @@ -67,6 +67,7 @@ import javax.xml.transform.TransformerFactory import javax.xml.transform.stream.StreamResult import javax.xml.transform.stream.StreamSource +@CompileStatic class Xslt extends SourceTask { @@ -85,21 +86,19 @@ class Xslt extends SourceTask def factory = TransformerFactory.newInstance() def transformer = factory.newTransformer(new StreamSource(stylesheetFile)); - source.visit { FileVisitDetails fvd -> - if( fvd.isDirectory() ) - { - return + getSource().visit( new EmptyFileVisitor() { + @Override + void visitFile(FileVisitDetails fvd) { + // Remove the extension from the file name + def name = fvd.file.name.replaceAll('[.][^\\.]*$', '') + if( extension == null ) + { + extension = 'html' + } + name += '.' + extension + def destFile = new File(destDir, name) + transformer.transform(new StreamSource(fvd.file), new StreamResult(destFile)) } - // Remove the extension from the file name - name = fvd.file.name.replaceAll('[.][^\\.]*$', '') - if( extension == null ) - { - extension = 'html' - } - name += '.' + extension - def destFile = new File(destDir, name) - transformer.transform(new StreamSource(fvd.file), new StreamResult(destFile)) - - } + } ) } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/b398234b/buildSrc/src/main/groovy/org/apache/zest/gradle/plugin/Documentation.groovy ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/groovy/org/apache/zest/gradle/plugin/Documentation.groovy b/buildSrc/src/main/groovy/org/apache/zest/gradle/plugin/Documentation.groovy index ee04772..0d2a931 100644 --- a/buildSrc/src/main/groovy/org/apache/zest/gradle/plugin/Documentation.groovy +++ b/buildSrc/src/main/groovy/org/apache/zest/gradle/plugin/Documentation.groovy @@ -17,19 +17,24 @@ * * */ -package org.apache.zest.gradle.plugin; - +package org.apache.zest.gradle.plugin +import groovy.io.FileType +import groovy.transform.CompileStatic +import groovy.transform.TypeCheckingMode; import org.gradle.api.DefaultTask +import org.gradle.api.Project +import org.gradle.api.file.CopySpec import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.OutputDirectory +import org.gradle.process.ExecSpec // TODO: try to use dependencies for FOP and execute within the same JVM. // TODO: move the bulk of resources into this plugin, instead of sitting in the project. +@CompileStatic class Documentation extends DefaultTask { @Input def String docName @@ -57,8 +62,8 @@ class Documentation extends DefaultTask { installAsciidocFilters() - [ outputDir, tempAsciidocDir, tempDir ]*.deleteDir() - [ outputDir, tempAsciidocDir, tempDir ]*.mkdirs() + [ outputDir, tempAsciidocDir, tempDir ].each { it.deleteDir() } + [ outputDir, tempAsciidocDir, tempDir ].each { it.mkdirs() } copySubProjectsDocsResources() generateAsciidocAccordingToReleaseSpecification() @@ -94,38 +99,43 @@ class Documentation extends DefaultTask if( installSnippets ) { dotAsciidocFiltersDir.mkdirs() - project.rootProject.copy { - from filtersDir - into dotAsciidocFiltersDir + project.rootProject.copy { CopySpec spec -> + spec.from filtersDir + spec.into dotAsciidocFiltersDir } - dotAsciidocFiltersDir.eachFileRecurse( groovy.io.FileType.FILES ) { file -> + dotAsciidocFiltersDir.eachFileRecurse( FileType.FILES ) { file -> if( file.name.endsWith( '.py' ) ) { - ant.chmod( file: file.absolutePath, perm: '755' ) + chmod(file, '755') } } println "Zest Asciidoc Filters Installed!" } } + @CompileStatic(TypeCheckingMode.SKIP) + def void chmod(File file, String permissions) { + ant.chmod( file: file.absolutePath, perm: permissions ) + } + def void copySubProjectsDocsResources() { project.rootProject.subprojects.each { p -> - p.copy { - from p.file( 'src/docs/resources' ) - into outputDir - include '**' + p.copy { CopySpec spec -> + spec.from p.file( 'src/docs/resources' ) + spec.into outputDir + spec.include '**' } } } def void generateAsciidocAccordingToReleaseSpecification() { - project.copy { - from docsDir - into tempAsciidocDir - include '**' + project.copy { CopySpec spec -> + spec.from docsDir + spec.into tempAsciidocDir + spec.include '**' } - if( project.version != '0' && !project.version.contains( 'SNAPSHOT' ) ) { + if( project.version != '0' && !project.version.toString().contains( 'SNAPSHOT' ) ) { def licenseFile = new File( tempAsciidocDir, 'userguide/libraries.txt' ) def extensionsFile = new File( tempAsciidocDir, 'userguide/extensions.txt' ) def toolsFile = new File( tempAsciidocDir, 'userguide/tools.txt' ) @@ -134,7 +144,8 @@ class Documentation extends DefaultTask asciidocFile.readLines().each { line -> if( line.startsWith( 'include::' ) ) { def approved = false - project.rootProject.releaseApprovedProjects.collect{it.projectDir}.each { approvedProjectDir -> + Set<Project> releaseApprovedProjects = project.rootProject.extensions.extraProperties.get('releaseApprovedProjects') as Set<Project> + releaseApprovedProjects.collect{it.projectDir}.each { approvedProjectDir -> if( line.contains( "${approvedProjectDir.parentFile.name}/${approvedProjectDir.name}" ) ) { approved = true } @@ -153,16 +164,16 @@ class Documentation extends DefaultTask def void generateXDoc() { - project.exec { - executable = 'asciidoc' - workingDir = '..' + project.exec { 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 asciidocIndexPath = relativePath( project.rootDir, new File( tempAsciidocDir, "$docName/index.txt" ) ) - args = [ + spec.args = [ '--attribute', 'revnumber=' + project.version, '--attribute', 'level1=' + (docType.equals('article') ? 1 : 0), '--attribute', 'level2=' + (docType.equals('article') ? 2 : 1), @@ -183,22 +194,22 @@ class Documentation extends DefaultTask def void generateChunkedHtml() { - project.copy { - from commonResourcesDir - into outputDir - include '**' + project.copy { CopySpec spec -> + spec.from commonResourcesDir + spec.into outputDir + spec.include '**' } - project.copy { - from "$docsDir/$docName/resources" - into outputDir - include '**' + project.copy { CopySpec spec -> + spec.from "$docsDir/$docName/resources" + spec.into outputDir + spec.include '**' } - project.exec { + project.exec { ExecSpec spec -> def xsltFile = "$docsDir/$docName/xsl/chunked.xsl" def outputPath = relativePath( project.projectDir, outputDir ) + '/' - executable = 'xsltproc' - args = [ + spec.executable = 'xsltproc' + spec.args = [ '--nonet', '--noout', '--output', outputPath, @@ -210,11 +221,11 @@ class Documentation extends DefaultTask def void generateSingleHtml() { - project.exec { + project.exec { ExecSpec spec -> // XML_CATALOG_FILES= String xsltFile = "$xslDir/xhtml.xsl" - executable = 'xsltproc' - args = [ + spec.executable = 'xsltproc' + spec.args = [ '--nonet', '--noout', '--output', "$outputDir/${docName}.html", @@ -228,19 +239,19 @@ class Documentation extends DefaultTask { // $ xsltproc --nonet ../docbook-xsl/fo.xsl article.xml > article.fo // $ fop article.fo article.pdf - project.exec { + project.exec { ExecSpec spec -> String xsltFile = "$xslDir/fo.xsl" - executable = 'xsltproc' - args = [ + spec.executable = 'xsltproc' + spec.args = [ '--nonet', '--output', "$tempDir/${docName}.fo", xsltFile, "$tempDir/xdoc-temp.xml" ] } - project.exec { - executable = 'fop' - args = [ + project.exec { ExecSpec spec -> + spec.executable = 'fop' + spec.args = [ "$tempDir/${docName}.fo", "$outputDir/${docName}.pdf" ]
