Eric (9) [Avatar] Offline
#1
This condition, outlined at the end of chapter 4 under short-circuiting tests, is referenced by the unless= attribute of the "test" target.

I currently have it defined with other properties at the top of my build file (outside of any targets). Since it's not working, I assume its not in the right place.

I don't see where it should go either from the book or the chapter 4 source code.

Thanks, -Eric
ErikHatcher (211) [Avatar] Offline
#2
Re: where does "tests.uptodate" condition go?
Could you elaborate on what you mean by "not working"? Are you getting an error or the tests are always running?
Eric (9) [Avatar] Offline
#3
Re: where does "tests.uptodate" condition go?
The tests are always running.
ErikHatcher (211) [Avatar] Offline
#4
Re: where does "tests.uptodate" condition go?
Could you pare this down to a simple runnable example for me to try out locally?

The <condition> itself needs to execute before the target that checks the property, perhaps in a target that it depends on.
Eric (9) [Avatar] Offline
#5
Re: where does "tests.uptodate" condition go?
I put the code in the target immediately preceding the test target:


<target name="test-compile" depends="compile,test-init" >
description="--> compile test code">
<!-- short-circuit condition -->
<condition property="tests.uptodate">
<and>

<uptodate>
<srcfiles dir="${src.home}" includes="**/*.java"/>
<mapper type="glob" >
from="*.java"
to="${build.classes.home}/*.class" />
</uptodate>

<uptodate>
<srcfiles dir="${test.src.home}" includes="**/*.java"/>
<mapper type="glob" >
from="*.java"
to="${test.classes.home}/*.class" />
</uptodate>

<uptodate>
<srcfiles dir="${test.src.home}" excludes="**/*.java"/>
<mapper type="glob" >
from="*"
to="${test.classes.home}/*" />
</uptodate>

<not>
<available file="${test.last.failed.file}"/>
</not>

<not>
<isset property="testcase"/>
</not>

<uptodate>
<srcfiles dir="${test.src.home}" includes="**/*.java"/>
<mapper type="package" >
from="*Test.java"
to="${test.data.home}/TEST-*Test.xml" />
</uptodate>
</and>
</condition>
<javac destdir="${test.home}" >
debug="$build.debug}"
includeantruntime="true"
srcdir="test">
<classpath refid="test.classpath"/>
</javac>
</target>

<!-- Primary test target -->
<target name="test" depends="test-compile" unless="tests.uptodate" ><!--- conditon reference -->
description="--> run JUnit tests">
<junit printsummary="false" >
errorProperty="test.failed"
failureProperty="test.failed"
fork="$junit.fork}">
<classpath>
<path refid="test.classpath"/>
<pathelement path="${java.class.path}"/>
</classpath>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest todir="${test.data.home}">
<fileset dir="${test.home}" includes="**/*Test.class"/>
</batchtest>
</junit>

<junitreport todir="${test.data.home}">
<fileset dir="${test.data.home}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${test.reports.home}"/>
</junitreport>

<echo message="last build failed tests" >
file="${test.last.failed.file}"/>

<fail message="Tests failed. Check log and/or reports." >
if="test.failed"/>

<!-- Remove test failed file, as these tests succeeded -->
<delete file="${test.last.failed.file}"/>
</target>


The tests till run regardless of the fact they ran successfully previously, etc.
Thanks, -Eric
Eric (9) [Avatar] Offline
#6
Re: where does "tests.uptodate" condition go?
Here's the build that you can run on your machine:

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="execute" name="rest">
<description>template for all builds</description>

<!-- set global properties for this build -->
<property name="src.home" location="src"/>
<property name="build.home" location="build"/>
<property name="build.classes.home" location="${build.home}/classes"/>
<property name="dist.home" location="dist"/>

<property name="build.debug" value="true"/>
<property name="build.deprecation" value="true"/>
<property name="build.optimize" value="true"/>
<property name="target" value="1.4"/>
<property name="source" value="1.4"/>

<property name="startup.class" value="com.ef.healthcare.gui.DisplayVitalsWindow"/>
<property name="debug" value="true" />

<!-- testing properties -->
<property name="junit.fork" value="true"/>
<property name="test.home" location="${build.home}/test"/>
<property name="test.data.home" location="${test.home}/data"/>
<property name="test.reports.home" location="${test.home}/reports"/>
<property name="test.last.failed.file" >
location="${build.home}/.lasttestsfailed"/>
<property name="test.src.home" location="test"/>

<path id="test.classpath">
<path refid="compile.classpath"/>
<pathelement location="${junit.jar}"/>
<pathelement location="${build.home}/classes"/>
<pathelement location="${build.home}/test"/>
</path>

<property name="junit.jar" location="c:/java/apps/junit3.8.1/junit.jar"/>

