ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jose Alberto Fernandez" <j_a_fernan...@yahoo.com>
Subject Re: [PATCH] Script enhancement to standardize the "project" object exposed
Date Fri, 28 Sep 2001 07:59:43 GMT
Taking a look at your script, shouldn't we be able to say:

    me.project  and me.owningTarget

no need to call the method invocation me.getProject(), etc.

With respect to the name, I would propose either "script" or "thisScript". What people think?

Jose Alberto

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


> Actually I just tried "this" and it doesn't work.... it must be a special
> BSF auto-provided object which contains all the other objects that
> Script.java exposed (a "for each in" gave me that info).
> 
> I modified it to be "me", like below:
> 
>             beans.put("me", this);
> 
> and it all worked well.  So anything other than "this" would be fine.   What
> is the best choice?   "me"?   "task"?  "thisTask"?   Here is my example
> script now:
> 
> <project default="test">
>   <property name="xyz" value="123"/>
>   <target name="test">
>     <script language="javascript"> <![CDATA[
>       proj = me.getProject();
>       echo = proj.createTask("echo");
>       main.addTask(echo);
>       for (i in me) {
>         echo.setMessage(i);
>         echo.execute();
>       }
>     ]]> </script>
>   </target>
>   <target name="main"/>
> </project>
> 
> I'm sure there is a better way to get output, but I'm just using the method
> shown in the documentation for now.   The above outputs this which shows
> that "me" is a Task and has access to all the methods and member variables:
> 
>      [echo] getTaskName
>      [echo] location
>      [echo] taskName
>      [echo] notifyAll
>      [echo] runtimeConfigurableWrapper
>      [echo] project
>      [echo] setLocation
>      [echo] setTaskName
>      [echo] setProject
>      [echo] getRuntimeConfigurableWrapper
>      [echo] setSrc
>      [echo] log
>      [echo] execute
>      [echo] setDescription
>      [echo] addText
>      [echo] getDescription
>      [echo] equals
>      [echo] notify
>      [echo] class
>      [echo] perform
>      [echo] wait
>      [echo] setOwningTarget
>      [echo] toString
>      [echo] hashCode
>      [echo] description
>      [echo] init
>      [echo] setLanguage
>      [echo] getProject
>      [echo] maybeConfigure
>      [echo] getOwningTarget
>      [echo] getClass
>      [echo] owningTarget
>      [echo] getLocation
> 
> I'll gladly submit an updated patch once we decide the best name for the
> task and if we want to expose the Project directly, although I'm inclined to
> only expose the Task and let the script get at the project reference if it
> wants.   If a committer patches it, please make sure to modify the
> documentation patch to match the actual name chosen and to reflect that its
> a Task object now rather than a Project.
> 
>     Erik
> 
> ----- Original Message -----
> From: "Erik Hatcher" <jakarta-ant@ehatchersolutions.com>
> To: "ant-dev" <ant-dev@jakarta.apache.org>
> Cc: <philsurette@home.com>
> Sent: Thursday, September 27, 2001 10:50 PM
> Subject: Re: [PATCH] Script enhancement to standardize the "project" object
> exposed
> 
> 
> > 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
> > >
> >
> >
> 


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Mime
View raw message