ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Morris" <dibbl...@hotmail.com>
Subject Wrapping an existing core Ant task
Date Mon, 13 Dec 2004 09:38:51 GMT
I am attempting to write an Ant task that wraps the 
org.apache.tools.ant.taskdefs.Java task.
I am having a problem in determining how it is intended by the Ant API to 
execute tasks manually.
For example, if I call org.apache.tools.ant.tasksdefs.Java.execute(), I 
receive a NullPointerException*.
Is there a standard way to invoke existing tasks through the Ant API?
Obviously the Ant framework does some setting up before calling execute(), 
hence the reason for the failure.
Is there an Ant API such as TaskExecuter.execute(Task)?
Assistance is most appreciated.

Please see the following test case which attempts to illustrate my objective 
in a trivial manner:

package org;

import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Java;

public class Hello extends Task
{
    private Java j;
    private String hello;

    public Hello()
    {
        j = new Java();
    }

    public void setHello(String hello)
    {
        this.hello = hello;
    }

    public void execute()
    {
        if(j == null)
        {
            throw new BuildException("j is null");
        }

        j.createArg().setValue(hello);
        j.setClassname("org.SayHello");
        j.setFork(true);
        j.execute();
    }
}

/*

<target name="sayhello">
	<taskdef name="sayhello" classname="org.Hello" classpathref="builds.path"/>

	<sayhello hello="World"/>
</target>

*build.xml:163: java.lang.NullPointerException
        at org.apache.tools.ant.Task.perform(Task.java:373)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.tools.ant.Target.performTasks(Target.java:369)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
        at org.apache.tools.ant.Main.runBuild(Main.java:673)
        at org.apache.tools.ant.Main.startAnt(Main.java:188)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
Caused by: java.lang.NullPointerException
        at org.apache.tools.ant.Task.log(Task.java:346)
        at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:137)
        at org.apache.tools.ant.taskdefs.Java.execute(Java.java:83)
        at org.Hello.execute(Hello.java:32)
        at 
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        ... 8 more
--- Nested Exception ---
java.lang.NullPointerException
        at org.apache.tools.ant.Task.log(Task.java:346)
        at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:137)
        at org.apache.tools.ant.taskdefs.Java.execute(Java.java:83)
        at org.Hello.execute(Hello.java:32)
        at 
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.tools.ant.Target.performTasks(Target.java:369)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
        at org.apache.tools.ant.Main.runBuild(Main.java:673)
        at org.apache.tools.ant.Main.startAnt(Main.java:188)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)

*/




Tony Morris
Gold Coast, Australia



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


Mime
View raw message