migrating-ant-to-dita.dita 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE task PUBLIC "-//OASIS//DTD DITA General Task//EN" "generalTask.dtd">
  3. <!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
  4. <task id="migrating-ant-to-dita">
  5. <title>Migrating Ant builds to use the <cmdname>dita</cmdname> command</title>
  6. <titlealts>
  7. <navtitle>Migrating Ant builds</navtitle>
  8. </titlealts>
  9. <shortdesc>Although DITA Open Toolkit still supports Ant builds, switching to the <cmdname>dita</cmdname> command
  10. offers a simpler command interface, sets all required environment variables and allows you to run DITA-OT without
  11. setting up anything beforehand.</shortdesc>
  12. <prolog>
  13. <metadata>
  14. <keywords>
  15. <indexterm>Ant<indexterm><xmlelement>exec</xmlelement></indexterm></indexterm>
  16. <indexterm>Ant<indexterm><xmlelement>dita-cmd</xmlelement></indexterm><indexterm><cmdname>dita</cmdname>
  17. command, benefits of</indexterm></indexterm>
  18. <indexterm>dita-cmd</indexterm>
  19. <indexterm><cmdname>dita</cmdname> command<indexterm>migrating Ant scripts</indexterm></indexterm>
  20. <indexterm>classpath<indexterm><cmdname>dita</cmdname> command</indexterm></indexterm>
  21. </keywords>
  22. </metadata>
  23. </prolog>
  24. <taskbody>
  25. <context>
  26. <p>Building output with the <cmdname>dita</cmdname> command is often easier than using Ant. In particular, you can
  27. use <filepath>.properties</filepath> files to specify sets of DITA-OT parameters for each build.</p>
  28. <p>You can include the <cmdname>dita</cmdname> command in shell scripts to perform multiple builds.</p>
  29. <note conref="../resources/conref-task.dita#ID/dita-in-path"/>
  30. </context>
  31. <steps>
  32. <step>
  33. <cmd>In your Ant build file, identify the properties set in each build target.</cmd>
  34. <info>
  35. <note>Some build parameters might be specified as properties of the project as a whole. You can refer to a
  36. build log to see a list of all properties that were set for the build.</note>
  37. </info>
  38. </step>
  39. <step>
  40. <cmd>Create a <filepath>.properties</filepath> file for each build and specify the needed build parameters, one
  41. per line, in the format <codeph>name = value</codeph>.</cmd>
  42. </step>
  43. <step>
  44. <cmd>Use the <cmdname>dita</cmdname> command to perform each build, referencing your
  45. <filepath>.properties</filepath> with the <parmname>--propertyfile</parmname>=<varname>file</varname>
  46. option.</cmd>
  47. </step>
  48. </steps>
  49. <example>
  50. <title>Example: Ant build</title>
  51. <p>Prior to DITA-OT 2.0, an Ant build like this was typically used to define the properties for each target.</p>
  52. <p>Sample build file: <filepath id="samples-dir"
  53. ><varname>dita-ot-dir</varname>/docsrc/samples</filepath><filepath>/ant_sample/build-chm-pdf.xml</filepath>
  54. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/ant_sample/build-chm-pdf.xml"/></codeblock></p></example>
  55. <example>
  56. <title>Example: <filepath>.properties</filepath> files with <cmdname>dita</cmdname> command</title>
  57. <p>The following <filepath>.properties</filepath> files and <cmdname>dita</cmdname> commands are equivalent to the
  58. example Ant build.</p>
  59. <p>Sample <filepath>.properties</filepath> file: <filepath conref="../resources/conref-task.dita#ID/samples-dir"
  60. /><filepath>/properties/chm.properties</filepath></p>
  61. <p>
  62. <codeblock outputclass="language-properties normalize-space show-line-numbers show-whitespace"><coderef href="../samples/properties/chm.properties"/></codeblock></p>
  63. <p>Sample <filepath>.properties</filepath> file: <filepath conref="../resources/conref-task.dita#ID/samples-dir"
  64. /><filepath>/properties/pdf.properties</filepath></p>
  65. <p>
  66. <codeblock outputclass="language-properties normalize-space show-line-numbers show-whitespace"><coderef href="../samples/properties/pdf.properties"/></codeblock></p>
  67. <p>Run from <filepath conref="../resources/conref-task.dita#ID/samples-dir"/>:</p>
  68. <codeblock><cmdname>dita</cmdname> <parmname>--input</parmname>=<filepath>sequence.ditamap</filepath> <parmname>--format</parmname>=<option>htmlhelp</option> \
  69. <parmname>--propertyfile</parmname>=<filepath>properties/chm.properties</filepath>
  70. <cmdname>dita</cmdname> <parmname>--input</parmname>=<filepath>taskbook.ditamap</filepath> <parmname>--format</parmname>=<option>pdf</option> \
  71. <parmname>--propertyfile</parmname>=<filepath>properties/pdf.properties</filepath></codeblock>
  72. </example>
  73. <example>
  74. <title>Example: Call the <cmdname>dita</cmdname> command from an Ant build</title>
  75. <p>In some cases, you might still want to use an Ant build to implement some pre- or post-processing steps, but
  76. also want the convenience of using the <cmdname>dita</cmdname> command with <filepath>.properties</filepath>
  77. files to define the parameters for each build. This can be accomplished with Ant’s <xmlelement>exec</xmlelement>
  78. task.</p>
  79. <p>This example uses a <xmlelement>dita-cmd</xmlelement> Ant macro defined in the <filepath
  80. conref="../resources/conref-task.dita#ID/samples-dir"/><filepath>/ant_sample/dita-cmd.xml</filepath> file:</p>
  81. <p>
  82. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/ant_sample/dita-cmd.xml#line=11,32"/></codeblock></p>
  83. <p>You can use this macro in your Ant build to call the <cmdname>dita</cmdname> command and pass the
  84. <parmname>input</parmname>, <parmname>format</parmname> and <parmname>propertyfile</parmname> parameters as
  85. follows:
  86. <codeblock outputclass="language-xml">&lt;dita-cmd input="sample.ditamap" format="pdf" propertyfile="sample.properties"/></codeblock>
  87. </p>
  88. <p>This approach allows you to use Ant builds to perform additional tasks at build time while allowing the
  89. <cmdname>dita</cmdname> command to set the classpath and ensure that all necessary JAR libraries are
  90. available.</p>
  91. <note>The attributes defined in the Ant macro are required and must be supplied each time the task is run. To set
  92. optional parameters in one build (but not another), use different <filepath>.properties</filepath> files for
  93. each build.</note>
  94. <p>Sample build file: <filepath conref="../resources/conref-task.dita#ID/samples-dir"
  95. /><filepath>/ant_sample/build-chm-pdf-hybrid.xml</filepath></p>
  96. <p>
  97. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/ant_sample/build-chm-pdf-hybrid.xml"/></codeblock>
  98. </p>
  99. </example>
  100. </taskbody>
  101. </task>