Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a Union and Macrodef-style element with dynamic content at runtime in Ant
    primarykey
    data
    text
    <p>I've a build script built in Ant which has a macrodef that takes a few default parameters, target, root and the like, and then an optional two, extrasrc-f and extrasrc-c. After they've come in, I like to do a uptodate check on all relevant resources, then only do a build if the target is out of date.</p> <p>What I have at the moment,</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;project name="Custom build" default="default"&gt; &lt;taskdef resource="net/sf/antcontrib/antlib.xml" classpath="C:/dev/ant/ant-contrib/ant-contrib-1.0b3.jar"/&gt; &lt;macrodef name="checkuptodate"&gt; &lt;attribute name="target" /&gt; &lt;element name="resource" /&gt; &lt;sequential&gt; &lt;condition property="needbuild"&gt; &lt;and&gt; &lt;resourcecount when="greater" count="0"&gt; &lt;resource /&gt; &lt;/resourcecount&gt; &lt;not&gt; &lt;uptodate targetfile="@{target}"&gt; &lt;srcresources&gt; &lt;resource /&gt; &lt;/srcresources&gt; &lt;/uptodate&gt; &lt;/not&gt; &lt;/and&gt; &lt;/condition&gt; &lt;/sequential&gt; &lt;/macrodef&gt; &lt;macrodef name="projbuild"&gt; &lt;attribute name="root" /&gt; &lt;attribute name="target" /&gt; &lt;element name="extrasrc-f" optional="true" /&gt; &lt;element name="extrasrc-c" optional="true" /&gt; &lt;sequential&gt; &lt;local name="needbuild" /&gt; &lt;checkuptodate target="@{root}/bin/@{target}"&gt; &lt;resource&gt; &lt;union&gt; &lt;extrasrc-f /&gt; &lt;fileset dir="@{root}/src" includes="**/*.java" /&gt; &lt;/union&gt; &lt;/resource&gt; &lt;/checkuptodate&gt; &lt;if&gt; &lt;istrue value="${needbuild}" /&gt; &lt;then&gt; &lt;javac srcdir="@{root}/src" destdir="@{root}/bin" includeantruntime="false" &gt; &lt;extrasrc-c /&gt; &lt;/javac&gt; &lt;/then&gt; &lt;/if&gt; &lt;/sequential&gt; &lt;/macrodef&gt; &lt;target name="default"&gt; &lt;projbuild root="." target="EntryPoint.class"&gt; &lt;extrasrc-f&gt; &lt;fileset dir="Proj2/src" includes="**/*.java" /&gt; &lt;fileset dir="Proj3/src" includes="**/*.java" /&gt; &lt;/extrasrc-f&gt; &lt;extrasrc-c&gt; &lt;classpath location="Proj2/src" /&gt; &lt;classpath location="Proj3/src" /&gt; &lt;/extrasrc-c&gt; &lt;/projbuild&gt; &lt;/target&gt; &lt;/project&gt; </code></pre> <p>But as you can see, at this point in time, for me it's inefficient, to do what I want, I've to create and pass in at least one fileset, and multiple classpaths. What I'd really like to do is just pass in a list of directories, then create the extrasrc-f and extrasrc-c elements on the fly from that information, but for the life of me, I've no idea how I'm able to do that.</p> <p>I've read up plenty about many of Ant and Ant-Contrib funky classes, but I haven't read anything that would allow me to do something like this, which I do find odd, because to me it looks an obvious situation.</p> <p>Am I approaching this in a very wrong way, or is there something I'm missing? If I'm really misusing Ant, I'd love pointers in the right direction about how to do this properly, create a catchall, template build in a macrodef (or target, if that's the only way to do it) which tests multiple source files against one file that gets built, while also passing in extra class or library paths too, preferably in one single list.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload