migrating-ant-to-dita.dita 6.7 KB

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