You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2009/01/02 15:10:23 UTC
svn commit: r730725 - in /labs/magma/trunk/maven-magma-plugin: ./
src/main/java/org/apache/magma/tools/maven/
Author: simoneg
Date: Fri Jan 2 06:10:23 2009
New Revision: 730725
URL: http://svn.apache.org/viewvc?rev=730725&view=rev
Log:
LABS-201 : basic procedure for complete build
Added:
labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/AjcCompilerException.java
labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/AjcLauncher.java
labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MavenMessageHandler.java
Modified:
labs/magma/trunk/maven-magma-plugin/pom.xml
labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java
Modified: labs/magma/trunk/maven-magma-plugin/pom.xml
URL: http://svn.apache.org/viewvc/labs/magma/trunk/maven-magma-plugin/pom.xml?rev=730725&r1=730724&r2=730725&view=diff
==============================================================================
--- labs/magma/trunk/maven-magma-plugin/pom.xml (original)
+++ labs/magma/trunk/maven-magma-plugin/pom.xml Fri Jan 2 06:10:23 2009
@@ -14,10 +14,7 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--->
-<project
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+--><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<packaging>maven-plugin</packaging>
<groupId>org.apache.magma.tools</groupId>
@@ -60,7 +57,17 @@
<artifactId>aspectjtools</artifactId>
<version>1.6.1</version>
</dependency>
- </dependencies>
+ <dependency>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa</artifactId>
+ <version>1.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-archiver</artifactId>
+ <version>2.0</version>
+ </dependency>
+ </dependencies>
<build>
<plugins>
<plugin>
@@ -100,4 +107,4 @@
</url>
</snapshotRepository>
</distributionManagement>
-</project>
+</project>
\ No newline at end of file
Added: labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/AjcCompilerException.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/AjcCompilerException.java?rev=730725&view=auto
==============================================================================
--- labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/AjcCompilerException.java (added)
+++ labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/AjcCompilerException.java Fri Jan 2 06:10:23 2009
@@ -0,0 +1,34 @@
+package org.apache.magma.tools.maven;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.aspectj.bridge.IMessage;
+
+public class AjcCompilerException extends MojoExecutionException {
+ private IMessage[] errors;
+
+ public AjcCompilerException( IMessage[] errors )
+ {
+ super( composeMessage( errors ) );
+ this.errors = errors;
+ }
+
+ public IMessage[] getErrors()
+ {
+ return errors;
+ }
+
+ private static final String composeMessage( IMessage[] errors ) {
+ StringBuffer sb = new StringBuffer();
+
+ sb.append( "Compiler errors : \n" );
+ for ( int i = 0; i < errors.length; i++ )
+ {
+ sb.append( errors[i].toString() );
+ sb.append( "\n" );
+ }
+
+ return sb.toString();
+ }
+
+
+}
Added: labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/AjcLauncher.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/AjcLauncher.java?rev=730725&view=auto
==============================================================================
--- labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/AjcLauncher.java (added)
+++ labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/AjcLauncher.java Fri Jan 2 06:10:23 2009
@@ -0,0 +1,236 @@
+package org.apache.magma.tools.maven;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.logging.Log;
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.MessageHandler;
+import org.aspectj.tools.ajc.Main;
+
+public class AjcLauncher {
+
+
+ public Set<String> inpath = new HashSet<String>();
+ public Set<String> aspectpath = new HashSet<String>();
+ public Set<String> sourceroots = new HashSet<String>();
+ public Set<String> classpath = new HashSet<String>();
+ public Set<String> bootclasspath = new HashSet<String>();
+ public Set<String> extdirs = new HashSet<String>();
+
+ public File outdir = null;
+ public File outjar = null;
+
+ public boolean outxml = true;
+ public String outxmlfile = null;
+ public boolean crossrefs = false;
+
+ public String source = "1.5";
+ public String target = "1.5";
+
+ public Properties xlintErrors = new Properties();
+
+ public boolean proceedOnError = false;
+
+ public Set<String> warn = new HashSet<String>();
+
+ public boolean debug = true;
+ public boolean preserveAllLocals = true;
+ public String encoding = "UTF-8";
+
+ public Set<String> xopts = new HashSet<String>();
+
+ public Log mavenLogger = null;
+
+ public Set<String> defaultArtifactExcludes = new HashSet<String>();
+
+ {
+ defaultArtifactExcludes.add("junit");
+ defaultArtifactExcludes.add("org.jmock");
+ defaultArtifactExcludes.add("aspectj");
+ defaultArtifactExcludes.add("com.sun:tools");
+ }
+
+ public IMessage[] start() {
+ MessageHandler holder = null;
+ if (mavenLogger != null) {
+ holder = new MavenMessageHandler(mavenLogger);
+ } else {
+ // TODO what holder to use?
+ }
+ return start(holder);
+ }
+
+ public IMessage[] start(MessageHandler h) {
+ Main m = new Main();
+ String[] commandLine = buildCommandLine();
+ m.run(commandLine, h);
+ if (h == null) return null;
+ return h.getErrors();
+ }
+
+ public String[] buildCommandLine() {
+ List<String> params = new ArrayList<String>();
+
+ if (inpath.size() > 0) {
+ params.add("-inpath");
+ addPath(params, inpath);
+ }
+ if (aspectpath.size() > 0) {
+ params.add("-aspectpath");
+ addPath(params, aspectpath);
+ }
+ if (outxml) {
+ params.add("-outxml");
+ }
+ if (outxmlfile != null) {
+ params.add("-outxmlfile");
+ params.add(outxmlfile);
+ }
+ if (sourceroots.size() > 0) {
+ params.add("-sourceroots");
+ addPath(params, sourceroots);
+ }
+ if (crossrefs) {
+ params.add("-crossrefs");
+ }
+ if (classpath.size() > 0) {
+ params.add("-classpath");
+ addPath(params, classpath);
+ }
+ if (bootclasspath.size() > 0) {
+ params.add("-bootclasspath");
+ addPath(params, bootclasspath);
+ }
+ if (extdirs.size() > 0) {
+ params.add("-extdirs");
+ addPath(params, extdirs);
+ }
+ if (outdir != null) {
+ params.add("-d");
+ params.add(outdir.getAbsolutePath());
+ } else if (outjar != null) {
+ params.add("-outjar");
+ params.add(outjar.getAbsolutePath());
+ }
+ if (source != null) {
+ params.add("-source");
+ addVersion(params, source);
+ }
+ if (target != null) {
+ params.add("-target");
+ addVersion(params, target);
+ }
+ if (proceedOnError) {
+ params.add("-proceedOnError");
+ }
+ if (debug) {
+ params.add("-g");
+ }
+ if (preserveAllLocals) {
+ params.add("-preserveAllLocals");
+ }
+ if (encoding != null) {
+ params.add("-encoding");
+ params.add(encoding);
+ }
+ if (warn.size() > 0) {
+ StringBuilder warnparam = new StringBuilder();
+ warnparam.append("-warn:");
+ for (String item : warn) {
+ warnparam.append(item);
+ warnparam.append(',');
+ }
+ warnparam.deleteCharAt(warnparam.length() - 1);
+ params.add(warnparam.toString());
+ }
+ if (xopts.size() > 0) {
+ for (String opt : xopts) {
+ params.add(opt);
+ }
+ }
+ if (xlintErrors.size() > 0) {
+ try {
+ File tmpxlints = File.createTempFile("aspectjXlint", ".properties");
+ tmpxlints.deleteOnExit();
+ FileWriter fw = new FileWriter(tmpxlints);
+ for (Map.Entry<Object, Object> entry : xlintErrors.entrySet()) {
+ fw.write(entry.getKey().toString());
+ fw.write(" = ");
+ fw.write(entry.getValue().toString());
+ fw.write("\n");
+ }
+ fw.close();
+ params.add("-Xlintfile");
+ params.add(tmpxlints.getAbsolutePath());
+ } catch (IOException e) {
+ throw new RuntimeException("Error writing temporary xlint configuration file", e);
+ }
+ }
+ return params.toArray(new String[params.size()]);
+ }
+
+ private void addVersion(List<String> params, String ver) {
+ params.add(ver);
+ }
+
+ private void addPath(List<String> params, Set<String> path) {
+ StringBuilder pathparam = new StringBuilder();
+ for (String acp : path) {
+ pathparam.append(acp);
+ pathparam.append(File.pathSeparatorChar);
+ }
+ pathparam.deleteCharAt(pathparam.length() - 1);
+ params.add(pathparam.toString());
+ }
+
+
+ /**
+ * @param path The path we are going to modify
+ * @param artifacts Set of {@link Artifact}s to add
+ * @param excludes Set of groupIds to exclude
+ */
+ public void addArtifactsToPath(Set<String> path, Set artifacts, Set<String> excludes) {
+ for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) {
+ Artifact art = (Artifact) iterator.next();
+ addArtifactToPath(path, art, excludes);
+ }
+ }
+
+ public boolean addArtifactToPath(Set<String> path, Artifact art, Set<String> excludes) {
+ if (excludes == null) excludes = defaultArtifactExcludes;
+ if (excludes.contains(art.getGroupId()) || excludes.contains(art.getGroupId() + ":" + art.getArtifactId())) return false;
+ File artifact = art.getFile();
+ if ( null != artifact ) {
+ path.add(artifact.getAbsolutePath());
+ }
+ return true;
+ }
+
+
+
+ public void addFilesToPath(Set<String> path, File... files) {
+ for (File file : files) {
+ addFileToPath(path, file);
+ }
+ }
+
+ public void addFileToPath(Set<String> path, File file) {
+ if (file.exists()) {
+ path.add(file.getAbsolutePath());
+ }
+ }
+
+
+}
Modified: labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java?rev=730725&r1=730724&r2=730725&view=diff
==============================================================================
--- labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java (original)
+++ labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java Fri Jan 2 06:10:23 2009
@@ -16,28 +16,297 @@
*/
package org.apache.magma.tools.maven;
+import java.io.File;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.mojo.aspectj.Module;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
+import org.apache.openjpa.enhance.PCEnhancer;
+import org.apache.openjpa.lib.conf.Configuration;
+import org.apache.openjpa.lib.util.Options;
+import org.apache.openjpa.util.ClassResolver;
+import org.aspectj.bridge.IMessage;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
+import org.codehaus.plexus.util.FileUtils;
/**
-* @goal magma-deploy
+* @goal war
* @requiresDependencyResolution compile
-* @phase process-sources
+* @phase compile
* @description Magma AspectJ Compiler Plugin.
* @author <a href="mailto:simoneg@apache.org">Simone Gianni</a>
*/
-public class MagmaAjcCompleteCompileMojo extends MagmaAjcCompileMojo {
+public class MagmaAjcCompleteCompileMojo extends AbstractMojo implements Contextualizable {
- protected void assembleArguments() throws MojoExecutionException {
- super.weaveDependencies = ModulesPreparer.prepareModules(project);
- super.assembleArguments();
- this.ajcOptions.add("-Xlint:warning");
+ /**
+ * The maven project.
+ *
+ * @parameter expression="${project}"
+ * @required @readonly
+ */
+ protected MavenProject project;
+
+ /**
+ * The basedir of the project.
+ *
+ * @parameter expression="${basedir}"
+ * @required @readonly
+ */
+ protected File basedir;
+
+ private PlexusContainer container;
+
+ /**
+ * Resolves the artifacts needed.
+ *
+ * @component
+ */
+ private ArtifactResolver artifactResolver;
+
+ /**
+ * ArtifactRepository of the localRepository. To obtain the directory of localRepository in unit tests use
+ * System.setProperty( "localRepository").
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
+ private ArtifactRepository localRepository;
+
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ Set artifacts = project.getArtifacts();
+ for (Object object : artifacts) {
+ try {
+ artifactResolver.resolve((Artifact)object, Collections.EMPTY_LIST, localRepository);
+ } catch (ArtifactResolutionException e) {
+ throw new MojoExecutionException("Error resolving artifacts", e);
+ } catch (ArtifactNotFoundException e) {
+ throw new MojoExecutionException("Error resolving artifacts", e);
+ }
+ }
+
+ getLog().info("Compiling classes and aspects in local project");
+ File baseout = new File(project.getBuild().getOutputDirectory());
+ baseout.mkdirs();
+ AjcLauncher launcher = new AjcLauncher();
+ launcher.xlintErrors.setProperty("cantFindType", "warning");
+ launcher.xlintErrors.setProperty("adviceDidNotMatch", "ignore");
+
+ launcher.mavenLogger = getLog();
+ launcher.outdir = baseout;
+ launcher.addArtifactsToPath(launcher.aspectpath, project.getArtifacts(), null);
+ List<URL> cpurls = new ArrayList<URL>();
+
+ launcher.classpath = launcher.aspectpath;
+ List sourceRoots = project.getCompileSourceRoots();
+ for (Object sr : sourceRoots) {
+ File srf = new File((String)sr);
+ launcher.addFileToPath(launcher.sourceroots, srf);
+ }
+ IMessage[] errors = launcher.start();
+ if (errors != null && errors.length > 0) {
+ throw new AjcCompilerException(errors);
+ }
+ jpaEnhance(launcher.aspectpath, null, baseout);
+
+ getLog().info("Weaving dependency JARs one by one");
+ List<File> weavedjars = new ArrayList<File>();
+ List<Artifact> skippeds = new ArrayList<Artifact>();
+ launcher.outdir = null;
+ launcher.sourceroots.clear();
+ launcher.outxml = false;
+ launcher.outxmlfile = null;
+ launcher.addFilesToPath(launcher.aspectpath, baseout);
+ for (Object artobj : project.getArtifacts()) {
+ Artifact art = (Artifact) artobj;
+ getLog().info("Weaving " + ArtifactUtils.versionlessKey(art) + " " + art.getVersion());
+ launcher.inpath.clear();
+ if (launcher.addArtifactToPath(launcher.inpath, art, null)) {
+ String fname = art.getGroupId() + "-" + art.getArtifactId() + "-";
+ fname += art.getVersion() + "-WEAVED";
+ File outdir = new File(baseout.getParentFile(), fname);
+ outdir.mkdirs();
+ launcher.outdir = outdir;
+ errors = launcher.start();
+ if (errors != null && errors.length > 0) {
+ throw new AjcCompilerException(errors);
+ }
+
+ jpaEnhance(launcher.aspectpath, art, outdir);
+ getLog().info("Rejarring modified classes");
+ File destjar = new File(baseout.getParentFile(), fname + ".jar");
+ try {
+ MavenArchiver archiver = new MavenArchiver();
+ JarArchiver jarArchiver = (JarArchiver) container.lookup("org.codehaus.plexus.archiver.Archiver","jar");
+ archiver.setArchiver(jarArchiver);
+ archiver.setOutputFile(destjar);
+ archiver.getArchiver().addDirectory(outdir);
+ MavenArchiveConfiguration conf = new MavenArchiveConfiguration();
+ archiver.createArchive(project, conf);
+ FileUtils.deleteDirectory(outdir);
+ } catch (Exception e) {
+ throw new RuntimeException("Error creating zip file " + destjar.getAbsolutePath(), e);
+ }
+ weavedjars.add(destjar);
+ getLog().info("Done");
+ } else {
+ skippeds.add(art);
+ getLog().info("Skipped");
+ }
+ }
+
+ getLog().info("Should assemble : ");
+ for (Artifact artifact : skippeds) {
+ getLog().info(" " + artifact.getFile().getAbsolutePath());
+ }
+ for (File file : weavedjars) {
+ getLog().info(" " + file.getAbsolutePath());
+ }
+
+ }
+
+ private String urlsAsStrings(URL[] urls) {
+ StringBuilder ret = new StringBuilder();
+ for (URL url : urls) {
+ ret.append(url.toString() + ";");
+ }
+ return ret.toString();
+ }
+
+ private URL[] allUrlsExcept(Set<String> classpath, Artifact except, File instead) {
+ Set<String> allExcept = allExcept(classpath, except, instead);
+ URL[] ret = new URL[allExcept.size()];
+ int i = 0;
+ for (String ele : allExcept) {
+ try {
+ ret[i++] = new URL("file:" + ele);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+ return ret;
}
+ private Set<String> allExcept(Set<String> classpath, Artifact except, File instead) {
+ Set<String> ret = new HashSet<String>();
+ ret.addAll(classpath);
+ if (except != null) {
+ ret.remove(except.getFile().getAbsolutePath());
+ }
+ if (instead != null) {
+ String path = instead.getAbsolutePath();
+ if (instead.isDirectory()) {
+ if (!path.endsWith(File.separator)) path += File.separator;
+ } else {
+ if (path.endsWith(File.separator)) path = path.substring(0, path.length() - 1);
+ }
+ ret.add(path);
+ }
+ return ret;
+ }
+
+ private void jpaEnhance(Set<String> set, Artifact art, File baseout) {
+ StringBuilder clazzes = new StringBuilder();
+ // set class loader
+ URL[] mycp = allUrlsExcept(set, art, baseout);
+ final ClassLoader cl = new URLClassLoader(mycp);
+
+ recurseClasses(baseout, baseout, clazzes, cl);
+ if (clazzes.toString().trim().length() == 0) return;
+
+ getLog().info("Running OpenJPA enhancement");
+
+ OpenJPAConfigurationImpl conf = new OpenJPAConfigurationImpl();
+
+ Options opts = new Options();
+ opts.setProperty("openjpa.MetaDataFactory", "jpa(URLs=" + urlsAsStrings(mycp) + ")");
+ conf.fromProperties(opts);
+ // don't allow connections
+ conf.setConnectionUserName(null);
+ conf.setConnectionPassword(null);
+ conf.setConnectionURL(null);
+ conf.setConnectionDriverName(null);
+ conf.setConnectionFactoryName(null);
+
+ conf.setClassResolver(new ClassResolver() {
+ public ClassLoader getClassLoader(Class context, ClassLoader env) {
+ return cl;
+ }
+ });
+ conf.setReadOnly(Configuration.INIT_STATE_FREEZING);
+ conf.instantiateAll(); // avoid threading issues
+
+ PCEnhancer.Flags flags = new PCEnhancer.Flags();
+ try {
+ PCEnhancer.run(conf, clazzes.toString().trim().split(" "), flags, null, null, null);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void recurseClasses(File root, File baseout, StringBuilder build, ClassLoader cl) {
+ if (baseout.isDirectory()) {
+ File[] listFiles = baseout.listFiles();
+ for (File file : listFiles) {
+ recurseClasses(root, file, build, cl);
+ }
+ } else {
+ if (baseout.getName().endsWith(".class")) {
+ String clname = baseout.getAbsolutePath().substring(root.getAbsolutePath().length());
+ if (clname.startsWith(File.separator)) clname = clname.substring(1);
+ clname = clname.substring(0, clname.length() - 6);
+ clname = clname.replace(File.separatorChar, '.');
+ try {
+ Class<?> class1 = cl.loadClass(clname);
+ boolean toenhance = false;
+ Annotation[] annotations = class1.getAnnotations();
+ for (Annotation annotation : annotations) {
+ if (annotation.annotationType().getName().startsWith("javax.persistence")) {
+ toenhance = true;
+ break;
+ }
+ }
+
+ if (toenhance) {
+ build.append(' ');
+ build.append(baseout.getAbsolutePath());
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public void contextualize(Context context) throws ContextException {
+ PlexusContainer cont = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
+ this.container = cont;
+ }
+
}
Added: labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MavenMessageHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MavenMessageHandler.java?rev=730725&view=auto
==============================================================================
--- labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MavenMessageHandler.java (added)
+++ labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MavenMessageHandler.java Fri Jan 2 06:10:23 2009
@@ -0,0 +1,94 @@
+package org.apache.magma.tools.maven;
+
+/**
+ * The MIT License
+ *
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import org.apache.maven.plugin.logging.Log;
+import org.aspectj.bridge.AbortException;
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.MessageHandler;
+
+/**
+ * A Ajc message handler. gets all compiler messages from the
+ * ajc compiler, and uses maven plugin logger to print them.
+ *
+ *
+ * @author <a href="mailto:kaare.nilsen@gmail.com">Kaare Nilsen</a>
+ */
+public class MavenMessageHandler
+ extends MessageHandler
+{
+ Log log;
+
+ /**
+ * Constructs a MessageHandler with a Maven plugin logger.
+ * @param log
+ */
+ public MavenMessageHandler( Log log )
+ {
+ super();
+ this.log = log;
+ }
+
+ /**
+ * Hook into the maven logger.
+ */
+ public boolean handleMessage( IMessage message )
+ throws AbortException
+ {
+ if ( message.getKind().equals( IMessage.WARNING ) && !isIgnoring( IMessage.WARNING ) )
+ {
+ log.warn( (CharSequence) message.getMessage() );
+ }
+ else if ( message.getKind().equals( IMessage.DEBUG ) && !isIgnoring( IMessage.DEBUG ) )
+ {
+ log.debug( (CharSequence) message.getMessage() );
+ }
+ else if ( message.getKind().equals( IMessage.ERROR ) && !isIgnoring( IMessage.ERROR ) )
+ {
+ log.error( (CharSequence) message.getMessage() );
+ }
+ else if ( message.getKind().equals( IMessage.ABORT ) && !isIgnoring( IMessage.ABORT ) )
+ {
+ log.error( (CharSequence) message.getMessage() );
+ }
+ else if ( message.getKind().equals( IMessage.FAIL ) && !isIgnoring( IMessage.FAIL ) )
+ {
+ log.error( (CharSequence) message.getMessage() );
+ }
+ else if ( message.getKind().equals( IMessage.INFO ) && !isIgnoring( IMessage.INFO ))
+ {
+ log.debug( (CharSequence) message.getMessage() );
+ }
+ else if ( message.getKind().equals( IMessage.WEAVEINFO ) && !isIgnoring( IMessage.WEAVEINFO ) )
+ {
+ log.debug( (CharSequence) message.getMessage() );
+ }
+ else if ( message.getKind().equals( IMessage.TASKTAG ) && !isIgnoring( IMessage.TASKTAG ) )
+ {
+ log.debug( (CharSequence) message.getMessage() );
+ }
+ return super.handleMessage( message );
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org