ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Inger <ma...@sedonacorp.com>
Subject Re: MyVeryOwnTask
Date Thu, 18 Oct 2001 21:08:46 GMT
i don't think ant takes very kindly to tasks being in the
default package.  try putting your task in a package.

secondly, use the Task.log method to output information
rather than writing directly to the console

public void execute() throws BuildException
{
  log(msg, Project.MSG_INFO);
}


finally, call your task:

	<MyVeryOwnTask message="something...." />

and way deep down, ant sees you want to set an
attribute named "message", so it will look for
a method on your task called "setMessage" which
takes 1 string argument.  This is the very simple
case, and should suffice for a lot of the things
you would want to do.




On Thu, 2001-10-18 at 16:20, Christine.Woon@nurun.com wrote:
> 
> Hi guys,
> 
> How do I acutally implement this in a build.xml file?
> 
> -----------------------------------------------------------------
> import org.apache.tools.ant.BuildException;
> import org.apache.tools.ant.Task;
> import java.util.*;
> 
> public class MyVeryOwnTask extends Task {
> private String msg;
> 
> 
>   // The method executing the task
>   public void execute() throws BuildException {
>     System.out.println(msg);
>   }
> 
>   // The setter for the "message" attribute
>   public void setMessage(String msg) {
>     this.msg = msg;
>   }
> }
> -------------------------------------------------------------------
> 
> I know I put this in my init target: <taskdef name="MyVeryOwnTask"
> classname="MyVeryOwnTask"/>
> but I'm not sure where I specify the actual 'msg' that I want to print out
> to the screen, except that now
> I can do this: <MyVeryOwnTask ........./>
> 
> thanks
> 
-- 
Matt Inger (matt.inger@sedonacorp.com)
Sedona Corporation
455 S. Gulph Road, Suite 300
King of Prussia, PA 19406
(484) 679-2213
"Self-respect - the secure feeling that no one,
 as yet, is suspicious." -H.L. Mencken 


Mime
View raw message