views:

1571

answers:

4

There must be an easy way to do this. I build a Flex app using ant that depends on a SWC library, which works fine except that it rebuilds the library whether it needs to or not. How do I tell ant to only run the task if any of the sources files of the library (*.as, *.mxml) are newer than the SWC?

I've looked at <dependset> but it only seems to delete files, not determine whether a task should be run or not. <depend> seems to expect a one-to-one relationship between the source and target files rather than a one-to-many relationship -- I have many input files and one output file, but no intermediate object files.

Thanks a lot, Alex

A: 

I have on that changes just modified files, you could execute it every minute.

<target name="touch" description="Touch modified files" if="dir">
    <tstamp>
        <format property="now" pattern="MM/dd/yyyy HH:mm a"/>
    </tstamp>
    <touch>
        <fileset dir="${dir}">
            <date datetime="${now}" when="after"/>
            <type type="file"/>
        </fileset>
    </touch>
</target>
01
A: 

Check out uptodate.

Rob Di Marco
+7  A: 

You may use the uptodate-task to create an property and executing your other target only if that property is set.

I don't know much about flex, but you probably want something like this:

<?xml version="1.0" encoding="UTF-8"?>
<project name="test" default="compile">

   <target name="checkforchanges">
      <uptodate property="nochanges">
         <srcfiles dir="." includes="**/*.as"/>
         <srcfiles dir="." includes="**/*.mxml"/>
         <mapper to="applicaton.flex"/>
      </uptodate>
   </target>

   <target name="compile" depends="checkforchanges" unless="nochanges">
      ...
   </target>

</project>
Mnementh
Thanks! Here's what I'm using now:<code> <uptodate property="playerlib.notRequired" targetfile="${playerlib.swc}" > <srcfiles dir= "${src.dir}" includes="**/*.as"/> <srcfiles dir= "${src.dir}" includes="**/*.mxml"/> <srcfiles dir= "${basedir}" includes="**/*.xml"/> </uptod
I believe in the "compile" target, you should use "unless" instead of "if". I could be wrong...
Todd
You're right. I got the wrong idea here (and needed some time to realize it). Thanks. I named the property the wrong way also. I will change my answer.
Mnementh
+2  A: 

The OutOfDate task from the ant contrib library is IMO much cleaner than the Ant uptodate option. The reason is that you have to define additional targets just to set the property.

The solution with Ant contrib (from their example page):

<outofdate>
    <sourcefiles>
        <pathelement path="build.xml"/>
        <fileset dir="${lib.dir}"/>
    </sourcefiles>
    <targetfiles path="${jrun.file}"/>
    <sequential>
        <mkdir dir="${build.bin.dir}"/>
        <echo file="${jrun.file}" message="java -cp ${jrun.path} $*"/>
        <chmod file="${jrun.file}" perm="ugo+rx"/>
    </sequential>
</outofdate>

Everything is kept nicely inside one single target.

Vladimir