You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jens Larsson <je...@west53.se> on 2001/11/16 19:28:55 UTC

Property manipulation through javascript

Hi fellow Ants,

I'm having a Ant-problem for which I can see no explaination. Any input appreciated.

In the snippet below the instance property is set to "a,b,c". I want the
ftp_transfer target to run three times with a different remotedir
attribute value each time. The target fires three times alright,
but the instance property holds the first value (a) all three times. What
am I doing wrong?

<target name="deploy" depends="archive">
  <script language="javascript"> <![CDATA[

    instances = Project.getProperty("instance").split(",");
    for (var i=0; i < instances.length; i++) {
      Project.setProperty("instance", instances[i]);
      ftp_transfer.execute();
    }

  ]]> </script>
</target>

<target name="ftp_transfer">
  <echo>Deploying files to ${testenv}/${instance} ...</echo>
  <ftp server="${ftp.server}"
       remotedir="/${testenv}/${service}/${instance}"
       userid="${userid}"
       password="${passwd}"
       verbose="true">
    <fileset dir="${vob.root}/code">
      <includesfile name="${vob.root}/includes.txt"/>
      <include name="class/${service}.jar"/>
    </fileset>
  </ftp>
</target>


Regards,
Jens Larsson


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Property manipulation through javascript

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 16 Nov 2001, Jens Larsson <je...@west53.se> wrote:

> The target fires three times alright, but the instance property
> holds the first value (a) all three times.

No it doesn't, but the message or remotedir attributes of your tasks
won't get evaluated a second or third time - the best thing you can do
is to stop using properties and call the appropriate methods directly,
something like

      testenv = project.getProperty("testenv");
      service = project.getProperty("service");
>     for (var i=0; i < instances.length; i++) {
>       Project.setProperty("instance", instances[i]);
        ftp_transfer.setRemoteDir("/"+testenv+"/"+service+"/"+instances[i]);
>       ftp_transfer.execute();
>     }

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>