[jboss-svn-commits] JBL Code SVN: r13811 - in labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin: src/main/java/org/jboss/maven/plugins/retro and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jul 27 12:48:19 EDT 2007


Author: pgier
Date: 2007-07-27 12:48:19 -0400 (Fri, 27 Jul 2007)
New Revision: 13811

Modified:
   labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/pom.xml
   labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/RetroCheckMojo.java
Log:
Working version of retro check mojo.
Issue: JBBUILD-343

Modified: labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/pom.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/pom.xml	2007-07-27 15:45:20 UTC (rev 13810)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/pom.xml	2007-07-27 16:48:19 UTC (rev 13811)
@@ -80,6 +80,11 @@
       <artifactId>commons-io</artifactId>
       <version>1.2</version>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+      <version>1.4.4</version>
+    </dependency>
   </dependencies>
   <distributionManagement>
     <repository>

Modified: labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/RetroCheckMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/RetroCheckMojo.java	2007-07-27 15:45:20 UTC (rev 13810)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/RetroCheckMojo.java	2007-07-27 16:48:19 UTC (rev 13811)
@@ -3,12 +3,23 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+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.model.Plugin;
 import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
-import org.jboss.ant.tasks.retrocheck.Checker;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
 
 /**
  * Maven plugin for running the retro check test.  
@@ -41,6 +52,41 @@
    protected org.apache.maven.project.MavenProjectHelper projectHelper;
 
    /**
+    * INTERNAL : Artifact factory, needed to download dependencies
+    *
+    * @component role="org.apache.maven.artifact.factory.ArtifactFactory"
+    * @required
+    * @readonly
+    */
+   protected ArtifactFactory artifactFactory;
+
+   /**
+    * INTERNAL : Artifact resolver, needed to download dependencies
+    *
+    * @component role="org.apache.maven.artifact.resolver.ArtifactResolver"
+    * @required
+    * @readonly
+    */
+   protected ArtifactResolver artifactResolver;
+   
+   /**
+    * INTERNAL : Local maven repository.
+    *
+    * @parameter expression="${localRepository}"
+    * @required
+    * @readonly
+    */
+   protected ArtifactRepository localRepository;
+   
+   /**
+    * Option to specify the jvm (or path to the java executable) to use with the forking options. For the default, the
+    * jvm will be the same as the one used to run Maven.
+    * 
+    * @parameter expression="${jvm}"
+    */
+   private String jvm;
+
+   /**
     * The Maven Plugin Object
     *
     * @parameter expression="${plugin.components}"
@@ -50,7 +96,7 @@
    protected List pluginComponents;
 
    /**
-    * The plugin dependencies.
+    * The plugin artifacts.
     *
     * @parameter expression="${plugin.artifacts}"
     * @required
@@ -59,6 +105,15 @@
    private List pluginArtifacts;
 
    /**
+    * The plugin dependencies.
+    *
+    * @parameter expression="${plugin.dependencies}"
+    * @required
+    * @readonly
+    */
+   private List pluginDependencies;
+
+   /**
     * Project classpath.
     *
     * @parameter expression="${project.compileClasspathElements}"
@@ -67,20 +122,24 @@
     */
    private List classpathElements;
 
+   
    /**
-    * @parameter expression="${project.pluginArtifacts}"
+    * The directory for compiled classes.
+    *
+    * @parameter expression="${project.build.outputDirectory}"
     * @required
     * @readonly
     */
-   //private HashSet pluginArtifacts;
+   private File targetClassesDirectory;
+
    /**
     * The directory for compiled classes.
     *
-    * @parameter expression="${project.build.outputDirectory}"
+    * 
     * @required
     * @readonly
     */
-   private File targetClassesDirectory;
+   private Plugin thePlugin;
 
    /**
     * The directory for compiled classes.
@@ -92,17 +151,47 @@
    private File targetDirectory;
 
    /**
+    * The path to the classes to be checked, relative to
+    * the build directory.  Defaults to a value of
+    * "classes-weaved" which means that classes in the direcotry
+    * target/classes-weaved will be checked.
     * @parameter
+    * @required
     */
