ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: MacroDef: use attribute inside another attributes default clause
Date Tue, 21 Oct 2003 10:07:20 GMT
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


Mime
View raw message