ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: [Q:] Writing a simple Ant task?
Date Thu, 26 Sep 2002 15:40:53 GMT
Calling me a liar, hummm ;-)

Then look at what's below! In Ant 1.4.1, a non-Task deriving class needs to
have a setProject(Project) method to work... Not deriving from Task is to
not have dependencies on Ant at all (a pure Bean), so requiring a method to
take an Ant class as argument pretty much defeats that purpose.

So granted, one can have a non-task deriving class in Ant 1.4.1, but only if
it has this setProject(org.apache.tools.ant.Project project) method.
Otherwise, it fails. Ant 1.5 OTOH doesn't need that method, and can use a
pure Bean with ZERO dependencies on Ant.

So I maintain that Ant 1.5 is the only version of Ant I know of that support
arbitrary classes as task using the bean pattern. I don't know if pre-1.4.1
worked better than 1.4.1... --DD


P:\org_apache\antx\echo-task>set ANT_HOME=C:\pro\ant

P:\org_apache\antx\echo-task>%ANT_HOME%\bin\ant
Buildfile: build.xml

compile:
    [javac] Compiling 1 source file

taskdef:

test:
   [myecho] Error setting project in class EchoTask

BUILD FAILED

P:\org_apache\antx\echo-task\build.xml:9: java.lang.NoSuchMethodException:
setProject

Total time: 1 second
P:\org_apache\antx\echo-task>set ANT_HOME=C:\pro\ant1.5

P:\org_apache\antx\echo-task>%ANT_HOME%\bin\ant
Buildfile: build.xml

compile:

taskdef:

test:
   [myecho] Hurra

BUILD SUCCESSFUL
Total time: 1 second
P:\org_apache\antx\echo-task>type EchoTask.java
/**
 * Simple task to demonstrate one doesn't need any dependency on ANT
 * to be a custom ANT task.
 *
 * @author <a href="mailto:ddevienne@lgc.com">Dominique Devienne</a>
 * @version May 2002 - Copyright (c) 2002, Landmark Graphics Corp.
 */
public class EchoTask {

  private String _message = "<none>";

  public void setProject(Object project) {
    System.out.println("setProject called with "+project);
  }

  public void setMessage(String message) {
    _message = message;
  }

  public void execute() {
    System.out.println(_message);
  }

} // END class EchoTask

P:\org_apache\antx\echo-task>REM edit EchoTask.java to take an Ant Project
P:\org_apache\antx\echo-task>%ANT_HOME%\bin\ant
Buildfile: build.xml

compile:
    [javac] Compiling 1 source file

taskdef:

test:
   [myecho] setProject called with org.apache.tools.ant.Project@bd2664
   [myecho] Hurra

BUILD SUCCESSFUL
Total time: 2 seconds
P:\org_apache\antx\echo-task>set ANT_HOME=C:\pro\ant

P:\org_apache\antx\echo-task>%ANT_HOME%\bin\ant
Buildfile: build.xml

compile:

taskdef:

test:
   [myecho] setProject called with org.apache.tools.ant.Project@1ddcde
   [myecho] Hurra

BUILD SUCCESSFUL

Total time: 0 seconds
P:\org_apache\antx\echo-task>type EchoTask.java
/**
 * Simple task to demonstrate one doesn't need any dependency on ANT
 * to be a custom ANT task.
 *
 * @author <a href="mailto:ddevienne@lgc.com">Dominique Devienne</a>
 * @version May 2002 - Copyright (c) 2002, Landmark Graphics Corp.
 */
public class EchoTask {

  private String _message = "<none>";

  public void setProject(org.apache.tools.ant.Project project) {
    System.out.println("setProject called with "+project);
  }

  public void setMessage(String message) {
    _message = message;
  }

  public void execute() {
    System.out.println(_message);
  }

} // END class EchoTask

P:\org_apache\antx\echo-task>
P:\org_apache\antx\echo-task>type build.xml
<?xml version="1.0"?>

<!-- ANT build file to test a specific feature or bug of ANT.
     Dominique Devienne <ddevienne@lgc.com>         Sep 2002
  -->
<project name="echo-task" default="test">

  <target name="test" depends="compile, taskdef">
    <myecho message="Hurra" />
  </target>

  <target name="compile">
    <javac srcdir="." includes="EchoTask.java" />
  </target>

  <target name="taskdef">
    <taskdef name="myecho" classname="EchoTask" classpath="." />
  </target>

</project>

P:\org_apache\antx\echo-task>

-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org] 
Sent: Thursday, September 26, 2002 1:04 AM
To: ant-user@jakarta.apache.org
Subject: Re: [Q:] Writing a simple Ant task?

On Wed, 25 Sep 2002, Erik Hatcher <jakarta-ant@ehatchersolutions.com>
wrote:

> Actually even in Ant 1.4.1 a task didn't need to extend from Task
> either,

Actually even in Ant 1.1 a task didn't need to extend from Task
either. 8-)

I think it almost never had to, let me see, TaskAdapter has been added
to Ant's CVS by Costin on 2000-01-27, so since then tasks didn't need
to extend Task anymore.

Stefan

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

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


Mime
View raw message