ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: MacroDef: use attribute inside another attributes default cla use
Date Tue, 21 Oct 2003 10:35:07 GMT
I havent found the patch.
Why you haven´t committed that to cvs? Just in test phase?

Your second suggestion sounds good. But I would do it more comfortable:
<macrodef>
    <attribute name="foo" default="bar"/>
should create a 
    <property name="foo" default="bar"/>

So the user doesn´t have to do it. It´s available as attribute, has default
behaviour and supports property replacement.
    <attribute name="foo"/>
    <attribute name="bar" default="${foo}"/>
would create the
    <property name="bar" value="${foo}"/>
and that will work.


Jan


> -----Original Message-----
> From: peter reilly [mailto:peter.reilly@corvil.com]
> Sent: Tuesday, October 21, 2003 12:19 PM
> To: Ant Users List
> Subject: Re: MacroDef: use attribute inside another attributes default
> cla use
> 
> 
> On Tuesday 21 October 2003 11:09, Jan.Materne@rzf.fin-nrw.de wrote:
> > Ok, but I want to have two attributes. One of them optional. So a
> >     <dep root="dist-lite" file="my-dependencies.txt"/>
> > should work.
> Ah.
> >
> > Does <local> introduce a new attribute?
> No.
> 
> But the following should work:
>   <target name="script">
>     <macrodef name="dep">
>       <attribute name="root"/>
>       <attribute name="file" default=""/>
>       <sequential>
>           <script language="javascript">
>             root = project.getProperty("root");
>             filename = project.getProperty("file");
>             if (filename.equals("")) {
>                 filename = root + ".dep"
>             }
>             importClass(java.lang.System);
>             System.out.println("root is " + root
>                                + " and filename is " + filename);
>           </script>
>         </sequential>
>     </macrodef>
>     <dep root="build.xml"/>
>   </target>
> 
> I could make an optional attribute to <attribute> allowing:
>   <target name="script">
>     <macrodef name="dep">
>       <attribute name="root"/>
>       <attribute name="file" optional="yes"/>
>       <sequential>
>           <!-- set file if file not set -->
>           <property name="file" value="${file}.dep"/> 
>           <script language="javascript">
>             root = project.getProperty("root");
>             importClass(java.lang.System);
>             System.out.println("root is " + root
>                                + " and filename is " + filename);
>           </script>
>         </sequential>
>     </macrodef>
>     <dep root="build.xml"/>
>   </target>
> 
> >
> >
> > Jan
> >
> > > -----Original Message-----
> > > From: peter reilly [mailto:peter.reilly@corvil.com]
> > > Sent: Tuesday, October 21, 2003 12:07 PM
> > > To: Ant Users List
> > > Subject: Re: MacroDef: use attribute inside another 
> attributes default
> > > clause
> > >
> > >
> > > The default in the attribute element may not expand other 
> attributes
> > > as this is expanded by ant before macrodef sees it.
> > >
> > > However the local patch I posted yesterday will fix this problem
> > > in a different way.
> > > With the patch, the macrodef attributes are real
> > > properties - with a local scope, so
> > > the following will work;
> > >
> > >   <target name="script">
> > >     <macrodef name="dep">
> > >         <attribute name="root"/>
> > >         <sequential>
> > >           <local name="file" value="${root}.dep"/>
> > >           <script language="javascript">
> > >             root = project.getProperty("root");
> > >             filename = project.getProperty("file");
> > >             importClass(java.lang.System);
> > >             System.out.println("root is " + root
> > >                                + " and filename is " + filename);
> > >           </script>
> > >         </sequential>
> > >     </macrodef>
> > >     <dep root="build.xml"/>
> > >   </target>
> > >
> > > With the output:
> > > script:
> > > root is build.xml and filename is build.xml.dep
> > >
> > > Peter
> > >
> > > On Tuesday 21 October 2003 10:43, 
> Jan.Materne@rzf.fin-nrw.de wrote:
> > > > I want to reuse one attribute for setting the default value
> > >
> > > of another one.
> > >
> > > > But that is not possible because the name is not resolved
> > >
> > > on that place.
> > >
> > > >     <macrodef name="dep">
> > > >         <attribute name="root"/>
> > > >         <attribute name="file" default="${root}.dep"/>
> > > >         <sequential>
> > > >         <script language="javascript"> <![CDATA[
> > > >             // attribute expansion from macrodef (script
> > >
> > > can´t reach the
> > >
> > > > values)
> > > >             root     = "${root}";
> > > >             filename = "${file}";
> > > >
> > > > Example:  <dep root="foo"/>
> > > > The "filename" is not set to "foo.dep" but to "${root}.dep".
> > > >
> > > > Workaround:
> > > > Test that behaviour and reset filename:
> > > >
> > > >         <script language="javascript"> <![CDATA[
> > > >             // attribute expansion from macrodef (script
> > >
> > > can´t reach the
> > >
> > > > values)
> > > >             root     = "${root}";
> > > >             filename = "${file}";
> > > >
> > > >             // handle the problem that the ${root} is not
> > >
> > > replaced in the
> > >
> > > >             // attribute tag. Mask the ${root} string -
> > >
> > > should not be
> > >
> > > > replaced
> > > >             // in the if-clause.
> > > >             if (filename.equals("${ro"+"ot}.dep")) {
> > > >                 filename = "${root}.dep";
> > > >             }
> > > >
> > > >
> > > > Is that a bug (which will be fixed - maybe until 1.6 final)
> > >
> > > or is it a
> > >
> > > > bigger problem?
> > > >
> > > >
> > > > Jan
> > >
> > > 
> ---------------------------------------------------------------------
> > > 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message