ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dave Sowerby" <dave.sowe...@gmail.com>
Subject scriptdef/ant funny
Date Sat, 19 May 2007 05:13:10 GMT
Hi All,

I've found rather odd behaviour in the use of scriptdef and I wondered
if anyone had come across it before and knew of any workaround?

If in a master project I initialise a scriptdef which sets a property
and then call another build file with <ant which then calls that
scriptdef the initialised scriptdef operates within the master
project, meaning that all properties etc are not available to my
"child" project.

Here's an example:

build.xml:

<project name="main">
   <scriptdef name="projectdetails" language="beanshell">
       <attribute name="name" />
       System.out.println("Setting property " + attributes.get("name"));
       project.setProperty(attributes.get("name"), attributes.get("name"));
   </scriptdef>

   <projectdetails name="property" />
   <echo>In ${ant.project.name}: ${property}</echo>
   <echo>forking to new Project:</echo>
   <ant antfile="child.xml" inheritRefs="true" />
   <echo>Returned from new Project.</echo>
   <echo>In ${ant.project.name}: ${childproperty}</echo>
</project>

child.xml:

<project name="child" default="default">
    <target name="default">
        <projectdetails name="childproperty" />
        <echo>In ${ant.project.name}: ${property}</echo>
        <echo>In ${ant.project.name}: ${childproperty}</echo>
    </target>
</project>

With the output of:

Buildfile: build.xml
[projectdetails] Setting property property
     [echo] In main: property
     [echo] forking to new Project:

default:
[projectdetails] Setting property childproperty
     [echo] In child: property
     [echo] In child: ${childproperty}
     [echo] Returned from new Project.
     [echo] In main: childproperty

Obviously, this is a contrived example to make it easier to
demonstrate.  I believe that the scriptdef is initialised at the point
of declaration and provided with a project object at that point and
then reused; my problem is that I expected the behaviour to mirror
that of ant-tasks/macrodefs, ie if I replace the scriptdef above with
a functionally equivilant macrodef I get the following output:

Buildfile: build.xml
     [echo] Setting property property
     [echo] In main: property
     [echo] forking to new Project:

default:
     [echo] Setting property childproperty
     [echo] In child: property
     [echo] In child: childproperty
     [echo] Returned from new Project.
     [echo] In main: ${childproperty}

Which is exactly the behavior that I'd expected based upon the
description of the <ant and <antcall targets.  Does anyone know if
this is a bug, or expected behaviour - also whether or not there is
any means of declaring a scriptdef to be reinitialised at each point
of use?

Thanks in advance,

Dave.

-- 
Dave Sowerby MEng MBCS

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


Mime
View raw message