ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marina <ppi...@yahoo.com>
Subject conditional global variables?
Date Sun, 26 Sep 2010 13:23:39 GMT
Hello!
In essence, I would like to know how to define a global property conditionally, 
and then have it available to all build files via <import>.

Now the details:
I have a build.common.xml file with all global properties and paths defined. I 
import it into my main build and component build files via <import>, and this 
makes everything that is defined in the common file available to all other build 
files.
build.common.xml:
            <property name="build.classes" value="${build}/classes"/> 
            ...
      <path id="compile.classpath">
            <pathelement location="${build}/classes"/>
            <path refid="jdk.classpath"/>
            <fileset dir="${lib}">
                  <include name="**/*.jar"/>
            </fileset>
...


Then, I have a main build.xml that calls a few component build.xml via <ant 
file=...> call.
If I <import> the build.common.xml into all my build files - I have all 
properties and paths available to all builds.

It all works great, but now I want to have the build.classes property set 
conditionally, based on the build mode (dev vs. release). Ideally, I would like 
something similar to the C #ifdef macros:

build.common.xml:
if 
    mode='dev'
then 
            <property name="build.classes" value="${build}/dev/classes"/> 
else
            <property name="build.classes" value="${build}/release/classes"/> 

I can do the <if> logic if I define this property in the main build, for 
example, as part of some <init> task. But, it means that the property is not 
global anymore, and, which is more important, I cannot define my paths in the 
build.common.xml based on the value of this property. At least I could not 
figure out yet a way to do it...

So, I was pondering over a few options:
1. define all properties like that and paths in the main build.xml and pass them 
as parameters to all component builds - very involved and inflexible...
2. define a target <init> in the build.common.xml that defines all those 
properties and paths - and make all builds call it (or depend on it) - again, 
very involved in terms of refactoring my existing builds, and inflexible.
3. any other way???

If only I could just define that one global property conditionally! I feel like 
I'm missing some basic core concept here.... 

Any pointers?

Thanks!
Marina
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message