views:

426

answers:

3

I've this code in my build.xml:

    <exec executable="cmd" osfamily="winnt">
        <arg value="/c"/>
        <arg value="xsltproc\bin\xsltproc.exe"/>
        <arg value="--xinclude"/>
        <arg value="-o"/>
        <arg value="dist/html/main.html"/>
        <arg value="xsl/html/docbook.xsl"/>
        <arg value="xml/main.xml"/>
    </exec>
    <exec executable="xsltproc" osfamily="unix">
        <arg value="--xinclude"/>
        <arg value="-o"/>
        <arg value="dist/html/main.html"/>
        <arg value="xsl/html/docbook.xsl"/>
        <arg value="xml/main.xml"/>
    </exec>

the sequence is the same... I'm wondering about how refactoring this small fragment in order to keep it DRY.

+6  A: 

maybe try using a property for the common bits with arg-line? something like this:

<property name="xslt.common" value="--xinclude -o dist/html/main.html xsl/html/docbook.xsl xml/main.xml"/>
<exec executable="cmd" osfamily="winnt">
    <arg value="/c"/>
    <arg value="xsltproc\bin\xsltproc.exe"/>
    <arg line="${xslt.common}"/>
</exec>
<exec executable="xsltproc" osfamily="unix">
    <arg line="${xslt.common}"/>
</exec>
thanks, it worked like a charm :)
dfa
+2  A: 

Define a macro.

You can glob the shared portions in an element, and conditionally execute the specific parts.

Nick Veys
This is an excellent solution if you have to perform the same task more than once.
A: 

I think the Unix version will work under NT if you have the xsltproc.exe available in via the PATH environment variable. You could try removing the osfamily and see.

Chris Nava