+   private String checkDirectory;
+   
+   /**
+    * @parameter
+    */
    private boolean verbose = false;
 
    /**
     * @parameter
     */
-   private boolean suppress = true;
+   private boolean suppress = false;
 
-   public void execute()
+   /**
+    * Location of the retro check jar to include in the classpath
+    */
+   private File jbossRetroCheckJar = null;
+   
+   /**
+    * Location of the retro runtime jar to include in the classpath
+    */
+   private File jbossRetroRtJar = null;
+   
+   public void execute() throws MojoExecutionException
    {
+      // First, make sure checker and runtime available on the classpath
+      resolveCheckerLocation();
+      
+      if ( jvm == null || jvm.equals("") )
+      {
+          // use the same JVM as the one used to run Maven (the "java.home" one)
+          jvm = System.getProperty( "java.home" ) + File.separator + "bin" + File.separator + "java";
+          getLog().debug( "Using JVM: " + jvm );
+      }
+
       this.getLog().info("[retro-check] Checking classes for jdk14");
 
       if (!project.getArtifact().getType().equalsIgnoreCase("jar")) {
@@ -112,41 +201,31 @@
       }
       ArrayList<String> argsList = new ArrayList<String>();
 
-      if (verbose)
-      {
-         argsList.add("-verbose");
-      }
-      if (suppress)
-      {
-         argsList.add("-suppress");
-      }
-      /*argsList.add("-destdir");
-      try
-      {
-         argsList.add(targetDirectory.getCanonicalPath() + "/classes-retro");
-      }
-      catch (Exception e)
-      {
-         this.getLog().error(e);
-      }*/
       argsList.add("-cp");
       StringBuilder classpath = new StringBuilder();
-      String pathSeparator = System.getProperty("path.separator");
-      for (Object element : classpathElements)
-      {
-         classpath.append(element);
-         classpath.append(pathSeparator);
-      }
 
-      for (Object artifact : pluginArtifacts)
+      String fileSep = System.getProperty("file.separator");
+      String weavedClassesDir = project.getBuild().getDirectory() + fileSep + checkDirectory;
+      classpath.append(weavedClassesDir);
+      classpath.append(File.pathSeparator);
+            
+      for (Object artifactObj : pluginArtifacts)
       {
+         Artifact artifact = (Artifact)artifactObj;
+         if (artifact.getArtifactId().equals("jboss-retro") && artifact.getClassifier() == null)
+         {
+            // We don't want to include the jboss-retro dependency for the checks
+            // because the jboss-retro jar is jdk1.5 and we should be running under 1.4
+            // and the checker and rt jars will have everything needed for the checks
+            continue;
+         }
          try
          {
-            File artifactFile = ((Artifact) artifact).getFile();
+            File artifactFile = artifact.getFile();
             if (artifactFile != null)
             {
                classpath.append(artifactFile.getCanonicalPath());
-               classpath.append(pathSeparator);
+               classpath.append(File.pathSeparator);
             }
          }
          catch (IOException ioe)
@@ -154,34 +233,136 @@
             this.getLog().warn("Could not get filename");
          }
       }
+      classpath.append(this.jbossRetroCheckJar.getAbsolutePath());
+      classpath.append(File.pathSeparator);
+      classpath.append(this.jbossRetroRtJar.getAbsolutePath());
+      classpath.append(File.pathSeparator);
       
+      getLog().debug("Using checker classpath: " +classpath.toString());
       argsList.add(classpath.toString());
 
-      try
+      argsList.add("org.jboss.ant.tasks.retrocheck.Checker");
+      
+      if (verbose)
       {
-         argsList.add(targetDirectory.getCanonicalPath() + 
-               System.getProperty("file.separator") + "classes-retro");
+         argsList.add("-verbose");
       }
-      catch (IOException ioe)
+      
+      if (suppress)
       {
-         this.getLog().error(ioe.toString());
+         argsList.add("-suppress");
       }
 
