Search code examples
htmlantbuildraml

Running raml2html inside an ANT script


I have some RAML files sitting in a folder, and I'm setting up an ANT script to "build" them into HTML documentation using the raml2html package featured on the raml.org site.
I'm new to ANT, so I'm probably not making the most efficient use of it, but that is of secondary concern. I use two targets to accomplish this goal, and they look like this (I've ommitted clean and init):

<!-- Look for the RAML, send them one at a time to post-build -->

<target name="build" depends="clean, init">
    <echo message="searching for raml source in ${src}"/>
    <foreach param="file" target="post-build">
        <fileset dir="${src}">
            <include name="**/*.raml"/>
        </fileset>
    </foreach>      
</target>


<!-- Run raml2html on each of them, saving output in build/ -->
<target name="post-build" depends="">
    <echo>file: ${file}</echo>
    <substring text="${file}" parent-dir="${src}/" property="filename" />
    <echo>filename: ${filename}</echo>
    <echo>build-to: ${build}/${filename}</echo>
    <exec executable="raml2html" failonerror="true">
        <arg value="-i ${file}" />
        <arg value="-o ${build}/${filename}" /> 
    </exec>
</target>   

When I run the ANT script: $ant build, those two targets return this:

build:
     [echo] searching for raml source in /home/ryan/workspace/RAMLValidator/src
  [foreach] The nested fileset element is deprectated, use a nested path instead

post-build:
     [echo] file: /home/ryan/workspace/RAMLValidator/src/sample.raml
     [echo] filename: sample.html
     [echo] build-to: /home/ryan/workspace/RAMLValidator/build/sample.html
     [exec] 2.0.2

It appears as though the arguments I supplied to the <exec> translated into raml2html's -V option somewhere along the way, as its version is 2.0.2 when I run $raml2html -V from the terminal. When I run this same command explicitly from the terminal: $raml2html -i src/sample.raml -o build/sample.html, it generates the HTML exactly as expected... How did I mess this up?


Solution

  • The problem is that ANT treats the option flag and the flag's argument as separate entities, each needing their own <arg /> tag in order to function properly.

    Modifying the exec task in the "post-build" target like so fixed the problem:

    <exec executable="raml2html" failonerror="true">
        <arg value="-o" />
        <arg value="${build}/${filename}"/>
        <arg value="${file}" /> 
    </exec>
    

    Hopefully that saves someone a fraction of the time it cost me!