List of usage examples for org.aspectj.tools.ajc Main setHolder
public void setHolder(IMessageHolder holder)
From source file:AjcCompiler.java
License:Open Source License
/** * Do the AspectJ compiling./* w w w . j a v a2s .c om*/ * * @throws Exception */ public void execute() throws Exception { assembleArguments(); if (!forceAjcCompile && !hasSourcesToCompile()) { getLog().warning("No sources found skipping aspectJ compile"); return; } if (!forceAjcCompile && !isBuildNeeded()) { getLog().info("No modifications found skipping aspectJ compile"); return; } if (getLog().isLoggable(Level.INFO)) { String command = "Running : ajc"; Iterator iter = ajcOptions.iterator(); while (iter.hasNext()) { command += (" " + iter.next()); } getLog().info(command); } try { getLog().fine( "Compiling and weaving " + resolvedIncludes.size() + " sources to " + getOutputDirectory()); writeBuildConfigToFile(ajcOptions, argumentFileName, getOutputDirectory()); getLog().fine("Argumentsfile written : " + new File(getOutputDirectory(), argumentFileName).getAbsolutePath()); } catch (IOException e) { throw new Exception("Could not write arguments file to the target area", e); } Main main = new Main(); MavenMessageHandler mavenMessageHandler = new MavenMessageHandler(getLog()); main.setHolder(mavenMessageHandler); synchronized (BIG_ASPECTJ_LOCK) { main.runMain((String[]) ajcOptions.toArray(new String[ajcOptions.size()]), false); } IMessage[] errors = mavenMessageHandler.getMessages(IMessage.ERROR, true); if (!proceedOnError && errors.length > 0) throw new Exception(Arrays.asList(errors).toString()); }
From source file:de.zalando.mojo.aspectj.AbstractAjcCompiler.java
License:Open Source License
/** * Do the AspectJ compiling.//w w w . j av a 2 s . c o m * * @throws MojoExecutionException */ @SuppressWarnings("unchecked") public void execute() throws MojoExecutionException { if (isSkip()) { if (getLog().isInfoEnabled()) { getLog().info("Skipping execution because of 'skip' option"); } return; } ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler(); if (!"java".equalsIgnoreCase(artifactHandler.getLanguage())) { getLog().warn("Not executing aspectJ compiler as the project is not a Java classpath-capable package"); return; } // MASPECT-110: // // Only add the aspectSourcePathDir and testAspectSourcePathDir to their respective // compileSourceRoots if they actually exist and are directories... to avoid crashing // downstream plugins requiring/assuming that all entries within the compileSourceRoots // and testCompileSourceRoots are directories. // final File aspectSourcePathDir = FileUtils.resolveFile(basedir, aspectDirectory); final File testAspectSourcePathDir = FileUtils.resolveFile(basedir, testAspectDirectory); final String aspectSourcePath = aspectSourcePathDir.getAbsolutePath(); final String testAspectSourcePath = testAspectSourcePathDir.getAbsolutePath(); if (aspectSourcePathDir.exists() && aspectSourcePathDir.isDirectory() && !project.getCompileSourceRoots().contains(aspectSourcePath)) { getLog().debug("Adding existing aspectSourcePathDir [" + aspectSourcePath + "] to compileSourceRoots."); project.getCompileSourceRoots().add(aspectSourcePath); } else { getLog().debug("Not adding non-existent or already added aspectSourcePathDir [" + aspectSourcePath + "] to compileSourceRoots."); } if (testAspectSourcePathDir.exists() && testAspectSourcePathDir.isDirectory() && !project.getTestCompileSourceRoots().contains(testAspectSourcePath)) { getLog().debug("Adding existing testAspectSourcePathDir [" + testAspectSourcePath + "] to testCompileSourceRoots."); project.getTestCompileSourceRoots().add(testAspectSourcePath); } else { getLog().debug("Not adding non-existent or already added testAspectSourcePathDir [" + testAspectSourcePath + "] to testCompileSourceRoots."); } assembleArguments(); if (!forceAjcCompile && !hasSourcesToCompile()) { getLog().warn("No sources found skipping aspectJ compile"); return; } if (!forceAjcCompile && !isBuildNeeded()) { getLog().info("No modifications found skipping aspectJ compile"); return; } if (getLog().isDebugEnabled()) { StringBuilder command = new StringBuilder("Running : ajc"); for (String arg : ajcOptions) { command.append(' ').append(arg); } getLog().debug(command); } try { getLog().debug( "Compiling and weaving " + resolvedIncludes.size() + " sources to " + getOutputDirectory()); AjcHelper.writeBuildConfigToFile(ajcOptions, argumentFileName, getOutputDirectory()); getLog().debug("Arguments file written : " + new File(getOutputDirectory(), argumentFileName).getAbsolutePath()); } catch (IOException e) { throw new MojoExecutionException("Could not write arguments file to the target area", e); } final Main ajcMain = new Main(); MavenMessageHandler mavenMessageHandler = new MavenMessageHandler(getLog()); ajcMain.setHolder(mavenMessageHandler); synchronized (BIG_ASPECTJ_LOCK) { ajcMain.runMain((String[]) ajcOptions.toArray(new String[ajcOptions.size()]), false); } IMessage[] errors = mavenMessageHandler.getMessages(IMessage.ERROR, true); if (!proceedOnError && errors.length > 0) { throw CompilationFailedException.create(errors); } }
From source file:org.codehaus.mojo.aspectj.AbstractAjcCompiler.java
License:Open Source License
/** * Do the AspectJ compiling.//from w ww . j a v a 2 s . c om * * @throws MojoExecutionException */ @SuppressWarnings("unchecked") public void execute() throws MojoExecutionException { if (isSkip()) { if (getLog().isInfoEnabled()) { getLog().info("Skipping execution because of 'skip' option"); } return; } ArtifactHandler artifactHandler = project.getArtifact().getArtifactHandler(); if (!"java".equalsIgnoreCase(artifactHandler.getLanguage())) { getLog().warn("Not executing aspectJ compiler as the project is not a Java classpath-capable package"); return; } // MASPECT-110: // // Only add the aspectSourcePathDir and testAspectSourcePathDir to their respective // compileSourceRoots if they actually exist and are directories... to avoid crashing // downstream plugins requiring/assuming that all entries within the compileSourceRoots // and testCompileSourceRoots are directories. // final File aspectSourcePathDir = FileUtils.resolveFile(basedir, aspectDirectory); final File testAspectSourcePathDir = FileUtils.resolveFile(basedir, testAspectDirectory); final String aspectSourcePath = aspectSourcePathDir.getAbsolutePath(); final String testAspectSourcePath = testAspectSourcePathDir.getAbsolutePath(); if (aspectSourcePathDir.exists() && aspectSourcePathDir.isDirectory() && !project.getCompileSourceRoots().contains(aspectSourcePath)) { getLog().debug("Adding existing aspectSourcePathDir [" + aspectSourcePath + "] to compileSourceRoots."); project.getCompileSourceRoots().add(aspectSourcePath); } else { getLog().debug("Not adding non-existent or already added aspectSourcePathDir [" + aspectSourcePath + "] to compileSourceRoots."); } if (testAspectSourcePathDir.exists() && testAspectSourcePathDir.isDirectory() && !project.getTestCompileSourceRoots().contains(testAspectSourcePath)) { getLog().debug("Adding existing testAspectSourcePathDir [" + testAspectSourcePath + "] to testCompileSourceRoots."); project.getTestCompileSourceRoots().add(testAspectSourcePath); } else { getLog().debug("Not adding non-existent or already added testAspectSourcePathDir [" + testAspectSourcePath + "] to testCompileSourceRoots."); } assembleArguments(); if (!forceAjcCompile && !hasSourcesToCompile()) { getLog().warn("No sources found skipping aspectJ compile"); return; } if (!forceAjcCompile && !isBuildNeeded()) { getLog().info("No modifications found skipping aspectJ compile"); return; } if (getLog().isDebugEnabled()) { StringBuilder command = new StringBuilder("Running : ajc"); for (String arg : ajcOptions) { command.append(' ').append(arg); } getLog().debug(command); } try { getLog().debug( "Compiling and weaving " + resolvedIncludes.size() + " sources to " + getOutputDirectory()); AjcHelper.writeBuildConfigToFile(ajcOptions, argumentFileName, getOutputDirectory()); getLog().debug("Arguments file written : " + new File(getOutputDirectory(), argumentFileName).getAbsolutePath()); } catch (IOException e) { throw new MojoExecutionException("Could not write arguments file to the target area", e); } final Main ajcMain = new Main(); MavenMessageHandler mavenMessageHandler = new MavenMessageHandler(getLog()); ajcMain.setHolder(mavenMessageHandler); synchronized (BIG_ASPECTJ_LOCK) { ajcMain.runMain(ajcOptions.toArray(new String[ajcOptions.size()]), false); } IMessage[] errors = mavenMessageHandler.getMessages(IMessage.ERROR, true); if (!proceedOnError && errors.length > 0) { throw CompilationFailedException.create(errors); } }
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 a 2 s . c o 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(); }