<path id="compile.classpath">
<pathelement location="${build.classes.home}"/>
<fileset dir="./lib">
<include name="*.jar"/>
</fileset>
</path>

<target name="init" description="--> prepare the build">
<tstamp> <!-- prefix="start"-->
<format property="buildtime" pattern="yyyy-MM-dd' 'HH:mm:ss"/>
</tstamp>
<echo message="Building ${ant.project.name}"/>
<echo message="buildtime = ${buildtime}"/>
<mkdir dir="${build.classes.home}"/>
<mkdir dir="${dist.home}"/>
</target>

<target name="test-init" >
description="--> prepare for testing"
unless="tests.uptodate" >
<mkdir dir="${test.home}"/>

<copy todir="${test.home}">
<fileset dir="test" excludes="**/*.java"/>
</copy>

<delete dir="${test.data.home}"/>
<delete dir="${test.reports.home}"/>
<mkdir dir="${test.data.home}"/>
<mkdir dir="${test.reports.home}"/>
</target>

<target name="compile" depends="init" >
description="--> compile source code">
<javac srcdir="${src.home}" >
destdir="${build.classes.home}"
optimize="${build.optimize}"
target ="${target}" source="${source}"
debug="${buld.debug}"
deprecation="${build.deprecation}" >
<classpath refid="compile.classpath"/>
<include name="**/*.java" />
</javac>
</target>

<target name="test-compile" depends="compile,test-init" >
description="--> compile test code">
<!-- short-circuit condition -->
<condition property="tests.uptodate">
<and>
<uptodate>
<srcfiles dir="${src.home}" includes="**/*.java"/>
<mapper type="glob" >
from="*.java"
to="${build.classes.home}/*.class" />
</uptodate>

<uptodate>
<srcfiles dir="${test.src.home}" includes="**/*.java"/>
<mapper type="glob" >
from="*.java"
to="${test.classes.home}/*.class" />
</uptodate>

<uptodate>
<srcfiles dir="${test.src.home}" excludes="**/*.java"/>
<mapper type="glob" >
from="*"
to="${test.classes.home}/*" />
</uptodate>

<not>
<available file="${test.last.failed.file}"/>
</not>

<not>
<isset property="testcase"/>
</not>

<uptodate>
<srcfiles dir="${test.src.home}" includes="**/*.java"/>
<mapper type="package" >
from="*Test.java"
to="${test.data.home}/TEST-*Test.xml" />
</uptodate>
</and>
</condition>
<javac destdir="${test.home}" >
debug="$build.debug}"
includeantruntime="true"
srcdir="test">
<classpath refid="test.classpath"/>
</javac>
</target>

<target name="test" depends="test-compile" unless="tests.uptodate" >
description="--> run JUnit tests">
<junit printsummary="false" >
errorProperty="test.failed"
failureProperty="test.failed"
fork="$junit.fork}">
<classpath>
<path refid="test.classpath"/>
<pathelement path="${java.class.path}"/>
</classpath>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest todir="${test.data.home}">
<fileset dir="${test.home}" includes="**/*Test.class"/>
</batchtest>
</junit>

<junitreport todir="${test.data.home}">
<fileset dir="${test.data.home}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${test.reports.home}"/>
</junitreport>

<echo message="last build failed tests" >
file="${test.last.failed.file}"/>

<fail message="Tests failed. Check log and/or reports." >
if="test.failed"/>

<!-- Remove test failed file, as these tests succeeded -->
<delete file="${test.last.failed.file}"/>
</target>

<target name="archive" depends="compile" description="--> create jar file">
<jar basedir="${build.home}" destfile="${dist.home}/project.jar"/>
</target>

<target name="clean" depends="init" description="--> remove temporary directories">
<delete dir="${build.home}"/>
<delete dir="${dist.home}"/>
</target>

<target name="execute" depends="compile" description="--> execute primary program">
<echo message="starting up" />
<java classname="${startup.class}" >
classpath="${build.classes.home}">
<arg value="{${debug}"/>
</java>
</target>

</project>
Eric (9) [Avatar] Offline
#7
Re: where does "tests.uptodate" condition go?
Sorry, here's something you can run on your machine (pared down).

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

<!-- set global properties for this build -->
<property name="src.home" location="src"/>
<property name="build.home" location="build"/>
<property name="build.classes.home" location="${build.home}/classes"/>
<property name="dist.home" location="dist"/>

<property name="build.debug" value="true"/>
<property name="build.deprecation" value="true"/>
<property name="build.optimize" value="true"/>
<property name="target" value="1.4"/>
<property name="source" value="1.4"/>

<!-- testing properties -->
<property name="junit.fork" value="true"/>
<property name="test.home" location="${build.home}/test"/>
<property name="test.data.home" location="${test.home}/data"/>
<property name="test.reports.home" location="${test.home}/reports"/>
<property name="test.last.failed.file" >
location="${build.home}/.lasttestsfailed"/>
<property name="test.src.home" location="test"/>

