Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant unless attribute not working?

Tags:

java

ant

I must be not understanding the unless attribute properly. I have a properties file that has a property as follows:

module.project.enabled=false
module.finance.enabled=true

And in my Ant build file I have the following piece

<echo message="Finance module enabled is ${module.finance.enabled}"/>
<echo message="Project module enabled is ${module.project.enabled}"/>
<javac srcdir="src" destdir="${classes}" debug="true">
    <classpath>
        <pathelement path="src"/>
        <fileset dir="web/WEB-INF/lib" includes="*.jar"/>
        <fileset dir="lib" includes="*.jar"/>
        <fileset dir="${GWT.HOME}" includes="gwt-user.jar,gwt-servlet.jar"/>
    </classpath>
    <exclude name="bla/finance/*.java" unless="${module.finance.enabled}"/>
    <exclude name="bla/project/*.java" unless="${module.project.enabled}"/>
</javac>

When running my ant target the properties do seem to be read

 [echo] Finance module enabled is true
 [echo] Project module enabled is false

But when I look at the ${classes} directory I would have expected to see no classes in the project package and classes in the finance package but alas it seems to be excluding both packages?

like image 608
Clinton Bosch Avatar asked May 04 '11 08:05

Clinton Bosch


1 Answers

For Ant 1.7 and prior, the if and unless attributes only check if a property is set. They don't actually check the value. You could in fact set it to anything, and that'll evaluate as true for if and false for unless. Likewise if you don't set it at all, you'll get false for if and true for unless.

In either case I'm not aware of the if and unless being available for <exclude>.

like image 97
WhiteFang34 Avatar answered Nov 19 '22 22:11

WhiteFang34