polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [3/3] zest-qi4j git commit: Documentation build plugin enhancements
Date Thu, 16 Jul 2015 21:50:26 GMT
Documentation build plugin enhancements

Declare task input/output, including content spread across the SDK.
The website build is now skipped if already up-to-date!


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/21b004e7
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/21b004e7
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/21b004e7

Branch: refs/heads/develop
Commit: 21b004e7ceabd750c2b5c4163f00905c8b62913e
Parents: 5a1a63b
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Thu Jul 16 23:49:53 2015 +0200
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Thu Jul 16 23:49:53 2015 +0200

----------------------------------------------------------------------
 .../org/qi4j/gradle/plugin/Documentation.groovy | 144 ++++++++++---------
 manual/build.gradle                             |   4 +-
 2 files changed, 78 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/21b004e7/buildSrc/src/main/groovy/org/qi4j/gradle/plugin/Documentation.groovy
----------------------------------------------------------------------
diff --git a/buildSrc/src/main/groovy/org/qi4j/gradle/plugin/Documentation.groovy b/buildSrc/src/main/groovy/org/qi4j/gradle/plugin/Documentation.groovy
index a6e6bf5..fef25a2 100644
--- a/buildSrc/src/main/groovy/org/qi4j/gradle/plugin/Documentation.groovy
+++ b/buildSrc/src/main/groovy/org/qi4j/gradle/plugin/Documentation.groovy
@@ -17,63 +17,85 @@ package org.qi4j.gradle.plugin;
 
 import org.gradle.api.DefaultTask
 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
 
-// TODO: use proper project variables for 'src' and other locations
-// TODO: extract out every location into configurable property
 // 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.
 class Documentation extends DefaultTask
 {
-  private String docName
+  @Input def String docName
+  @Input def String docType
+  void setDocName( String docName ) { this.docName = docName }
+  void setDocType( String docType ) { this.docType = docType }
 
-  private String 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') }
+
+  @InputFiles def getSubProjectsDocsDirs() { project.parent.subprojects.collect { p ->
p.file( 'src/docs' ) } }
+  @InputFiles def getSubProjectsTestDirs() { project.parent.subprojects.collect { p ->
p.file( 'src/test' ) } }
+
+  @OutputDirectory def File getOutputDir() { project.file( "${project.buildDir}/docs/${docName}/"
) }
+
+  def File getTempDir() { project.file( "${project.buildDir}/tmp/docs/${docName}") }
 
   @TaskAction
   def void generate()
   {
-    def userHome = new File(System.getProperty("user.home"))
-    def snippetDir = new File(userHome, ".asciidoc/filters/snippet").absoluteFile
+    installAsciidocFilters()
+
+    [ outputDir, tempDir ]*.deleteDir()
+    [ outputDir, tempDir ]*.mkdirs()
+
+    copySubProjectsDocsResources()
+    generateXDoc()
+    generateChunkedHtml()
+    // generateSingleHtml()
+    // generatePdf()
+  }
+
+  def void installAsciidocFilters()
+  {
+    def userHome = new File( System.getProperty( 'user.home' ) )
+    def snippetDir = new File( userHome, '.asciidoc/filters/snippet' ).absoluteFile
     if( !snippetDir.exists() )
     {
       println "Installing [snippet] into $snippetDir"
       snippetDir.mkdirs()
       project.copy {
-        from "$project.rootDir/buildSrc/src/bin"
+        from "${project.rootDir}/buildSrc/src/bin"
         into snippetDir
         include 'snippet.*'
       }
-      ant.chmod(dir: snippetDir, perm: "755", includes: "snippet.py")
+      ant.chmod( dir: snippetDir, perm: '755', includes: 'snippet.py' )
     }
 
-    def devstatusDir = new File(userHome, ".asciidoc/filters/devstatus").absoluteFile
+    def devstatusDir = new File( userHome, '.asciidoc/filters/devstatus' ).absoluteFile
     if( !devstatusDir.exists() )
     {
       println "Installing [devstatus] into $devstatusDir"
       snippetDir.mkdirs()
       project.copy {
-        from "$project.rootDir/buildSrc/src/bin"
+        from "${project.rootDir}/buildSrc/src/bin"
         into devstatusDir
         include 'devstatus.*'
       }
-      ant.chmod(dir: devstatusDir, perm: "755", includes: "devstatus.py")
+      ant.chmod( dir: devstatusDir, perm: '755', includes: 'devstatus.py' )
     }
-
-    new File(project.buildDir, "docs/$docName".toString()).mkdirs()
-    new File(project.buildDir, "tmp/docs/$docName".toString()).mkdirs()
-
-    copySubProjectsResources()
-    generateXDoc()
-    generateChunkedHtml()
-    // generateSingleHtml()
-    // generatePdf()
   }
 
-  def void copySubProjectsResources()
+  def void copySubProjectsDocsResources()
   {
     project.parent.subprojects.each { p ->
       p.copy {
-        from 'src/docs/resources'
-        into "build/docs/$docName/"
+        from p.file( 'src/docs/resources' )
+        into outputDir
         include '**'
       }
     }
@@ -83,28 +105,28 @@ class Documentation extends DefaultTask
   {
     project.exec {
       executable = 'asciidoc'
-      workingDir = ".."
-      def commonResourcesDir = 'manual/src/resources'
-      def asciidocConfigFile = 'manual/src/conf/asciidoc.conf'
-      def docbookConfigFile = 'manual/src/conf/docbook45.conf'
-      def linkimagesConfigFile = 'manual/src/conf/linkedimages.conf'
-      def xdocOutputFile = "manual/build/tmp/docs/$docName/xdoc-temp.xml".toString()
-      def asciiDocFile = "manual/src/docs/$docName/index.txt".toString()
+      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( docsDir, "$docName/index.txt"
) )
       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=' + commonResourcesDir,
+              '--attribute', 'importdir=' + commonResourcesPath,
               '--backend', 'docbook',
               '--attribute', 'docinfo1',
               '--doctype', docType,
-              '--conf-file=' + asciidocConfigFile,
-              '--conf-file=' + docbookConfigFile,
-              '--conf-file=' + linkimagesConfigFile,
-              '--out-file', xdocOutputFile,
-              asciiDocFile
+              '--conf-file=' + asciidocConfigPath,
+              '--conf-file=' + docbookConfigPath,
+              '--conf-file=' + linkimagesConfigPath,
+              '--out-file', xdocOutputPath,
+              asciidocIndexPath
       ]
     }
   }
