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[6]: Embedded dynamic ANT tasks.
Date Tue, 10 Jun 2003 09:08:26 GMT

Awesome!

Peter,   do   you   think  it would be potentially worthy to put the source
code   somewhere  where  people  could add/ modify things without branching
endlessly?   SourceForge? Would ant-contrib assign a spot in the CVS? I can
of  course  expose  CVS  from  my own server, but it would be probably more
natural if such extension were available on ANT's cvs somewhere...

Dawid

P.S. Send me the code, please - I would love to check it out! :)

pr> Excellent....
pr> This is mega cool.

pr> I modified DynamicBSHTask#execute to use createDataType() rather
pr> than createTask() and with ant 1.6 one can use the dynamic bsh
pr> to define conditions, filters, and tasks very easily:

pr> <project name="t">

pr>   <taskdef name="bshdef"
pr>            classname="com.dawidweiss.bsh.dynbinding.ant.DynamicBSHTask">
pr>   </taskdef>

pr>   <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

pr>   <target name="condition">
pr>     <bshdef name="all.lower">
pr>       /*% @implements org.apache.tools.ant.taskdefs.condition.Condition %*/
pr>       String message;

pr>       void setString(String message) {
pr>           global.message = message;
pr>       }

pr>       boolean eval() {
pr>           return (message.toLowerCase() == message);
pr>       }
pr>     </bshdef>
    
pr>     <if>
pr>       <all.lower string="this is lower"/>
pr>       <then>
pr>         <echo>the string is all lower</echo>
pr>       </then>
pr>     </if>

pr>   </target>

pr>   <target name="path">

pr>     <bshdef name="showpath">
pr>       /*% @extends org.apache.tools.ant.Task %*/
pr>       import org.apache.tools.ant.types.Path;

pr>       Path    path;

pr>       org.apache.tools.ant.types.Path createPath() {
pr>           global.path = new Path(self.getProject());
pr>           return global.path;
pr>       }

pr>       void execute() {
pr>          self.log("Path is " + global.path);
         
pr>       }
pr>     </bshdef>
    
pr>     <showpath>
pr>       <path>
pr>         <fileset dir="."/>
pr>       </path>
pr>     </showpath>
pr>   </target>


pr> </project>


pr> On Tuesday 10 June 2003 09:43, you wrote:
>> 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.

pr> My bad, I should have looked harder.
pr> Peter.

>>
>> 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> Ps.
pr> My direct e-mail gets bounced.


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