+      argsList.add(project.getBuild().getDirectory() + 
+          File.separator + checkDirectory);
+
       String[] args = new String[argsList.size()];
       for (int i = 0; i < args.length; ++i)
       {
          args[i] = argsList.get(i);
       }
 
-      Checker checker = new Checker();
+      Commandline cli = new Commandline();
+   
+      cli.setExecutable( jvm );
+      cli.addArguments(args);
+      
+      StreamConsumer out = new MojoLogStreamConsumer();
+
+      StreamConsumer err = new MojoLogStreamConsumer();
+      
+      int returnCode;
+
       try
       {
-         checker.check(args);
+         returnCode = CommandLineUtils.executeCommandLine( cli, out, err );
+         getLog().info("Checker returned with code: " + returnCode);
       }
-      catch (Exception e)
+      catch ( CommandLineException e )
       {
-         this.getLog().error(e);
+         throw new MojoExecutionException( "Error while executing forked tests.", e );
       }
+   }
 
+   /** 
+    * Resolve the location of the Checker class, and the retro runtime classes  
+    *
+    */
+   public void resolveCheckerLocation() throws MojoExecutionException
+   {
+      // First figure out which verion of retro should be used
+      String jbossRetroVersion = null;
+      Iterator iter = this.pluginArtifacts.iterator();
+      while(iter.hasNext()) {
+         Artifact nextArtifact = (Artifact)iter.next();
+         if (nextArtifact.getArtifactId().equals("jboss-retro") 
+               && nextArtifact.getClassifier() == null)
+         {
+            jbossRetroVersion = nextArtifact.getVersion();          
+         }
+      }
+
+      // Next determine if the checker and runtime are attached to the project 
+      // (meaning that we are checking a build of jboss-retro itself)
+      List attachedArtifacts = project.getAttachedArtifacts();
+      for (Object artifactObj : attachedArtifacts) {
+         Artifact artifact = (Artifact)artifactObj;
+         if (artifact.getArtifactId().equals("jboss-retro") && artifact.getClassifier().equals("retrocheck"))
+         {
+            if (artifact.getClassifier().equals("retrocheck")) 
+            {
+               this.jbossRetroCheckJar = artifact.getFile();
+            }
+            else if(artifact.getClassifier().equals("rt")) 
+            {
+               this.jbossRetroRtJar = artifact.getFile();
+            }
+         }
+      }
+      
+      if (this.jbossRetroCheckJar != null && this.jbossRetroRtJar != null) 
+      {
+         // We found the checker and runtime attached, so just return
+         return;
+      }
+      
+      // Get the checker and runtime from the repository
+      Artifact checkerArtifact = artifactFactory.createArtifactWithClassifier("org.jboss", "jboss-retro", jbossRetroVersion, "jar", "retrocheck");            
+      Artifact runtimeArtifact = artifactFactory.createArtifactWithClassifier("org.jboss", "jboss-retro", jbossRetroVersion, "jar", "rt");            
+      try 
+      {
+         artifactResolver.resolve(checkerArtifact, project.getRemoteArtifactRepositories(), localRepository);
+         artifactResolver.resolve(runtimeArtifact, project.getRemoteArtifactRepositories(), localRepository);
+      }
+      catch (ArtifactResolutionException are) 
+      {
+         throw new MojoExecutionException("Problem resolving artifact: " + are);
+      }
+      catch (ArtifactNotFoundException are) 
+      {
+         throw new MojoExecutionException("Problem resolving artifact: " + are);
+      }
+      
+      this.jbossRetroCheckJar = checkerArtifact.getFile();
+      this.jbossRetroRtJar = runtimeArtifact.getFile();
+
    }
+   
+
+   /**
+    * Consume and log command output from the Checker
+    * @author pgier
+    *
+    */
+   public class MojoLogStreamConsumer implements StreamConsumer
+   {
+      public void consumeLine(String line)
+      {
+         getLog().info(line);
+      }
+   }
+
 }
+
+
+




More information about the jboss-svn-commits mailing list