ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Hatcher" <jakarta-...@ehatchersolutions.com>
Subject Re: [PATCH] Script enhancement to standardize the "project" object exposed
Date Fri, 28 Sep 2001 05:50:36 GMT
I'm all for "target" being added also.   Actually if we just add "this"::

    beans.put("this", this);

it would give access to the instance of the <script> task itself which could
then get the project and target directly using getProject and
getOwningTarget.

Actually using "this" seems to be the cleanest short-term patch in order to
allow easy access to everything a custom task could access under a simple
pre-defined fixed name.   I had thought of this change before, but didn't
remember that idea until you brought up the "target" suggestion.

Could whoever commit this modify the Script.java change to the above?

Thanks,
    Erik

----- Original Message -----
From: "Phil Surette" <philsurette@home.com>
To: <ant-dev@jakarta.apache.org>
Cc: <ant-user@jakarta.apache.org>
Sent: Friday, September 28, 2001 1:13 AM
Subject: Re: [PATCH] Script enhancement to standardize the "project" object
exposed


> What about adding in the target as well, e.g. something like:
>
>              addBeans(project.getTargets());
>              addBeans(project.getReferences());
>
>              beans.put("project", getProject());
>
> +            beans.put("target", getOwningTarget());
> +
>              BSFManager manager = new BSFManager ();
>
> When I first started using the script tag a couple of weeks ago
> I just naturally expected to see both the target and the
> project predefined in all scripts. They are the context for the
> script. Having access to the grandparent (project) - while a
> _big_ improvement - without access to the parent (target)
> just seems wrong somehow.
>
> (yes, you can get at the target if you know its name, but this
> is just as inelegant as needing to know the project name: it creates
> an easily broken dependency between the task name and the embedded
> script and a real trap for all those cut-and-pasters out there)
>
> Erik Hatcher wrote:
> >
> > Well, with a +1000000, I couldn't resist making the change I proposed.
:)
> >
> > Attached is a patch against the ANT_14 versions of Script.java and the
> > documentation file for this task.
> >
> > Here is the sample build file that I used to test my change with:
> >
> > <project default="test">
> >   <target name="test">
> >     <script language="javascript"> <![CDATA[
> >       echo = project.createTask("echo");
> >       main.addTask(echo);
> >       for (i=1; i<=10; i++) {
> >         echo.setMessage(i*i);
> >         echo.execute();
> >       }
> >     ]]> </script>
> >   </target>
> >
> >   <target name="main"/>
> > </project>
> >
> > ----- Original Message -----
> > From: "Peter Donald" <donaldp@apache.org>
> > To: <ant-user@jakarta.apache.org>
> > Sent: Thursday, September 27, 2001 5:01 PM
> > Subject: Re: Javascript errors
> >
> > > On Fri, 28 Sep 2001 05:06, Erik Hatcher wrote:
> > > > This problem actually could be alleviated with a patch to the
<script>
> > task
> > > > such that the project reference was fed to BSF with the name
"project"
> > > > rather than as the name of the project.   I've got a few such
similar
> > > > patches on my to-do list for the <script> task to make using it
easier.
> > I
> > > > won't have time to get to this patch very soon though, but it
appears to
> > be
> > > > a straightforward change.
> > >
> > > +1000000 ;)
> > >
> > > --
> > > Cheers,
> > >
> > > Pete
> > >
> > > When a stupid man is doing something he's ashamed of, he always
> > > declares that it is his duty.
> > > George Bernard Shaw
> > >
> >
>
  ------------------------------------------------------------------------
> >                     Name: patchfile.txt
> >    patchfile.txt    Type: Plain Text (text/plain)
> >                 Encoding: quoted-printable
>


Mime
View raw message