You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Stefan Bodewig <bo...@bost.de> on 2000/05/30 17:21:08 UTC

[PATCH] added unless attribute to target

The appended patch adds an unless attribute to targets. The value of
this attribute is the name of a property. If this property is set the
target will be skipped.

Rationale:

1. Sometimes it easier to check for the absence instead of the presence
of something. For example

<available property="windows" file="c:\autoexec.bat" />
<target name="test" unless="windows">
    ...
</target>

would execute target test only on non Microsoft systems (silly
example, I know).

2. Sometimes you have two alternative ways to do something:

<target name="dowork" depends="way1,way2">
    ...
</target>
<target name="way1" if="way1ispossible">
    ...
</target>
<target name="way2" unless="way1ispossible">
    ...
</target>

3. You want to produce different things depending on your build
environment.

Let's assume I want to build a JDBC driver and I have both the 1.0
version and the 2.0 version in the same source tree - I still want to
support JDBC 1.0. The 1.0 version won't compile on JDK 1.2 and the 2.0
version not on JDK 1.1, so:

<available property="java2" classname="java.lang.ThreadLocal" />
<target name="build" depends="jdbc1,jdbc2" />
<target name="jdbc1" unless="java2">
    ...
</target>
<target name="jdbc2" if="java2">
    ...
</target>

Stefan