@@ -112,25 +134,26 @@ class Documentation extends DefaultTask
   def void generateChunkedHtml()
   {
     project.copy {
-      from 'src/resources'
-      into "build/docs/$docName/"
+      from commonResourcesDir
+      into outputDir
       include '**'
     }
     project.copy {
-      from "src/docs/$docName/resources"
-      into "build/docs/$docName/"
+      from "$docsDir/$docName/resources"
+      into outputDir
       include '**'
     }
 
     project.exec {
-      String xsltFile = "src/docs/$docName/xsl/chunked.xsl"
+      def xsltFile = "$docsDir/$docName/xsl/chunked.xsl"
+      def outputPath = relativePath( project.projectDir, outputDir ) + '/'
       executable = 'xsltproc'
       args = [
               '--nonet',
               '--noout',
-              '--output', "build/docs/$docName/",
+              '--output', outputPath,
               xsltFile,
-              "build/tmp/docs/$docName/xdoc-temp.xml"
+              "$tempDir/xdoc-temp.xml"
       ]
     }
   }
@@ -139,14 +162,14 @@ class Documentation extends DefaultTask
   {
     project.exec {
       // XML_CATALOG_FILES=
-      String xsltFile = 'src/xsl/xhtml.xsl'
+      String xsltFile = "$xslDir/xhtml.xsl"
       executable = 'xsltproc'
       args = [
               '--nonet',
               '--noout',
-              '--output', "build/docs/$docName/$docName" + ".html",
+              '--output', "$outputDir/${docName}.html",
               xsltFile,
-              "build/tmp/docs/$docName/xdoc-temp.xml"
+              "$tempDir/xdoc-temp.xml"
       ]
     }
   }
@@ -156,41 +179,26 @@ class Documentation extends DefaultTask
     // $ xsltproc --nonet ../docbook-xsl/fo.xsl article.xml > article.fo
     // $ fop article.fo article.pdf
     project.exec {
-      String xsltFile = 'src/xsl/fo.xsl'
+      String xsltFile = "$xslDir/fo.xsl"
       executable = 'xsltproc'
       args = [
         '--nonet',
-        '--output', "build/tmp/docs/$docName/$docName"+".fo",
+        '--output', "$tempDir/${docName}.fo",
         xsltFile,
-        "build/tmp/docs/$docName/xdoc-temp.xml"
+        "$tempDir/xdoc-temp.xml"
       ]
     }
     project.exec {
       executable = 'fop'
       args = [
-        "build/tmp/docs/$docName/$docName"+".fo",
-        "build/docs/$docName/$docName" + ".pdf"
+        "$tempDir/${docName}.fo",
+        "$outputDir/${docName}.pdf"
       ]
     }
   }
 
-  String getDocName( )
-  {
-    return docName
-  }
-
-  void setDocName( String docName )
-  {
-    this.docName = docName
-  }
-
-  String getDocType( )
-  {
-    return docType
-  }
-
-  void setDocType( String docType )
+  def String relativePath( File root, File target )
   {
-    this.docType = docType
+    new File( root.toURI().relativize( target.toURI() ).toString() ).path
   }
 }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/21b004e7/manual/build.gradle
----------------------------------------------------------------------
diff --git a/manual/build.gradle b/manual/build.gradle
index 3e3fc50..b81294e 100644
--- a/manual/build.gradle
+++ b/manual/build.gradle
@@ -46,8 +46,8 @@ dependencies {
 
 task website( type: org.qi4j.gradle.plugin.Documentation,
               dependsOn: rootProject.allprojects.tasks.flatten().findAll { it.name == AsciidocBuildInfo.TASK_NAME
} ) {
-  docName = 'website'
-  docType = 'article'
+  docName 'website'
+  docType 'article'
 }
 
 task archiveWebsite( type: Copy ) {


Mime
View raw message