Krissh
Krissh

Reputation: 357

Pass Command Line arguments to Apache Ant build file from DITAOT custom plugin

I am trying to build a very basic custom html5 plugin for dita-ot. Below is my current setup. Here is my plugin.xml file.

plugin.xml

<plugin id="html5-test" version="3.6.1">        
    <transtype name="html5-test" desc="testing html5 transformation with current setup." >
        <param name="args.artlbl" desc="Specifies whether to generate a label for each image;" type="enum">
            <val>yes</val>
            <val default="true">no</val>
          </param>
    </transtype>
    

    <feature extension="ant.import" file="build.xml" />
</plugin>

Here is build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:if="ant:if" xmlns:unless="ant:unless" name="dita2html5-test" default="get-parameters">
<target name="get-parameters">
    <echoproperties/>
    <!-- here I want to access CLI arguments for further use. --!>
    <echo message="print value:${args.artlbl}"/>
</target>

the console only shows text and no value. I was expecting to see "no" there as it is default value. Ultimate goal is to get CLI arguments inside transtype tag and then pass them to build.xml. After that add this to properties and then use inside ant xslt task.

Upvotes: 1

Views: 165

Answers (2)

Krissh
Krissh

Reputation: 357

So finally I figured it out.

dita -f html5 -i /test.dita -Done=abc

will pass "one" as a parameter to the build.xml file. In build.xml file you will access the argument by following. No changes needed in plugin.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:if="ant:if" xmlns:unless="ant:unless" name="dita2html5-test" default="get-parameters">
<target name="get-parameters">
    <echo>Embed another1:${one}</echo>
    <echo message="print value:${args.artlbl}"/>
</target>

Upvotes: 0

jelovirt
jelovirt

Reputation: 5892

Configuring parameter default value in plugin.xml doesn't actually set the property default value. DITA-OT only uses the information when generating documentation for plug-ins.

You have to handle the default value in the build.xml. DITA-OT built-in plug-ins use the following convention:

<project>
  <!--
  This is the enty point DITA-OT will call when running html5-test.
  In depends first call your own init target, then normal HTML5 target.
  -->
  <target name="dita2html5-test"
          depends="html5-test.init,
                   dita2html5"/>
  <target name="html5-test.init">
    <!--
    Since property values cannot be overwritten once set, this will only
    set the value if there is no value set from the command line.
    -->
    <property name="args.artlbl" value="no"/>
  </target>

</project>

Upvotes: 3

Related Questions