ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: How to create paths that depend on a condition?
Date Sun, 23 May 2004 23:27:07 GMT
Also, as somebody else mentioned, the if/unless of <patternset> could
come to your rescue for an even simpler solution:

<javac [...]>
  <src>
    <dirset dir="${src.test.dir}">
      <include name="share-12-13-14" />
      <include name="share-13-14" if="j2ee1[34].available" />
    </dirset>
  </src>
</javac>

Provided one's using Ant 1.6.x, with the smarts Antoine added to
DirectoryScanner, this should not scan all of the ${src.test.dir}
as it used to (works nonetheless, it's just slow...). You'd still
need the <condition> to combine your two .available properties,
so it may not be that better, especially with Ant 1.5.x. --DD

> -----Original Message-----
> From: Dominique Devienne [mailto:DDevienne@lgc.com]
> Sent: Sunday, May 23, 2004 6:15 PM
> To: 'Ant Users List'
> Subject: RE: How to create paths that depend on a condition?
> 
> > From: Vincent Massol [mailto:vmassol2@pivolis.com]
> >
> > Ok, I've found a solutiob but it looks really ugly:
> >
> > <dirset dir="${src.test.dir}/share-13-14">
> >   <and>
> >     <filename name="share-13-14"/>
> >     <or>
> >       <selector if="j2ee13.available"/>
> >       <selector if="j2ee14.available"/>
> >     </or>
> >   </and>
> > </dirset>
> >
> > Any better solution?
> 
> Maybe... If I understand correctly, you want to include the share-12-13-14
> path element only if either j2ee1[34]* properties are defined. I haven't
> tested this, but I think I remember the 'path' attribute of <pathelement>
> will accept an empty value, simply ignoring it. So
> 
> <condition property="j2ee1[34].srcdir"
>            value="${src.test.dir}/share-13-14">
>   <or>
>     <isset property="j2ee13.available" />
>     <isset property="j2ee14.available" />
>   </or>
> <condition>
> <property name="j2ee1[34].srcdir" value="" />
> 
> <javac [...]>
>   <src>
>     <pathelement location="${src.test.dir}/share-12-13-14"/>
>     <pathelement path="${j2ee1[34].srcdir}"/>
>   </src>
> </javac>
> 
> Should do what you want, is easy enough to read, and is pure Ant. --DD
> 
> <usual-lamentation>
> I'd rather have if/unless on all Ant elements, as I lament often,
> rather than rely on knowledge of edge cases behavior in <pathelement>
> though. I've created for my own task a Path-derivative that accepts
> nested <element>s, with built-in if/unless/iftrue/unlessTrue/os/osFamily
> condition attributes, but it's only really useful in my own tasks only,
> unless you id/refid that Path, or when using the semi-official ant:type
> magic attribute (which still works only with tasks with add*(Path),
> and not the ones using create*(Path)).
> 
> Anyways, I think your use case is yet more evidence for the usefulness
> of generalized if/unless.
> </usual-lamentation>
> 
> > > -----Original Message-----
> > > From: Vincent Massol [mailto:vmassol2@pivolis.com]
> > >
> > > I'd like to create a <path> that depends on some property being
> > > defined or not. This is for putting inside the <javac> task.
> > > I cannot find the right combination. Here's what I'd like to do:
> > >
> > >     <javac [...]>
> > >       <src>
> > >         <pathelement location="${src.test.dir}/share-12-13-14"/>
> > > ---> start here
> > >         <dirset dir="${src.test.dir}/share-13-14">
> > >           <and>
> > >             <depth max="0"/>
> > >             <or>
> > >               <selector if="j2ee13.available"/>
> > >               <selector if="j2ee14.available"/>
> > >             </or>
> > >           </and>
> > >         </dirset>
> > > ---> stop here
> 
> ---------------------------------------------------------------------
> 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