ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Olivier Gies <olivier.g...@bull.net>
Subject Re: How can I "conditionall chooise" a target implementation?
Date Thu, 29 May 2008 02:27:28 GMT
Hi Cyril,

I would suggest using the <if><then><else> from ant-contrib, at the 
project root level... It changed my life the day I started using it, and 
no more complicated target-based frameowrk with 'if' and 'unless' 
attributes everywhere.

Hope this helps,

BR

*Olivier Gies*

*Delivery Manager
Customs & Tax Software Engineering Center
Bull, Architect of an Open World ^TM
Phone: +86 (10) 65978001 - Ext 555 *

*www.bull.com <http://www.bull.com/>*

*This e-mail contains material that is confidential for the sole use of
the intended recipient. Any review, reliance or distribution by others
or forwarding without express permission is strictly prohibited. If you
are not the intended recipient, please contact the sender and delete all
copies.*



-------- Original Message  --------
Subject: How can I "conditionall chooise" a target implementation?
From: Cyril Sagan <Cyril.Sagan@sas.com>
To: Ant Users List <user@ant.apache.org>
Date: 29/05/2008 06:27

> PROBLEM:  I'm trying to develop a general build framework.   In so doing,
>           I need some mechanism for to provide a "conditional implementation"
>           for a target.  We cannot solve this problem using <antcall/>.
>           Can anyone suggest an implementation?
> 
> 
> Here's a couple ways that I tried, that almost work,... but do not.
> 
> All use this simple build.xml:
>   <?xml version="1.0"?>
>   <project name="generic_build" default="all">
>       <property file="config.properties" />
>       <import file="common.xml"/>
>   </project>
> 
> 
> Failing attempt #1:  This almost works, but doesn't because <import/>
> cannot be embedded inside a target!!  arg!
> 
> common.xml:
>   <?xml version="1.0"?>
>   <project name="generic_build" default="all">
>       <target name="use_lib_A" if="use.A">
>           <!-- sorry, cannot <import/> in a target! -->
>           <import file="lib_A.xml" />  <!-- target "all_impl" defined inside
-->
>       </target>
> 
>       <target name="use_lib_B" if="use.B">
>           <!-- sorry, cannot <import/> in a target! -->
>           <import file="lib_B.xml" />  <!-- target "all_impl" defined inside
-->
>       </target>
> 
>       <target name="all"
>               depends="init, use_lib_A, use_lib_B, all_impl" />
>   </project>
> 
> 
> 
> Failing attempt #2:  This would work, if Ant supported property expansion
> in the targets's depends attribute.
> 
> common.xml:
>   <?xml version="1.0"?>
>   <project name="generic_build" default="all">
>       <import file="lib_A.xml" />
>       <import file="lib_B.xml" />
> 
>       <target name="use_lib_A" if="use.A">
>           <property name="use.library" value="lib_A" />
>       </target>
> 
>       <target name="use_lib_B" if="use.B">
>           <property name="use.library" value="lib_B" />
>       </target>
> 
>       <target name="use_lib_B" if="use.B">
>           <import file="lib_B.xml" />  <!-- target "all_impl" defined inside
-->
>       </target>
> 
>       <!-- sorry, no property expansion inside attributes! -->
>       <target name="all"
>               depends="init, use_lib_A, use_lib_B, ${use.library}.all_impl" />
>   </project>
> 
> 
> 
> Failing attempt #3:  Almost works, except the depends targets
> always excute...
> 
> common.xml:
>   <?xml version="1.0"?>
>   <project name="generic_build" default="all">
>       <import file="lib_A.xml" />
>       <import file="lib_B.xml" />
> 
>       <!-- sorry, depends called regardless of if/unless -->
>       <target name="use_lib_A" if="use.A" depends="implementation_A" />
>       <target name="use_lib_A" if="use.B" depends="implementation_B" />
> 
>       <target name="all"  depends="init, use_lib_A, use_lib_B"
>   </project>
> 
> This gets us closest to what we want, and would suffice if we could
> tolerate the <antcall/>:
>       <target name="use_lib_A" if="use.A">
>           <antcall target="implementation_A" />
>       </target>
> 
> ...but we can't use antcall because it re-reads the *entire* build
> file.  There's some fairly complicated init (that we don't have
> control of) that doesn't tolerate being called multiple times.
> 
> I'd appreciate any suggestions from the experts!
> 
> Thanks.
> 
> --Cyril
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message