migrating-ant-to-dita.dita 5.5 KB

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