ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dawid Weiss <Dawid.We...@cs.put.poznan.pl>
Subject Re[4]: Embedded dynamic ANT tasks.
Date Tue, 10 Jun 2003 08:43:50 GMT

Ah... yeah - this is tricky.... but possible:

pr>    void execute() {      log("hello world");  }

not  possible  because  once  you're inside the script, you are not anymore
aware  that  you're  a  subclass  of some other method (BeanShell currently
doesn't support this).

pr>    void execute() {      this.log("hello world");  }

Nope,   all  BeanShell scripts have a 'this' object which is of type XThis.
Again:  beanshell  archtiecture,  which  is hard to modify (and it wouldn't
make much sense anyway - Pat knows what he's doing :).

pr>    void execute() {      global.log("hello world");  }

global is for "instance" scope. This is misleading, but is explained in the
BeanShell manual - in my application every script has its own namespace, so
it is like class's instance scope.

What  you  need  to  do  is  refer to methods of the 'self' object, which I
register  for  every  script  as  a  public  global  variable.  This is the
reference to your superclass.

So: self.log("hello world"); should do the trick.

check  out  the  examples (test cases) - there's some code that does access
superclass methods and fields.

Unfortunately  you won't be able to access protected methods/ fields of the
superclass - haven't figured out how to overcome this problem yet.

Dawid

pr> Hi Dawid,

pr> I have been playing with the dynamic bsh task.

pr> I have used the /*% extends org.apache.tools.ant.Task %*/
pr> comment to inform BSHWrapperClassGenerator to
pr> extend Task.
pr> This works but  I cannot figure out how to access the methods
pr> of the class.

pr> none of
pr>    void execute() {      log("hello world");  }
pr>    void execute() {      this.log("hello world");  }
pr>    void execute() {      global.log("hello world");  }
pr> work.

pr> Peter

pr> On Tuesday 10 June 2003 07:35, Dawid Weiss wrote:
>> Thanks   Erik.  I  indeed  don't  use  DynamicConfigurator  -  the code was
>> actually meant to demonstrate how BeanShell can be used to create real Java
>> classes...  so  it  has  deficiencies  of  course  ;)  It all can be fixed/
>> extended,  if  there's  a  need. I'm glad people liked what I've done and I
>> will certainly work on it.
>>
>> Sat, what is that Mutant proposal?
>>
>> Dawid
>>
>> EH> Very nice!  I've dreamed of something like this for a long while
>> EH> (probably a few minutes after I figured out how Ant tasks are written).
>> EH>   I believe at least the Mutant proposal had this capability too, so
>> EH> maybe its implementation can be revisited to compare with what you've
>> EH> done.  I've not looked under the covers of how you implemented it, but
>> EH> result is great).
>>
>> EH> I'm guessing you aren't using the DynamicConfigurator interface, based
>> EH> on a follow-up e-mail.  It seems like it would be a lighter-weight way
>> EH> to deal with attributes and sub-elements.
>>
>> EH> I'd be way psyched to have something like this added to Ant's core.
>>
>> EH>         Erik
>>
>> EH> On Friday, June 6, 2003, at 10:53  AM, Dawid Weiss wrote:
>> >> Dear ANT community,
>> >>
>> >> I thought one day: maybe it would be fun if I could define ANT tasks
>> >> INSIDE
>> >>
>> >> the  ANT  script that is being executed? So it could look like this:
>> >>> <!-- Define an embedded task and use it immediately -->
>> >>> <target name="example" depends="prepare">
>> >>>
>> >>>     <!-- define the task -->
>> >>>     <embeddedtaskdef name="counterTask"><![CDATA[
>> >>>         String message;
>> >>>         int    min;
>> >>>         int    max;
>> >>>
>> >>>         void setMin(int min) {
>> >>>             // note how 'global' is used instead of 'this'
>> >>>             // global scope refers to the task instance anyway.
>> >>>             global.min = min;
>> >>>         }
>> >>>
>> >>>         void setMax(int max) {
>> >>>             global.max = max;
>> >>>         }
>> >>>
>> >>>         void setMessage(String message) {
>> >>>             global.message = message;
>> >>>         }
>> >>>
>> >>>         void execute() {
>> >>>             if (message != null)
>> >>>                 System.out.print(message);
>> >>>             for (int i=min;i<max;i++) {
>> >>>                 System.out.print(i);
>> >>>                 if (i+1 != max) System.out.print(",");
>> >>>             }
>> >>>         }
>> >>>     ]]></embeddedtaskdef>
>> >>>
>> >>>     <!-- use the defined task right away! -->
>> >>>     <counterTask min="0" max="10" message="The numbers from 0 to
10
>> >>> are: " />
>> >>>     <counterTask min="5" max="20" message="And the numbers from 5
to
>> >>> 20 are: " />
>> >>> </target>
>> >>
>> >> I've played with BSH and BCEL and the solution can be found at:
>> >>
>> >> http://www.cs.put.poznan.pl/dweiss/index.php/projects/bsh-binding/
>> >> index.xml?lang=en
>> >>
>> >> I  personally find it quite a useful task, even though it started
>> >> purely as
>> >> a toy and a mind-exerciser :)
>> >>
>> >> Regards,
>> >> Dawid
>> >>
>> >> _______________________
>> >> Dawid Weiss, http://www.cs.put.poznan.pl/dweiss
>> >> Laboratory of Intelligent Decision Support Systems, Poznan UT, Poland
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> >> For additional commands, e-mail: user-help@ant.apache.org
>>
>> EH> ---------------------------------------------------------------------
>> EH> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> EH> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org


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


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


Mime
View raw message