|  | 
| 1 | 1 | plugins { | 
| 2 |  | -    id 'com.github.eerohele.dita-ot-gradle' version '0.4.2' | 
|  | 2 | +    id 'com.github.eerohele.dita-ot-gradle' version '0.4.3' | 
|  | 3 | +    id 'com.github.eerohele.saxon-gradle' version '0.3.0' | 
| 3 | 4 | } | 
| 4 | 5 | 
 | 
| 5 |  | -ditaOt.dir System.getProperty('dita.home', '../') | 
|  | 6 | +import com.github.eerohele.DitaOtTask | 
|  | 7 | +import com.github.eerohele.SaxonXsltTask | 
| 6 | 8 | 
 | 
| 7 |  | -import com.github.eerohele.AntBuilderAssistant | 
| 8 |  | -def antBuilder = AntBuilderAssistant.getAntBuilder(project) | 
|  | 9 | +def getPropertyOrDefault(String name, def defaultValue) { | 
|  | 10 | +    hasProperty(name) ? findProperty(name) : defaultValue | 
|  | 11 | +} | 
| 9 | 12 | 
 | 
| 10 |  | -task pdf { | 
| 11 |  | -  doLast { | 
| 12 |  | -    antBuilder.execute { | 
| 13 |  | -      ant(antfile: 'build.xml', target: 'pdf') | 
|  | 13 | +String ditaHome = getPropertyOrDefault('ditaHome', projectDir.getParent()) | 
|  | 14 | +String ditaHomeSrc = getPropertyOrDefault('ditaHomeSrc', ditaHome) | 
|  | 15 | +String configDir = "${ditaHomeSrc}/config" | 
|  | 16 | +String ditavalFile = "${projectDir}/platform.ditaval" | 
|  | 17 | +Boolean toolkitBuild = file("${projectDir}/../lib/dost.jar").exists() | 
|  | 18 | +String samplesDir = toolkitBuild ? "${ditaHome}/docsrc/samples" : "${projectDir}/samples" | 
|  | 19 | +String outputDir = getPropertyOrDefault('outputDir', toolkitBuild ? "${ditaHome}/doc" : "${projectDir}/out") | 
|  | 20 | + | 
|  | 21 | +String toURI(String path) { | 
|  | 22 | +    file(path).toURI().toString() | 
|  | 23 | +} | 
|  | 24 | + | 
|  | 25 | +ditaOt.dir ditaHome | 
|  | 26 | + | 
|  | 27 | +task messages(type: SaxonXsltTask) { | 
|  | 28 | +    input "${configDir}/messages.xml" | 
|  | 29 | +    output "${projectDir}/user-guide/DITA-messages.xml" | 
|  | 30 | +    stylesheet "${projectDir}/resources/messages.xsl" | 
|  | 31 | +} | 
|  | 32 | + | 
|  | 33 | +task params(type: SaxonXsltTask) { | 
|  | 34 | +    input "${configDir}/plugins.xml" | 
|  | 35 | +    output "${projectDir}/parameters/all-parameters.dita" | 
|  | 36 | +    stylesheet "${projectDir}/resources/params.xsl" | 
|  | 37 | +    parameters('output-dir.url': toURI('parameters')) | 
|  | 38 | +    outputs.dir "${projectDir}/parameters" | 
|  | 39 | +} | 
|  | 40 | + | 
|  | 41 | +task extensionPoints(type: SaxonXsltTask) { | 
|  | 42 | +    input "${configDir}/plugins.xml" | 
|  | 43 | +    output "${projectDir}/extension-points/all-extension-points.dita" | 
|  | 44 | +    stylesheet "${projectDir}/resources/extension-points.xsl" | 
|  | 45 | +    parameters('output-dir.url': toURI('extension-points')) | 
|  | 46 | +    outputs.dir "${projectDir}/extension-points" | 
|  | 47 | +} | 
|  | 48 | + | 
|  | 49 | +task generatePlatformFilter { | 
|  | 50 | +    ant.condition(property: 'platform', value: 'windows') { | 
|  | 51 | +        os(family: 'windows') | 
|  | 52 | +    } | 
|  | 53 | + | 
|  | 54 | +    ant.condition(property: 'platform', value: 'osx' ) { | 
|  | 55 | +        os(family: 'mac') | 
|  | 56 | +    } | 
|  | 57 | + | 
|  | 58 | +    ant.condition(property: 'platform', value: 'unix' ) { | 
|  | 59 | +        os(family: 'unix') | 
|  | 60 | +    } | 
|  | 61 | + | 
|  | 62 | +    ant.echoxml(file: ditavalFile) { | 
|  | 63 | +        val { | 
|  | 64 | +            prop(action: 'include', att: 'platform', val: platform) | 
|  | 65 | +            prop(action: 'exclude', att: 'platform') | 
|  | 66 | +        } | 
| 14 | 67 |     } | 
| 15 |  | -  } | 
| 16 | 68 | } | 
| 17 | 69 | 
 | 
| 18 |  | -task html { | 
| 19 |  | -  doLast { | 
| 20 |  | -    antBuilder.execute { | 
| 21 |  | -      ant(antfile: 'build.xml', target: 'html') | 
|  | 70 | +task autoGenerate(dependsOn: [messages, params, extensionPoints, generatePlatformFilter]) { | 
|  | 71 | +    description 'Run tasks that generate content from resource files and the build environment.' | 
|  | 72 | +} | 
|  | 73 | + | 
|  | 74 | +task pdf(type: DitaOtTask, dependsOn: autoGenerate) { | 
|  | 75 | +    input "${projectDir}/userguide-book.ditamap" | 
|  | 76 | +    output outputDir | 
|  | 77 | +    transtype 'pdf' | 
|  | 78 | + | 
|  | 79 | +    properties { | 
|  | 80 | +        property(file: "${projectDir}/samples/properties/docs-build-pdf.properties") | 
| 22 | 81 |     } | 
| 23 |  | -  } | 
| 24 | 82 | } | 
| 25 | 83 | 
 | 
| 26 |  | -task htmlhelp { | 
| 27 |  | -  doLast { | 
| 28 |  | -    antBuilder.execute { | 
| 29 |  | -      ant(antfile: 'build.xml', target: 'htmlhelp') | 
|  | 84 | +task html(type: DitaOtTask, dependsOn: autoGenerate) { | 
|  | 85 | +    input "${projectDir}/userguide.ditamap" | 
|  | 86 | +    output outputDir | 
|  | 87 | +    transtype 'html5' | 
|  | 88 | + | 
|  | 89 | +    properties { | 
|  | 90 | +        property(file: "${projectDir}/samples/properties/docs-build-html5.properties") | 
|  | 91 | +    } | 
|  | 92 | +} | 
|  | 93 | + | 
|  | 94 | +task htmlhelp(type: DitaOtTask, dependsOn: autoGenerate) { | 
|  | 95 | +    input "${projectDir}/userguide.ditamap" | 
|  | 96 | +    output outputDir | 
|  | 97 | +    transtype 'htmlhelp' | 
|  | 98 | +    filter ditavalFile | 
|  | 99 | + | 
|  | 100 | +    properties { | 
|  | 101 | +        property(file: "${projectDir}/samples/properties/docs-build-htmlhelp.properties") | 
|  | 102 | +    } | 
|  | 103 | + | 
|  | 104 | +    doLast { | 
|  | 105 | +        ant.move(todir: outputDir, failonerror: 'no') { | 
|  | 106 | +            fileset(dir: "${outputDir}/htmlhelp", includes: '*.chm') | 
|  | 107 | +        } | 
|  | 108 | + | 
|  | 109 | +        ant.delete(dir: "${outputDir}/htmlhelp") | 
| 30 | 110 |     } | 
| 31 |  | -  } | 
| 32 | 111 | } | 
| 33 | 112 | 
 | 
| 34 | 113 | task cleanUp { | 
|  | 114 | +    doLast { | 
|  | 115 | +        ant.delete(dir: outputDir) | 
|  | 116 | +    } | 
|  | 117 | +} | 
|  | 118 | + | 
|  | 119 | +def commit = new ByteArrayOutputStream() | 
|  | 120 | + | 
|  | 121 | +task gitMetadata { | 
| 35 | 122 |   doLast { | 
| 36 |  | -    antBuilder.execute { | 
| 37 |  | -      ant(antfile: 'build.xml', target: 'clean') | 
|  | 123 | +    exec { | 
|  | 124 | +        workingDir = projectDir | 
|  | 125 | +        commandLine 'git' | 
|  | 126 | +        args = ['rev-parse', 'HEAD'] | 
|  | 127 | +        standardOutput = commit | 
| 38 | 128 |     } | 
| 39 | 129 |   } | 
| 40 | 130 | } | 
| 41 | 131 | 
 | 
| 42 |  | -task all(dependsOn: [pdf, html, htmlhelp]) | 
|  | 132 | +task site(type: DitaOtTask) { | 
|  | 133 | +    dependsOn 'messages', 'params', 'extensionPoints', 'gitMetadata' | 
|  | 134 | + | 
|  | 135 | +    input file("${projectDir}/site.ditamap") | 
|  | 136 | +    output getPropertyOrDefault('outputDir', "${buildDir}/site") | 
| 43 | 137 | 
 | 
|  | 138 | +    transtype 'org.dita-ot.html' | 
|  | 139 | + | 
|  | 140 | +    properties { | 
|  | 141 | +        property(name: 'args.gen.task.lbl', value: 'YES') | 
|  | 142 | +        property(name: 'args.rellinks', value: 'noparent') | 
|  | 143 | +        property(name: 'commit', value: commit) | 
|  | 144 | +    } | 
|  | 145 | +} | 
|  | 146 | + | 
|  | 147 | +task all(dependsOn: [pdf, html, htmlhelp]) | 
| 44 | 148 | task dist(dependsOn: [pdf, html]) | 
| 45 | 149 | 
 | 
| 46 | 150 | defaultTasks 'dist' | 
0 commit comments