Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Syntax used for nested var values???

Help
2007-10-31
2013-04-24
  • Holger Rauch
    Holger Rauch
    2007-10-31

    Hi to all ant-contrib forum members,

    I'm currently struggling with the problem of how to access nested var values.
    More precisely, I'm talking about my try to use something like @{@{othervar}} to do so, which is not quite right (see also XML comment in the Ant build file below).

    Any help is greatly appreciated. Thanks in advance for any help/links, etc. :-)))

    Kind regards,

        Holger

    ==================================================================

    <?xml version="1.0" encoding="iso-8859-1" ?>

    <project name="nestedvartest" default="do" basedir=".">

      <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

      <macrodef name="varnamevalinmac">
        <attribute name="samplevar" default="NOT SET" />
        <attribute name="othervar" default="NOT SET" />
        <sequential>
          <var name="@{samplevar}" unset="true" />
          <echo message="before for loop: othervar contains @{othervar}" />
          <for list="a,b,c,d,e"
           param="othervarval">
        <sequential>
          <var name="@{othervar}" value="@{othervarval}" />
          <echo message="inside for loop: @{othervar} contains @{othervarval}" />
          <if>
            <not>
              <isset property="@{samplevar}" />
            </not>
            <then>
              <!-- What's the right syntax for accessing @{othervar}'s value after it has been assigned, I mean *without* using the for loop param's value??? -->
              <var name="@{samplevar}" value="@{@{othervar}}" />
              <echo message="@{samplevar} previously NOT set; initially contains ${@{samplevar}}" />
            </then>
            <else>
              <var name="@{samplevar}" value="${@{samplevar}} @{@{othervar}}" />
            </else>
          </if>
        </sequential>
          </for>
          <!-- Analogous for @{samplevar}'s value -->
          <echo message="@{samplevar} contains @{@{samplevar}}" />
        </sequential>
      </macrodef>

      <target name="do">
        <varnamevalinmac samplevar="test"
                 othervar="test2" />
      </target>

    </project>

    ===========================================================================