[jboss-cvs] JBossAS SVN: r69933 - projects/aop/trunk/maven-jbossaop-plugin/src/main/java/org/jboss/maven/plugins.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 19 10:47:07 EST 2008


Author: stalep
Date: 2008-02-19 10:47:06 -0500 (Tue, 19 Feb 2008)
New Revision: 69933

Added:
   projects/aop/trunk/maven-jbossaop-plugin/src/main/java/org/jboss/maven/plugins/JBossAOPMojo.java
Modified:
   projects/aop/trunk/maven-jbossaop-plugin/src/main/java/org/jboss/maven/plugins/JBossAOPCMojo.java
Log:
[JBAOP-520] Added support for running aop apps with maven. Added docbook info on the maven plugin.

Modified: projects/aop/trunk/maven-jbossaop-plugin/src/main/java/org/jboss/maven/plugins/JBossAOPCMojo.java
===================================================================
--- projects/aop/trunk/maven-jbossaop-plugin/src/main/java/org/jboss/maven/plugins/JBossAOPCMojo.java	2008-02-19 15:46:40 UTC (rev 69932)
+++ projects/aop/trunk/maven-jbossaop-plugin/src/main/java/org/jboss/maven/plugins/JBossAOPCMojo.java	2008-02-19 15:47:06 UTC (rev 69933)
@@ -26,10 +26,8 @@
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.model.Dependency;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
@@ -69,7 +67,7 @@
    /** 
     * 
     * 
-    * @parameter expression="${supress}" default-value="false"
+    * @parameter expression="${supress}" default-value="true"
     */
    private boolean suppress;
    
@@ -88,13 +86,6 @@
    private boolean report;
 
    /** 
-    * 
-    * 
-    * @parameter expression="${failOnError}" default-value="true"
-    */
-   private boolean failOnError;
-
-   /** 
     * If it is set to true all project dependencies will also be included to the aop classpath
     * 
     * @parameter expression="${includeProjectDependency}" default-value="false"
@@ -104,7 +95,7 @@
    
    /** 
     * 
-    * @parameter expression="${classPath}" default-value="${project.build.outputDirectory}"
+    * @parameter expression="${classPath}" default-value=""
     */
    private String classPath;
 
@@ -119,28 +110,11 @@
     * @parameter expression="${aopClassPath}" default-value=""
     */
    private String aopClassPath;
-
-   /** 
-    * 
-    * @parameter expression="${compilerClassPath}" default-value=""
-    */
-   private String compilerClassPath;
-
-   /**
-    * @parameter default-value="${project.compileDependencies}"
-    * @required
-    * @readonly
-    */
-   private List<Dependency> cDependencies;
-
-   /**
-    * @parameter default-value="${project.dependency}"
-    * @required
-    * @readonly
-    */
-   private Dependency pDependency;
    
    /**
+    * Set this to specify certain classes that will be weaved. This prevents the parser to check
+    * all the classes in eg target/classes.
+    * 
     * @parameter
     */
    private String[] includes;
@@ -149,6 +123,7 @@
 
    /**
     * @parameter expression="${project}"
+    * @readonly
     */
    private MavenProject project;
    
@@ -168,6 +143,10 @@
 
    private String createClassPathList()
    {
+      //if classPath is set, use only that
+      if(getClassPath() != null && getClassPath().length() > 0)
+         return getClassPath();
+      
       StringBuffer sb = new StringBuffer();
       for(Artifact a : pluginArtifacts)
       {
@@ -178,16 +157,17 @@
       {
          for(Object o : project.getDependencyArtifacts())
          {
+            if(((Artifact) o).getFile() != null)
             sb.append(((Artifact) o).getFile().toString()).append(File.pathSeparator);
          }
       }
 
       if(isTest())
-         sb.append(project.getBuild().getTestOutputDirectory());
-      else
+         sb.append(project.getBuild().getTestOutputDirectory()).append(File.pathSeparator);
+      
          sb.append(project.getBuild().getOutputDirectory());
 
-      System.err.println("CLASSPATH: "+sb.toString());
+//      System.err.println("CLASSPATH: "+sb.toString());
       return sb.toString();
    }
 
@@ -302,11 +282,6 @@
       return classPath;
    }
 
