You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by graste <gr...@gmail.com> on 2005/08/12 15:21:26 UTC

Call Ant task from java file

Hi,

I'm new to ant tasks and their use outside of ant. I want to execute ent  
tasks outside of build.xml in a simple java class.

My sample source code (inside a public static method of a plugin):
----------
// project
Project project = new Project();
project.init();
// fileset
FileSet fs = new FileSet();
fs.setIncludes("**/CVS");
fs.setDir(new File(exportDirectory));
// delete task properties
Delete delTask = new Delete();
delTask.setProject(project);
delTask.addFileset(fs);
delTask.setIncludeEmptyDirs(true);
// execute task
delTask.execute();
----------

First question: What am I doing wrong? I want to delete all directories  
called "CVS" in the specified folder. So what's the common workflow to use  
ant tasks outside of ant?
Second question: How can I get the log messages of the task? I thought  
about getting them as a String.

BuildLogger log = new DefaultLogger();
log.setMessageOutputLevel(Project.MSG_VERBOSE);
log.setOutputPrintStream(System.out);
log.setErrorPrintStream(System.out);
project.addBuildListener(log);

How do I have to use the above methods to get the log messages as one  
single string? Or aren't these message the ones I'm looking for?

Thanks in advance for ANY help (or helpful URLs at least). :)

Regards,

Steffen Gransow

-- 
Using Opera8

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