List of usage examples for org.aspectj.tools.ajc Main runMain
public void runMain(String[] args, boolean useSystemExit)
From source file:AjcCompiler.java
License:Open Source License
/** * Do the AspectJ compiling.// w w w.jav a 2 s . c o m * * @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. jav a 2 s.com * * @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 ww w. j av a2s . 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); } }