ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: [Fwd: [New task] scripttypedef (or refectdef)]
Date Mon, 16 Feb 2004 12:07:59 GMT
Erik Hatcher wrote:

> So this would allow creating a filter, mapper, or other type 
> dynamically?  

Yes (well mapper's when the mapper type patch is applied).

> Nice!  Just a sanity check - there is no way to do this with scripting 
> stuff in 1.6.1 is there?

I was about to say that one could not but this is not
true:

    <script language="beanshell">
      import org.apache.tools.ant.Task;
      import org.apache.tools.ant.BuildException;
      import java.io.File;
      public class DeleteOnExit extends Task {
         private File file;
         public void setFile(File file) {
             this.file = file;
         }
         public void execute() {
             if (file == null) {
                throw new BuildException("Missing attribute file");
             }
             file.deleteOnExit();
         }
      }
      project.addDataTypeDefinition("deleteonexit", DeleteOnExit.class);
    </script>
    <deleteonexit file="tobedeleted"/>

works fine!

<scripttypedef> does however handle namespace,  antlib and <antcall> use.

>
>
>> package org.apache.tools.ant.taskdefs.optional;
>>
>> /**
>>  * Class to define an ant definition using a script that
>>  * can return a class that is a normal ant task/datatype.
>>  * If the language is beanshell it must be 2.0 or higher.
>>  * The other scripting currently known to work is
>>  * groovy (1.0beta3).
>>  * <p>
>>  * Note that if there is anything incorrect with the script
>>  * the warning message is quite cryptic.
>>  * </p>
>>  * This class is based in part on o.a.t.ant.util.ScriptRunner.
>>  * The main difference is that it does not define
>>  * beans. This is for three reasons:
>>  * <ol>
>>  * <li>The definition may be used in another project.</li>
>>  * <li>It should be possible to convert to java later.</li>
>
>
> And the third reason is?  :)

removed..... (I had problems with groovy and assumed it was due
to the references being defined).

Peter
Also the orignal posted code had a error:

            ClassLoader cl = createLoader();
            Thread.currentThread().setContextClassLoader(cl);
            manager.setClassLoader(cl);
should be:
            ClassLoader classloader = createLoader();
            Thread.currentThread().setContextClassLoader(classloader);
            manager.setClassLoader(classloader);

Peter



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


Mime
View raw message