Quantcast
Channel: Ant If/Unless Attribute Issue - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Ant If/Unless Attribute Issue

$
0
0

Forewarning, this is my first attempt at actually creating an ANT build script. I'm trying to make it so that my test target only runs if the compiled property is set to true, additionally I want my dist target to run unless the junit.failure property is set to true. But for some reason, the following code doesn't seem to be doing what I intended it to; meaning that when I try to run ant it will not execute tests as compiled is not set to true (I believe), but if I look in the bin folder I can see that the .class files were indeed generated. And consequently this means that dist will not run either as it depends on both the compile and test targets. Any thoughts or ideas on what I may be doing wrong?

<project name="project" default="dist" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless"><description>        Build file for the project</description><!-- set global properties for this build --><property name="src" location="src"/><property name="lib" location="lib"/><property name="bin" location="bin"/><property name="dist"  location="dist"/><property name="distDirName" value="dist"/><!-- including the external jar files --><path id="proj.classpath"><fileset dir="${lib}" includes="*.jar"/><pathelement location="${bin}"/></path><target name="compile" description="compile the source"><!-- Create the distribution directory --><mkdir dir="${bin}"/><!-- Compile the java code from ${src} into ${bin} --><javac srcdir="${src}" classpathref="proj.classpath" destdir="${bin}"/><!-- Set condition for dependent target --><condition property="compiled"><and><available file="**/SampleTest.class"/><available file="**/DBConnection.class"/></and></condition></target><target name="test" depends="compile" if="compiled"><junit failureproperty="junit.failure" errorproperty="junit.failure" printsummary="withOutAndErr" fork="yes" haltonfailure="true" haltonerror="true"><formatter type="xml"/><test name="this.one.dir.SampleTest" todir="${bin}"/><classpath refid="proj.classpath"/></junit></target><target name="dist" depends="compile,test" unless="junit.failure" description="generate the distribution"><!-- Create the distribution directory --><mkdir dir="${dist}"/><!-- Put everything in ${bin} into the distribution.jar file --><jar jarfile="${dist}/distribution.jar" basedir="${basedir}" excludes="**/test/,${distDirName}/**"/></target></project>

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images