List of usage examples for org.aspectj.bridge IMessageHolder getMessages
IMessage[] getMessages(IMessage.Kind kind, boolean orGreater);
From source file:org.eclipse.ajdt.core.ant.AjcTask.java
License:Open Source License
/** * Run the compile in the same VM by loading the compiler (Main), setting up any message holders, doing the compile, and * converting abort/failure and error messages to BuildException, as appropriate. * /* ww w. j a v a2 s . co m*/ * @return true on successful compilation * @throws BuildException if abort or failure messages or if errors and failonerror. * */ protected boolean executeInSameVM(String[] args) { if (null != maxMem) { log("maxMem ignored unless forked: " + maxMem, Project.MSG_WARN); } IMessageHolder holder = messageHolder; int numPreviousErrors; if (null == holder) { MessageHandler mhandler = new MessageHandler(true); final IMessageHandler delegate; delegate = new AntMessageHandler(this.logger, this.verbose, false); mhandler.setInterceptor(delegate); holder = mhandler; numPreviousErrors = 0; } else { numPreviousErrors = holder.numMessages(IMessage.ERROR, true); } AjdtCommandForAnt command = new AjdtCommandForAnt(); { Main newmain = new Main(); newmain.setCommand(command); newmain.setHolder(holder); newmain.setCompletionRunner(new Runnable() { public void run() { doCompletionTasks(); } }); if (null != main) { MessageUtil.fail(holder, "still running prior main"); return false; } main = newmain; } main.runMain(args, false); if (failonerror) { int errs = holder.numMessages(IMessage.ERROR, false); errs -= numPreviousErrors; if (0 < errs) { String m = errs + " errors"; MessageUtil.print(System.err, holder, "", MessageUtil.MESSAGE_ALL, MessageUtil.PICK_ERROR, true); throw new BuildException(m); } } // Throw BuildException if there are any fail or abort // messages. // The BuildException message text has a list of class names // for the exceptions found in the messages, or the // number of fail/abort messages found if there were // no exceptions for any of the fail/abort messages. // The interceptor message handler should have already // printed the messages, including any stack traces. // HACK: this ignores the Usage message { IMessage[] fails = holder.getMessages(IMessage.FAIL, true); if (!LangUtil.isEmpty(fails)) { StringBuffer sb = new StringBuffer(); String prefix = "fail due to "; int numThrown = 0; for (int i = 0; i < fails.length; i++) { String message = fails[i].getMessage(); if (LangUtil.isEmpty(message)) { message = "<no message>"; } else if (-1 != message.indexOf(USAGE_SUBSTRING)) { continue; } Throwable t = fails[i].getThrown(); if (null != t) { numThrown++; sb.append(prefix); sb.append(LangUtil.unqualifiedClassName(t.getClass())); String thrownMessage = t.getMessage(); if (!LangUtil.isEmpty(thrownMessage)) { sb.append(" \"" + thrownMessage + "\""); } } sb.append("\"" + message + "\""); prefix = ", "; } if (0 < sb.length()) { sb.append(" (" + numThrown + " exceptions)"); throw new BuildException(sb.toString()); } } } return command.isFailed(); }
From source file:org.eclipse.ajdt.core.ant.AJDT_AjcCompilerAdapter.java
License:Open Source License
public boolean execute() throws BuildException { javac.log(//w ww .j a v a2s . co m "Note that you may see messages about skipping *.aj files above. " + "These messages can be ignored as these files are handled directly by " + "ajc. Similarly, the messages below about skipping *.java files can be ignored.", Project.MSG_INFO); // javac task spits out messages that it if (null == javac) { throw new IllegalStateException("null javac"); } if (!((Boolean) inSelfCall.get()).booleanValue() && afterCleaningDirs()) { // if we are not re-calling ourself and we cleaned dirs, // then re-call javac to get the list of all source files. inSelfCall.set(Boolean.TRUE); javac.execute(); // javac re-invokes us after recalculating file list } else { try { AjcTask ajc = new AjcTask(); String err = ajc.setupAjc(javac); if (null != err) { throw new BuildException(err, javac.getLocation()); } addAJFiles(ajc); IMessageHolder handler = new MessageHandler(); ajc.setMessageHolder(handler); String logFile = null; String[] args = javac.getCurrentCompilerArgs(); for (int i = 0; i < args.length; i++) { if (args[i].equals("-log") && args.length > i) { logFile = args[i + 1]; ajc.setLog(new File(logFile)); break; } } ajc.execute(); // if log file is used, this message handler will never show any errors IMessage[] messages = handler.getMessages(IMessage.ERROR, true); if (messages != IMessage.RA_IMessage && logFile != null) { // log messages String msg = "Compilation has errors or warnings. Log is available in " + logFile; javac.log(msg, Project.MSG_INFO); return false; } else { return ajc.wasCompilationSuccessful(); } } finally { inSelfCall.set(Boolean.FALSE); } } return true; }