ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scotte Zinn" <sz...@patronix.com>
Subject Re: Conditional Filter Problem
Date Mon, 07 Aug 2000 22:07:20 GMT
There is more than one of us new people to Ant that expect localized
filters.  Was this something considered for Ant or was it a known issue?  I
think filters would be much more useful if they were localized to a target.

On a related note, I was also expecting properties specified in a target to
be evaluated only if the target was executed.  That is, if a target had the
if/unless clause in it and it didn't qualify for execution, then the
properties specified in that target would not be set as well.  Again, this
is a form of conditional configuration.  In my scenario, I wanted to be able
to (via a command-line option) do a debug or release build of my code which
entailed compiling against a specific .jar file.  The solution I had to do
was a wrapper shell script around the Ant invocation that set the
${build-type.jar} property on the Ant invocation line.

-- Scotte

-----Original Message-----
From: damon.m.rolfs@ac.com [mailto:damon.m.rolfs@ac.com]
Sent: Monday, August 07, 2000 5:42 PM
To: ant-user@jakarta.apache.org
Subject: Conditional Filter Problem


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
"com.sun.java.util.collections" 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 "com.sun.java.util.collections"
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>

  <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
com.sun.java.util.collections"/>
    <filter token="collections.package"
value="com.sun.java.util.collections"/>
  </target>

  <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>

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

  <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}"
             dest="${build.src}"
             filtering="on"
             excludes="**/*.~*"/>
  </target>



Mime
View raw message