ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <hol...@yahoo.com>
Subject Re: Best way to handle an "if" type situation?
Date Fri, 26 Oct 2001 14:45:29 GMT
--- Robert Seeger <rseeger@nortelnetworks.com> wrote:
> I want to create a path. If another path element has been defined, I
> want it included in the path. If it isn't defined, I don't want it
> included. The solution I've come up with so far is show below. Does
> anyone have any input on whether this is a good way to handle this?
> Is there a better way?
>
> <target name="c.e.c.w" if="cpath.local">
>   <path id="cpath.external">
>     <pathelement location="${TOOLSHOME}/java/acme/lib.jar"/>
> 	<pathelement location="${TOOLSHOME}/java/jsdk/lib/jsdk.jar"/>
> 	<pathelement location="${TOOLSHOME}/java/jdbc/classes"/>
> 	<pathelement location="${TOOLSHOME}/java/swing/swingall.jar"/>
> 	<pathelement location="${TOOLSHOME}/java/pfj/pfjfull.jar"/>
> 	<pathelement path="${cpath.local}"/>
>   </path>
> </target>
> 
> <target name="c.e.c.wo" unless="cpath.local">
>   <path id="cpath.external">
>     <pathelement location="${TOOLSHOME}/java/acme/lib.jar"/>
> 	<pathelement location="${TOOLSHOME}/java/jsdk/lib/jsdk.jar"/>
> 	<pathelement location="${TOOLSHOME}/java/jdbc/classes"/>
> 	<pathelement location="${TOOLSHOME}/java/swing/swingall.jar"/>
> 	<pathelement location="${TOOLSHOME}/java/pfj/pfjfull.jar"/>
>   </path>
> </target>
> 
> <target name="cpath.external.create" depends="c.e.c.w, c.e.c.wo">
> </target>

Unlike properties, you can override the value of a reference, so I'd avoid
the duplication of the five <pathelement>s and set them in a <path> on
their own, then combine that with ${cpath.local}, if set. For example:
  <property name="TOOLSHOME" value="/usr/local/lib"/>
  <path id="cpath.external">
    <pathelement location="${TOOLSHOME}/java/acme/lib.jar"/>
    <pathelement location="${TOOLSHOME}/java/jsdk/lib/jsdk.jar"/>
    <pathelement location="${TOOLSHOME}/java/jdbc/classes"/>
    <pathelement location="${TOOLSHOME}/java/swing/swingall.jar"/>
    <pathelement location="${TOOLSHOME}/java/pfj/pfjfull.jar"/>
  </path>
  <property name="cpath" refid="cpath.external"/>

  <target name="c.e.c.w" if="cpath.local">
    <path id="cpath.external">
      <pathelement path="${cpath}"/>
      <pathelement path="${cpath.local}"/>
    </path>
  </target>

  <target name="cpath.external.create" depends="c.e.c.w">
    <property name="cpath.external" refid="cpath.external"/>
    <echo message="cpath.external = ${cpath.external}"/>
  </target>

Note: I set the ${cpath.external} property the way I did so the final
value of the cpath.external reference could be echoed out (ie., I set the
original cpath.external reference to a property named "cpath" initially,
so I could set ${cpath.external} after the reference was finalized). If
you don't want to do that, you can chuck ${cpath} and just set it as
${cpath.external} to begin with. Also, you don't really need the
cpath.external.create target if you have some more real target that
depends on c.e.c.w instead.

Diane

=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

Mime
View raw message