You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by ky...@panix.com on 2002/06/19 18:18:49 UTC

Re: ant-user Digest 19 Jun 2002 15:21:22 -0000 Issue 396



   From: "Erik Hatcher" <ja...@ehatchersolutions.com>
   To: "Ant Users List" <an...@jakarta.apache.org>
   Subject: Re: Conditionally setting code variables
   Date: Wed, 19 Jun 2002 10:42:14 -0400

   Yup.

   We just answered this just a couple of days ago.

   <property name="build.debug" value="false"/>
   <javac debug="${build.debug}"..../>

   To override from the command-line:

       ant -Dbuild.debug=true

Unless I can access build.debug from within my Java source code, as
far as I can see, what you write only alters the way Ant runs, but has
no effect on the source code that actually gets compiled, unlike the
C/C++ example I posted:

   > # in makefile:
   > ifdef DEBUG
   >   DBG_FLGS='-g -DDEBUG'
   > else
   >   DBG_FLGS=
   > endif
   >
   > foo: foo.o
   > cc -o foo $(DBG_FLGS) foo.o
   >
   >
   > ...and in the source .c file
   >
   > ...
   > #ifdef DEBUG
   >        /* print diagnostics */
   > #endif

Thanks!

kj

P.S. Please Cc me in replies, since I get ant-user-digest.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ant-user Digest 19 Jun 2002 15:21:22 -0000 Issue 396

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
> One thing I have thought of doing is writing something to take properties
> and types and generate a java class
>
> <constfile
>     destdir="build/src"
>     classname="org.example.Const"
>     scope="public"
>    >
>   <const type="boolean" name="debug" value="${debug}" />
>   <const type="String" name="bootDir" value="${project.basedir}" />
> </constfile>


> You could get away with this on a case by case basis using filters or the
> replace task

I actually think you could get away with it with XDoclet out of the box
right now, even.  Using a custom template that iterates over the collection
of template parameters.  I'm not 100% sure, but 99.5% sure this would work
with a very simple custom template.

As for feeding properties into Java source code to do the macro-like
expansion or control things - I'd like to see a more detailed use-case of
what you were trying to accomplish.  Using an Abstract Factory pattern and
parameterizing a classname in a configuration file is more my speed for this
kind of thing, rather than doing too much dynamic modification of Java
source code during a build.

    Erik



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: ant-user Digest 19 Jun 2002 15:21:22 -0000 Issue 396

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: <ky...@panix.com>
To: <an...@jakarta.apache.org>
Cc: <ja...@ehatchersolutions.com>
Sent: Wednesday, June 19, 2002 9:18 AM
Subject: Re: ant-user Digest 19 Jun 2002 15:21:22 -0000 Issue 396


>
>
>
>    From: "Erik Hatcher" <ja...@ehatchersolutions.com>
>    To: "Ant Users List" <an...@jakarta.apache.org>
>    Subject: Re: Conditionally setting code variables
>    Date: Wed, 19 Jun 2002 10:42:14 -0400
>
>    Yup.
>
>    We just answered this just a couple of days ago.
>
>    <property name="build.debug" value="false"/>
>    <javac debug="${build.debug}"..../>
>
>    To override from the command-line:
>
>        ant -Dbuild.debug=true
>
> Unless I can access build.debug from within my Java source code, as
> far as I can see, what you write only alters the way Ant runs, but has
> no effect on the source code that actually gets compiled, unlike the
> C/C++ example I posted:

I see, you want macro preprocessing of your source.


no. not yet, anyway. you could feed your java source through the C-era m4
preprocessor, but there is no support for it.


One thing I have thought of doing is writing something to take properties
and types and generate a java class

<constfile
    destdir="build/src"
    classname="org.example.Const"
    scope="public"
   >
  <const type="boolean" name="debug" value="${debug}" />
  <const type="String" name="bootDir" value="${project.basedir}" />
</constfile>

this would generate something like

package org.example.Const;

public final class Const {
    public final static boolean debug=false;
    public final Static string bootDir="/home/users/me/boot"
}

You could get away with this on a case by case basis using filters or the
replace task


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>