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 11:04:40 GMT
> The patch is with the bugzilla report:
> http://issues.apache.org/bugzilla/show_bug.cgi?id=23942

I will play a little bit ...


> This won't work as the default attribute gets processed by ant before
> macrodef sees it.
> for example:
> <property name="foo" value="global foo"/>
> <macrodef name="macro">
>    <attribute name="foo"/>
>    <attribute name="bar" default="${foo}"/>
>    <sequential>
>      <echo>bar is ${bar}</echo>
>    </sequential>
> </macrodef>
> <macro foo="macro's foo"/>
> 
> generates
> foo:
> bar is global foo


argh - you´re right.
Mmh - could overriding the Task.maybeConfigure() help? I don´t know whether
the 
RuntimeConfigurable holds the original strings "${foo}" or the resolved
values
"global foo". 

While having a look into the sources it seems to be very difficult - if
possible.
Property replacement is finally done in
RuntimeConfigurable.maybeConfigure(Project, boolean).
(Line 404)


I think I will stay on my workaround ...


Jan


> 
> Peter
> > 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
> 
> 
> ---------------------------------------------------------------------
> 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