Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Introduce required 'sourceDir' parameter
Browse files Browse the repository at this point in the history
e.g.:

    reference {
        sourceDir = file('src/docbook')
    }

This value is delegated to each of the referenceHtmlMulti,
referenceHtmlSingle, and referencePdf tasks as well, assuming
no more specific value has been set.
  • Loading branch information
cbeams committed Nov 8, 2011
1 parent 757642f commit 9154539
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions docbook-reference-plugin/src/main/groovy/DocbookReference.groovy
Expand Up @@ -52,17 +52,27 @@ class DocbookReferencePlugin implements Plugin<Project> {
def single = tasks.add("referenceHtmlSingle", HtmlSingleDocbookReferenceTask)
def pdf = tasks.add("referencePdf", PdfDocbookReferenceTask)

tasks.add("reference") {
def reference = tasks.add("reference") {
description = "Generates HTML and PDF reference documentation."
dependsOn([multi, single, pdf])

@InputDirectory
File sourceDir // e.g. 'src/reference'
}

project.gradle.taskGraph.whenReady {
if (multi.sourceDir == null) multi.sourceDir = reference.sourceDir
if (single.sourceDir == null) single.sourceDir = reference.sourceDir
if (pdf.sourceDir == null) pdf.sourceDir = reference.sourceDir
}

}

}

abstract class AbstractDocbookReferenceTask extends DefaultTask {
File sourceDirectory = new File(project.getProjectDir(), "build/reference-work");
@InputDirectory
File sourceDir // e.g. 'src/reference'

@Input
String sourceFileName = 'index.xml';
Expand All @@ -89,14 +99,14 @@ abstract class AbstractDocbookReferenceTask extends DefaultTask {
logging.captureStandardError(LogLevel.INFO)
}

preprocessDocbookSources() // TODO call once and only once
unpack() // TODO call only once
sourceDir = filterDocbookSources(sourceDir) // TODO call only once
unpack() // TODO call only once

SAXParserFactory factory = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
factory.setXIncludeAware(true);
docsDir.mkdirs();

File srcFile = new File(sourceDirectory, sourceFileName);
File srcFile = new File(sourceDir, sourceFileName);
String outputFilename = srcFile.getName().substring(0, srcFile.getName().length() - 4) + '.' + this.getExtension();

File oDir = new File(getDocsDir(), xdir)
Expand Down Expand Up @@ -133,24 +143,29 @@ abstract class AbstractDocbookReferenceTask extends DefaultTask {
copyImagesAndCss(project, xdir)
}

private void preprocessDocbookSources() {
docbookSrcDir = new File('src/docbook')
docbookWorkDir = new File('build/reference-work')
/**
* @param sourceDir directory of unfiltered sources
* @return directory of filtered sources
*/
private File filterDocbookSources(File sourceDir) {
docbookWorkDir = new File("${project.buildDir}/reference-work")

docbookWorkDir.mkdirs()

// copy everything but index.xml
project.copy {
into(docbookWorkDir)
from(docbookSrcDir) { exclude '**/index.xml' }
from(sourceDir) { exclude '**/index.xml' }
}
// copy index.xml and expand ${...} variables along the way
// e.g.: ${version} needs to be replaced in the header
project.copy {
into(docbookWorkDir)
from(docbookSrcDir) { include '**/index.xml' }
from(sourceDir) { include '**/index.xml' }
expand(version: "${project.version}")
}

return docbookWorkDir
}

private void unpack() {
Expand Down Expand Up @@ -218,7 +233,7 @@ abstract class AbstractDocbookReferenceTask extends DefaultTask {
private void copyImagesAndCss(def project, def dir) {
project.copy {
into "${project.buildDir}/reference/${dir}/images"
from "src/docbook/images" // SI specific
from "${sourceDir}/images" // SI specific
}
project.copy {
into "${project.buildDir}/reference/${dir}/images"
Expand Down

0 comments on commit 9154539

Please sign in to comment.