-   private String getCompilerClassPath()
-   {
-      return compilerClassPath;
-   }
-
    private boolean isVerbose()
    {
       return verbose;

Added: projects/aop/trunk/maven-jbossaop-plugin/src/main/java/org/jboss/maven/plugins/JBossAOPMojo.java
===================================================================
--- projects/aop/trunk/maven-jbossaop-plugin/src/main/java/org/jboss/maven/plugins/JBossAOPMojo.java	                        (rev 0)
+++ projects/aop/trunk/maven-jbossaop-plugin/src/main/java/org/jboss/maven/plugins/JBossAOPMojo.java	2008-02-19 15:47:06 UTC (rev 69933)
@@ -0,0 +1,228 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.maven.plugins;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * A Simple mojo that uses JBoss AOP to run a class with aop weaving enabled.
+ * Supports compiletime and loadtime.
+ * 
+ * @author <a href="stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ * @requiresDependencyResolution package
+ * @goal run
+ * @phase package
+ */
+public class JBossAOPMojo  extends AbstractMojo
+{
+
+   /** 
+    * If it is set to true all project dependencies will also be included to the aop classpath
+    * 
+    * @parameter expression="${includeProjectDependency}" default-value="false"
+    */
+   private boolean includeProjectDependency;
+   
+   /** 
+    * 
+    * @parameter expression="${classPath}" default-value=""
+    */
+   private String classPath;
+   
+   /** 
+    * 
+    * @parameter expression="${aopPaths}" default-value={src/main/resources/jboss-aop.xml}
+    */
+   private String[] aoppaths;
+   
+   /** 
+    * 
+    * @parameter expression="${executable}" default-value=null
+    * @required
+    */
+   private String executable;
+   
+   /** 
+    * 
+    * @parameter expression="${loadtime}" default-value="false"
+    */
+   private boolean loadtime;
+   
+   /**
+    * The plugin dependencies.
+    *
+    * @parameter expression="${plugin.artifacts}"
+    * @required
+    * @readonly
+    */
+   private List<Artifact> pluginArtifacts; 
+   
+   /**
+    * @parameter expression="${project}"
+    * @required
+    * @readonly
+    */
+   private MavenProject project;
+   
+   public void execute() throws MojoExecutionException, MojoFailureException
+   {
+      executeOutOfProcess(createCommandLine());
+      
+   }
+   
+   private void executeOutOfProcess(Commandline cl)
+   {
+
+      CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
+      CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();     
+      try
+      {
+         CommandLineUtils.executeCommandLine( cl, out, err );
+
+         processStream(new BufferedReader( new StringReader( err.getOutput()) ), true);
+         processStream(new BufferedReader( new StringReader( out.getOutput()) ), false);
+      }
+      catch (CommandLineException e)
+      {
+         e.printStackTrace();
+      }
+   }
+   
+   @SuppressWarnings("unchecked")
+   private Commandline createCommandLine()
+   {
+      Commandline cl = new Commandline();
+      cl.setExecutable("java");
+      cl.setWorkingDirectory(project.getBuild().getOutputDirectory());
+      
+      if(loadtime)
+      {
+         String javaagent = getJavaagentPath();
+         if(javaagent != null)
+         cl.addArguments(new String[] { "-javaagent:"+javaagent});
+      }
+      cl.addArguments(new String[] { "-cp", createClassPathList()});
+      cl.addArguments(new String[] { "-Djboss.aop.path="+ getAoppath()});
+      
+      cl.addArguments(new String[] { executable});
+      
+      if(getLog().isDebugEnabled()) 
+      { 
+         getLog().debug("Executing aop: "+cl.toString()); 
+      }
+      return cl;
+   }
+   
+   private String getJavaagentPath()
+   {
+      for(Artifact a : pluginArtifacts)
+      {
+         if(a.getArtifactId().equals("jboss-aop"))
+         {
+            return a.getFile().toString();
+         }
+      }
+      return null;
+   }
+   
+   private String createClassPathList()
+   {
+    //if classPath is set, use only that
+      if(classPath != null && classPath.length() > 0)
+         return classPath;
+      
+      StringBuffer sb = new StringBuffer();
+      for(Artifact a : pluginArtifacts)
+      {
+         if(a.getGroupId().startsWith("org.jboss") 
+               || a.getGroupId().startsWith("jboss") 
+               || a.getGroupId().startsWith("trove"))
+         sb.append(a.getFile().toString()).append(File.pathSeparator);
+      }
+
+      if(includeProjectDependency)
+      {
+         for(Object o : project.getDependencyArtifacts())
+         {
+            if(((Artifact) o).getFile() != null)
+            sb.append(((Artifact) o).getFile().toString()).append(File.pathSeparator);
+         }
+      }
+
+      sb.append(project.getBuild().getOutputDirectory());
+
+      return sb.toString();
+   }
+
+   
+   private String getAoppath()
+   { 
+      if(aoppaths.length > 0)
+      {
+         StringBuffer sb = new StringBuffer();
+         for(String aoppath : aoppaths)
+         {
+            if(sb.length() > 0)
+               sb.append(File.pathSeparator);
+            sb.append(new File(project.getBasedir(), aoppath).getAbsolutePath());
+//            sb.append(aoppath);
+         }
+         return sb.toString();
+      }
+      else
+         return new File(project.getBasedir(),"src/main/resources/jboss-aop.xml").getAbsolutePath();
+   }
+
+   private void processStream(BufferedReader input, boolean isError)
+   {
+      String err = null;
+      try
+      {
+         while( (err = input.readLine()) != null)
+         {
+            if(isError)
+               getLog().error(err);
+            else
+               getLog().info(err);
+         }
+      }
+      catch (IOException e)
+      {
+         e.printStackTrace();
+      }
+   }
+
+}




More information about the jboss-cvs-commits mailing list