aronadaal
aronadaal

Reputation: 9263

apache ant: import filelist from file and use it in apply task

I'm trying to import an external filelist into my ant build-script and using it during in an apply task.

listoffiles:

<filelist id="myfiles" dir=".">
    <file name="file1" />
    <file name="file2" />
</filelist>

build.xml:

<target name="build">
    <property file="listoffiles"/>

    <apply executable="cat" parallel="false">
        <srcfile/>
        <filelist id="${myfiles}" />
    </apply>
</target>

I'm not sure if this works. In a tutorial I read that property is for importing properties and filelist is defined as a datatype. I also tried to define the filelist inside build.xml and referencing it with the code above... also no success.

Hope someone can help me!

Thanks aronadaal

P.S: Is there a way to print the content of a filelist? Just for debugging purposes.

Upvotes: 0

Views: 1017

Answers (2)

user4524982
user4524982

Reputation:

You want to use refid when you use the filelist rather than id - and not use the id like a property, i.e.

<apply executable="cat" parallel="false">
    <srcfile/>
    <filelist refid="myfiles" />
</apply>

You can print the value of a reference with ${toString:myfiles} - see http://ant.apache.org/manual/properties.html#toString

Edited to answer resourcelist question of the follow up answer

resourcelist is a resource collection that consists of resources whose names have been read from a file. Something like https://stackoverflow.com/a/37132426/4524982 should be doable with

<xslt-saxon ...>
  <resourcelist>
    <file file="includes"/>
  </resourcelist>
</xslt-saxon>

which works if (and only if) the xslt-saxon task supports nested resource collections.

Upvotes: 1

aronadaal
aronadaal

Reputation: 9263

I gave ant-contrib a try and found the following working solution.

example content of 'includes':

path1/file1
path2/file2
path2/file3

target from build.xml:

<target name="build-xml" depends="get-xml-files">
    <loadfile property="file" srcfile="includes"/>
    <for param="line" list="${file}" delimiter="${line.separator}">
        <sequential>
            <xslt-saxon in="@{line}.xml" out="@{line}.xml" style="tranform.xsl"/>
        </sequential>
    </for>
</target>

pros: script-like, easy to implement

cons: additional dependency, not-ant-like

So regarding your proposal resourcelist I'll stuck how to reference the lines read in my saxon-call. With ant-contrib I do something like `@{line}'.

Sorry for all these questions... but the ant manual is not really helpful for beginners.

Do you have any book recommendations for ant?

Thanks aronadaal

Upvotes: 1

Related Questions