ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Conditional Filter Problem
Date Mon, 07 Aug 2000 21:41:46 GMT
I'm having problems setting up a filter that is conditional to the target
development environment.  I have an architecture built on Java 2
collections, but some of my users use a Java 1.1.8 environment.  There is
an issue that in Java 2, the collections library is located in the
"java.util" package, while for Java 1.1 developers must include a
collections.jar file and the corresponding classes belong to the
"" package.  I'd like to simplify their build
process by automatically setting the class imports.  My approach to
accomplish this is to change the imports in the Java code to use a filter.
So import an Iterator is done by:

  import @collections.package@.Iterator;

In my build.xml script I attempt to set the collections.package filter to
be "java.util" for a Java 2 environment or ""
for a Java 1.1 environment.  My script contains conditional targets based
on a build for Java 1.1 property.  If the users want to build for Java 1.1,
then they uncomment a property declaration in the init target (see
build.xml extract below).

This does not work, however since it appears the filter tasks are always
executed even if they are contained in a target that is not executed.  In
fact, it appears that which version of the filter is used is based solely
on which filter is set last.  Is this a bug in Ant, or is there a better
way to accomplish setting a filter to a dependent value?

Thanks, ~dmr

build.xml extract:

  <target name="init">
      == This property dictates the environment GRNDS will be compiled for.  If
      == it is left undefined, then GRNDS will be built for Java 2.  If it is
      == defined then, GRNDS will be built for Java 1.1.
      == uncomment this property only if you are working in a Java 1.1
      == environment, such as IBM WebSphere
    <!--property name="build-java-1.1" value="true"/-->

  <target name="prepare-java1_1" depends="prepare" if="build-java-1.1">
    <echo message="building for Java 1.1.8 platform"/>
    <echo message="collections.package set to"/>
    <filter token="collections.package" value=""/>

  <target name="prepare-java2" depends="prepare" unless="build-java-1.1">
    <echo message="building for Java 2 platform"/>
    <echo message="collections.package set to java.util"/>
    <filter token="collections.package" value="java.util"/>

  <target name="prepare" depends="init">
    <mkdir dir="${build.dir}"/>

  <target name="prepare-src" depends="prepare,prepare-java2,prepare-java1_1">
    <!-- create directories -->
    <mkdir dir="${build.src}"/>
    <mkdir dir="${build.dest}"/>

    <!-- copy src files -->
    <copydir src="${src.dir}"

View raw message