build.gradle 4.5 KB

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