ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: Re[4]: Embedded dynamic ANT tasks.
Date Tue, 10 Jun 2003 09:06:32 GMT
Excellent....
This is mega cool.

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

<project name="t">

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

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

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

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

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

  </target>

  <target name="path">

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

      Path    path;

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

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


</project>


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.

My bad, I should have looked harder.
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

Ps.
My direct e-mail gets bounced.


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


Mime
View raw message