ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scot P. Floess" <flo...@mindspring.com>
Subject Curious behavior calling target from script...
Date Mon, 05 Jun 2006 11:44:46 GMT
Can someone please look at the following and explain the behavior I am 
seeing?

<project  name = "MyProject">
    <taskdef  resource = "net/sf/antcontrib/antlib.xml"/>

    <script language="javascript">
        <![CDATA[
            echo     = MyProject.createTask ( "echo" );
            variable = MyProject.createTask ( "var"  );

            variable.setName  ( "theVal" );
            variable.setValue ( "foo"    );
            variable.execute  ();

            echo.setMessage ( "Javascript = " + MyProject.getProperty ( 
"theVal" ) );
            echo.perform    ();

            echoval.execute ();

            variable.setName  ( "theVal" );
            variable.setValue ( "bar"    );
            variable.execute  ();

            echo.setMessage ( "Javascript = " + MyProject.getProperty ( 
"theVal" ) );
            echo.perform    ();

            echoval.execute ();
        ]]>
    </script>

    <echo  message = "After Javascript = ${theVal}"/>

    <target name="echoval">
        <echo>echoval = ${theVal}</echo>
    </target>
</project>


Buildfile: build.xml
     [echo] Javascript = foo
     [echo] echoval = foo
     [echo] Javascript = bar
     [echo] echoval = foo
     [echo] After Javascript = bar

Basically, when I set some value in the script, I see the correct value 
from within the script...and as well as once the script ends...  
However, in the script when I call out to a target, the value is 
unchanged.  I'm not sure if this is a scoping issue or if I am calling 
out incorrectly?

I looked over the online docs for <script> and it says I have access to 
all items of the project from the script (which clearly I do).  However, 
the curious part is that I do set the value theVal in the script and can 
see the value changing...but when I call out to the target, echoval, 
theVal maintains the same value as its initial value.

I tried different variations of the above - using project instead of 
MyProject, etc.  I found the results to be the same.

Many thanks ahead of time!

Scot

-- 
Scot P. Floess
27 Lake Royale
Louisburg, NC  27549

252-478-8087 (Home)
919-754-4592 (Work)

Chief Architect JPlate  http://sourceforge.net/projects/jplate
Chief Architect JavaPIM http://sourceforge.net/projects/javapim


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message