Hello,
I am having a problem with Ant that has me slightly baffled and very
frustrated. It seems my custom ant tasks will not be run if they are
inside an ant target called via "antcall". The set properties will
however be called. For instance, in the code below, the setMessage and
setFile methods on RCG task used in "utilities-build" will be called
but the execute method will not if the target "test" is run (which
makes an antcall to utilities-build). If "utilities-build" is directly
executed, then the execute method of RCGenericLog will be run. I have
confirmed this with other ant tasks I have written and been using.
Note, using the "ant" tag to run a target in another file does not
cause a problem- furthermore, targets run as a result of the "depends"
attribute do not suffer this problem. So, what the heck is going on
here - I'll look at the ant src next but has anyone run into ! this? It
looks as if ant has been specifically coded to behave this way. Note,
ONLY tasks that I write are affected by this - tasks that come with ant
don't experience this.
Ryan
RCG.java ------------------------------------------------------------
package com.kodak.sis.ant;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import java.util.Date;
import java.util.List;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.IOException;
public class RCG extends Task {
private String m_file;
private String m_message;
public void setFile ( String file ) {
log ( "setFile." );
m_file = file;
}
public void setMessage ( String message ) {
log ( "setMessage." );
m_message = message;
}
public void execute() throws BuildException {
log (
"-----------------------------------------------------------------------
-----------------------------------executing." );
System.exit(1);
try {
Project proj = getProject();
String fo = proj.getBaseDir().getName() + File.separator +
m_file;
log ( "Generic Log: " + fo );
File fot = new File(fo);
if ( !fot.exists() ) {
fot.createNewFile();
}
FileOutputStream fs = new FileOutputStream(fo,true);
OutputStreamWriter out = new OutputStreamWriter(fs);
out.write(m_message);
out.close();
fs.close();
} catch (IOException e) {
log ( e.toString() );
throw new BuildException ( e );
}
}
}