import org.apache.tools.ant.*;
import org.apache.tools.ant.taskdefs.*;
import org.apache.tools.ant.types.*;
+import org.apache.tools.ant.util.TaskLogger;
import org.aspectj.bridge.*;
+import org.aspectj.bridge.IMessage.Kind;
import org.aspectj.tools.ajc.Main;
import org.aspectj.tools.ajc.Main.MessagePrinter;
import org.aspectj.util.*;
private boolean failonerror;
private boolean fork;
private String maxMem;
+ private TaskLogger logger;
// ------- single entries dumped into cmd
protected GuardedCommand cmd;
* or if there were compiler errors and failonerror is true.
*/
public void execute() throws BuildException {
+ this.logger = new TaskLogger(this);
if (executing) {
throw new IllegalStateException("already executing");
} else {
verifyOptions();
try {
String[] args = makeCommand();
- if (verbose || listFileArgs) { // XXX if listFileArgs, only do that
- log("ajc " + Arrays.asList(args), Project.MSG_VERBOSE);
- }
+ logVerbose("ajc " + Arrays.asList(args));
if (!fork) {
executeInSameVM(args);
} else { // when forking, Adapter handles failonerror
} catch (BuildException e) {
throw e;
} catch (Throwable x) {
- System.err.println(Main.renderExceptionForUser(x));
+ this.logger.error(Main.renderExceptionForUser(x));
throw new BuildException("IGNORE -- See "
+ LangUtil.unqualifiedClassName(x)
- + " rendered to System.err");
+ + " rendered to ant logger");
} finally {
executing = false;
if (null != tmpOutjar) {
ArrayList result = new ArrayList();
if (0 < ignored.size()) {
for (Iterator iter = ignored.iterator(); iter.hasNext();) {
- log("ignored: " + iter.next(), Project.MSG_INFO);
+ logVerbose("ignored: " + iter.next());
}
}
// when copying resources, use temp jar for class output
String path = outjar.getAbsolutePath();
int len = FileUtil.zipSuffixLength(path);
if (len < 1) {
- log("not copying resources - weird outjar: " + path);
+ this.logger.info("not copying resources - weird outjar: " + path);
} else {
path = path.substring(0, path.length()-len) + ".tmp.jar";
tmpOutjar = new File(path);
if (null == holder) {
MessageHandler mhandler = new MessageHandler(true);
final IMessageHandler delegate;
- delegate = verbose ? MessagePrinter.VERBOSE: MessagePrinter.TERSE;
+ delegate = new AntMessageHandler(this.logger,this.verbose);
mhandler.setInterceptor(delegate);
- if (!verbose) {
- mhandler.ignore(IMessage.INFO);
- }
holder = mhandler;
numPreviousErrors = 0;
} else {
*/
protected void executeInOtherVM(String[] args) {
if (null != messageHolder) {
- log("message holder ignored when forking: "
- + messageHolder.getClass().getName(), Project.MSG_WARN);
+ this.logger.warning("message holder ignored when forking: "
+ + messageHolder.getClass().getName());
}
CommandlineJava javaCmd = new CommandlineJava();
javaCmd.setClassname(org.aspectj.tools.ajc.Main.class.getName());
both[0] = path;
}
}
- if (verbose) { // XXX also when ant is verbose...
- log("forking " + Arrays.asList(both));
- }
+ logVerbose("forking " + Arrays.asList(both));
int result = execInOtherVM(both);
if (0 > result) {
throw new BuildException("failure[" + result + "] running ajc");
Project project = getProject();
PumpStreamHandler handler = new LogStreamHandler(this,
- Project.MSG_INFO, Project.MSG_WARN);
+ verbose ? Project.MSG_VERBOSE : Project.MSG_INFO,
+ Project.MSG_WARN);
// replace above two lines with what follows as an aid to debugging when running the unit tests....
// LogStreamHandler handler = new LogStreamHandler(this,
if (file.canRead() && FileUtil.hasSourceSuffix(file)) {
list.add(file.getAbsolutePath());
} else {
- log("skipping file: " + file, Project.MSG_WARN);
+ this.logger.warning("skipping file: " + file);
}
}
}
}
}
}
+
}
+ protected void logVerbose(String text) {
+ if (this.verbose) {
+ this.logger.info(text);
+ } else {
+ this.logger.verbose(text);
+ }
+ }
/**
* Commandline wrapper that
* only permits addition of non-empty values
}
}
}
+
+private static class AntMessageHandler implements IMessageHandler {
+
+ private TaskLogger logger;
+ private boolean taskLevelVerbose;
+
+ public AntMessageHandler(TaskLogger logger, boolean taskVerbose) {
+ this.logger = logger;
+ this.taskLevelVerbose = taskVerbose;
+ }
+
+ /* (non-Javadoc)
+ * @see org.aspectj.bridge.IMessageHandler#handleMessage(org.aspectj.bridge.IMessage)
+ */
+ public boolean handleMessage(IMessage message) throws AbortException {
+ Kind messageKind = message.getKind();
+ String messageText = message.toString();
+ if (messageKind == IMessage.ABORT) {
+ this.logger.error(messageText);
+ } else if (messageKind == IMessage.DEBUG) {
+ this.logger.debug(messageText);
+ } else if (messageKind == IMessage.ERROR) {
+ this.logger.error(messageText);
+ } else if (messageKind == IMessage.FAIL){
+ this.logger.error(messageText);
+ } else if (messageKind == IMessage.INFO) {
+ if (this.taskLevelVerbose) {
+ this.logger.info(messageText);
+ }
+ else {
+ this.logger.verbose(messageText);
+ }
+ } else if (messageKind == IMessage.WARNING) {
+ this.logger.warning(messageText);
+ } else if (messageKind == IMessage.WEAVEINFO) {
+ this.logger.info(messageText);
+ } else if (messageKind == IMessage.TASKTAG) {
+ // ignore
+ } else {
+ throw new BuildException("Unknown message kind from AspectJ compiler: " + messageKind.toString());
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.aspectj.bridge.IMessageHandler#isIgnoring(org.aspectj.bridge.IMessage.Kind)
+ */
+ public boolean isIgnoring(Kind kind) {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.aspectj.bridge.IMessageHandler#dontIgnore(org.aspectj.bridge.IMessage.Kind)
+ */
+ public void dontIgnore(Kind kind) {
+ }
+
+}
}