<path id="test.classpath">
<path refid="compile.classpath"/>
<pathelement location="${junit.jar}"/>
<pathelement location="${build.home}/classes"/>
<pathelement location="${build.home}/test"/>
</path>

<property name="junit.jar" location="c:/java/apps/junit3.8.1/junit.jar"/>

<path id="compile.classpath">
<pathelement location="${build.classes.home}"/>
<fileset dir="./lib">
<include name="*.jar"/>
</fileset>
</path>

<target name="init" description="--> prepare the build">
<tstamp> <!-- prefix="start"-->
<format property="buildtime" pattern="yyyy-MM-dd' 'HH:mm:ss"/>
</tstamp>
<echo message="Building ${ant.project.name}"/>
<echo message="buildtime = ${buildtime}"/>
<mkdir dir="${build.classes.home}"/>
<mkdir dir="${dist.home}"/>
</target>

<target name="test-init" >
description="--> prepare for testing"
unless="tests.uptodate" >
<mkdir dir="${test.home}"/>

<copy todir="${test.home}">
<fileset dir="test" excludes="**/*.java"/>
</copy>

<delete dir="${test.data.home}"/>
<delete dir="${test.reports.home}"/>
<mkdir dir="${test.data.home}"/>
<mkdir dir="${test.reports.home}"/>
</target>

<target name="compile" depends="init" >
description="--> compile source code">
<javac srcdir="${src.home}" >
destdir="${build.classes.home}"
optimize="${build.optimize}"
target ="${target}" source="${source}"
debug="${buld.debug}"
deprecation="${build.deprecation}" >
<classpath refid="compile.classpath"/>
<include name="**/*.java" />
</javac>
</target>

<target name="test-compile" depends="compile,test-init" >
description="--> compile test code">
<!-- <br /> short-circuit condition that doesn't short circuit yet <br /> -->
<condition property="tests.uptodate">
<and>
<uptodate>
<srcfiles dir="${src.home}" includes="**/*.java"/>
<mapper type="glob" >
from="*.java"
to="${build.classes.home}/*.class" />
</uptodate>

<uptodate>
<srcfiles dir="${test.src.home}" includes="**/*.java"/>
<mapper type="glob" >
from="*.java"
to="${test.classes.home}/*.class" />
</uptodate>

<uptodate>
<srcfiles dir="${test.src.home}" excludes="**/*.java"/>
<mapper type="glob" >
from="*"
to="${test.classes.home}/*" />
</uptodate>

<not>
<available file="${test.last.failed.file}"/>
</not>

<not>
<isset property="testcase"/>
</not>

<uptodate>
<srcfiles dir="${test.src.home}" includes="**/*.java"/>
<mapper type="package" >
from="*Test.java"
to="${test.data.home}/TEST-*Test.xml" />
</uptodate>
</and>
</condition>
<javac destdir="${test.home}" >
debug="$build.debug}"
includeantruntime="true"
srcdir="test">
<classpath refid="test.classpath"/>
</javac>
</target>

<target name="test" depends="test-compile" unless="tests.uptodate" >
description="--> run JUnit tests">
<junit printsummary="false" >
errorProperty="test.failed"
failureProperty="test.failed"
fork="$junit.fork}">
<classpath>
<path refid="test.classpath"/>
<pathelement path="${java.class.path}"/>
</classpath>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest todir="${test.data.home}">
<fileset dir="${test.home}" includes="**/*Test.class"/>
</batchtest>
</junit>

<junitreport todir="${test.data.home}">
<fileset dir="${test.data.home}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${test.reports.home}"/>
</junitreport>

<echo message="last build failed tests" >
file="${test.last.failed.file}"/>

<fail message="Tests failed. Check log and/or reports." >
if="test.failed"/>

<!-- Remove test failed file, as these tests succeeded -->
<delete file="${test.last.failed.file}"/>
</target>

<target name="archive" depends="compile" description="--> create jar file">
<jar basedir="${build.home}" destfile="${dist.home}/project.jar"/>
</target>

<target name="clean" depends="init" description="--> remove temporary directories">
<delete dir="${build.home}"/>
<delete dir="${dist.home}"/>
</target>

</project>
ErikHatcher (211) [Avatar] Offline
#8
Re: where does "tests.uptodate" condition go?
Eric - I see you've brought this issue over to the Ant user e-mail list. Stefan has replied to you there. Let's let the e-mail list support take over from here allowing you to benefit from the many others on the list. I apologize for not being able to get to this issue fast enough.
Eric (9) [Avatar] Offline
#9
Re: where does "tests.uptodate" condition go?
NP Erik...I hadn't realized what a good resource the mailing list is.