You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vm...@apache.org on 2006/04/01 16:35:14 UTC

svn commit: r390676 - in /maven/plugins/trunk/maven-clover-plugin/src: it/maven-clover-plugin-sample-simple/ main/java/org/apache/maven/plugin/clover/

Author: vmassol
Date: Sat Apr  1 06:35:13 2006
New Revision: 390676

URL: http://svn.apache.org/viewcvs?rev=390676&view=rev
Log:
- Cleaned up by factorizing common configuration elements and ensure AbstractCloverMojo.execute() is always called by the different mojos as it registers the license.
- Ensure the clover db directory is always created

Modified:
    maven/plugins/trunk/maven-clover-plugin/src/it/maven-clover-plugin-sample-simple/pom.xml
    maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/AbstractCloverMojo.java
    maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverAggregateMojo.java
    maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverCheckMojo.java
    maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java
    maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java
    maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverLogMojo.java

Modified: maven/plugins/trunk/maven-clover-plugin/src/it/maven-clover-plugin-sample-simple/pom.xml
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clover-plugin/src/it/maven-clover-plugin-sample-simple/pom.xml?rev=390676&r1=390675&r2=390676&view=diff
==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/it/maven-clover-plugin-sample-simple/pom.xml (original)
+++ maven/plugins/trunk/maven-clover-plugin/src/it/maven-clover-plugin-sample-simple/pom.xml Sat Apr  1 06:35:13 2006
@@ -19,6 +19,14 @@
     <plugins>
       <plugin>
         <artifactId>maven-clover-plugin</artifactId>
+        <configuration>
+
+          <!-- Verify that we can modify the location of the Clover database and that the directory is created if
+               it doesn't exist. Note: we're putting the configuration here and not in the build section because the
+               build section inherits from the reporting section but not the other way around... -->
+          <cloverDatabase>${project.build.directory}/customclover/myclover.db</cloverDatabase>
+
+        </configuration>
       </plugin>
     </plugins>
   </reporting>
@@ -34,11 +42,17 @@
       <plugin>
         <artifactId>maven-clover-plugin</artifactId>
         <configuration>
-          <jdk>1.4</jdk>
+
           <targetPercentage>1%</targetPercentage>
+
+          <!-- Verify that we can specify the JDK version for Clover's instrumentation -->
+          <jdk>1.4</jdk>
+
+          <!-- Verify that we can exclude some files from the instrumentation -->
           <excludes>
             <exclude>**/*Dummy*.java</exclude>
           </excludes>
+
         </configuration>
         <executions>
           <execution>

Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/AbstractCloverMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/AbstractCloverMojo.java?rev=390676&r1=390675&r2=390676&view=diff
==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/AbstractCloverMojo.java (original)
+++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/AbstractCloverMojo.java Sat Apr  1 06:35:13 2006
@@ -29,6 +29,12 @@
 public abstract class AbstractCloverMojo extends AbstractMojo
 {
     /**
+     * @parameter expression="${project.build.directory}/clover/clover.db"
+     * @required
+     */
+    private String cloverDatabase;
+
+    /**
      * A Clover license file to be used by the plugin. If not specified, the Clover plugin uses a default evaluation
      * license.
      *
@@ -51,7 +57,7 @@
      *  
      * @parameter default-value="threaded"
      */
-    protected String flushPolicy;
+    private String flushPolicy;
 
     /**
      * When the Clover Flush Policy is set to "interval" or threaded this value is the minimum period between flush
@@ -59,7 +65,7 @@
      *
      * @parameter default-value="500"
      */
-    protected int flushInterval;
+    private int flushInterval;
 
     /**
      * If true we'll wait 2*flushInterval to ensure coverage data is flushed to the Clover database before running
@@ -72,7 +78,7 @@
      * 
      * @parameter default-value="true"
      */
-    protected boolean waitForFlush;
+    private boolean waitForFlush;
 
     /**
      * Whether the Clover instrumentation should use the Clover <code>jdk14</code> or <code>jdk15</code> flags to
@@ -80,13 +86,13 @@
      *
      * @parameter
      */
-    protected String jdk;
+    private String jdk;
 
     /**
      * @parameter expression="${project}"
      * @required
      */
-    protected MavenProject project;
+    private MavenProject project;
 
     /**
      * Resource locator.
@@ -198,4 +204,34 @@
     {
         this.licenseLocation = licenseLocation;
     }  
+
+    protected MavenProject getProject()
+    {
+        return this.project;
+    }
+
+    protected boolean getWaitForFlush()
+    {
+        return this.waitForFlush;
+    }
+
+    protected String getJdk()
+    {
+        return this.jdk;
+    }
+
+    protected String getCloverDatabase()
+    {
+        return this.cloverDatabase;
+    }
+
+    protected int getFlushInterval()
+    {
+        return this.flushInterval;
+    }
+
+    protected String getFlushPolicy()
+    {
+        return this.flushPolicy;
+    }
 }

Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverAggregateMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverAggregateMojo.java?rev=390676&r1=390675&r2=390676&view=diff
==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverAggregateMojo.java (original)
+++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverAggregateMojo.java Sat Apr  1 06:35:13 2006
@@ -1,18 +1,11 @@
 package org.apache.maven.plugin.clover;
 
-import org.apache.maven.reporting.AbstractMavenReport;
-import org.apache.maven.reporting.MavenReportException;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.doxia.site.renderer.SiteRenderer;
-import org.codehaus.doxia.sink.Sink;
 
 import java.io.File;
 import java.util.*;
 
-import com.cenqua.clover.reporters.html.HtmlReporter;
 import com.cenqua.clover.CloverMerge;
 
 /**
@@ -25,17 +18,9 @@
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
  * @version $Id$
  */
-public class CloverAggregateMojo extends AbstractMojo
+public class CloverAggregateMojo extends AbstractCloverMojo
 {
     /**
-     * The location of the <a href="http://cenqua.com/clover/doc/adv/database.html">Clover database</a>.
-     *
-     * @parameter expression="${project.build.directory}/clover/clover.db"
-     * @required
-     */
-    private String cloverDatabase;
-
-    /**
      * The location of the merged clover database to create when running a report in a multimodule build.
      *
      * @parameter expression="${project.build.directory}/clover/cloverMerge.db"
@@ -44,45 +29,6 @@
     private String cloverMergeDatabase;
 
     /**
-     * The directory where the Clover report will be generated.
-     *
-     * @parameter expression="${project.reporting.outputDirectory}/clover"
-     * @required
-     */
-    private File outputDirectory;
-
-    /**
-     * When the Clover Flush Policy is set to "interval" or threaded this value is the minimum
-     * period between flush operations (in milliseconds).
-     *
-     * @parameter default-value="500"
-     */
-    protected int flushInterval;
-
-    /**
-     * If true we'll wait 2*flushInterval to ensure coverage data is flushed to the Clover
-     * database before running any query on it.
-     *
-     * Note: The only use case where you would want to turn this off is if you're running your
-     * tests in a separate JVM. In that case the coverage data will be flushed by default upon
-     * the JVM shutdown and there would be no need to wait for the data to be flushed. As we
-     * can't control whether users want to fork their tests or not, we're offering this parameter
-     * to them.
-     *
-     * @parameter default-value="true"
-     */
-    protected boolean waitForFlush;
-
-    /**
-     * The Maven project.
-     *
-     * @parameter expression="${project}"
-     * @required
-     * @readonly
-     */
-    private MavenProject project;
-
-    /**
      * The projects in the reactor for aggregation report.
      *
      * @parameter expression="${reactorProjects}"
@@ -98,10 +44,12 @@
         throws MojoExecutionException
     {
         // If we're in a module with children modules, then aggregate the children clover databases.
-        if ( this.project.getModules().size() > 0 )
+        if ( getProject().getModules().size() > 0 )
         {
+            super.execute();
+
             // Ensure all databases are flushed
-            AbstractCloverMojo.waitForFlush( this.waitForFlush, this.flushInterval );
+            AbstractCloverMojo.waitForFlush( getWaitForFlush(), getFlushInterval() );
 
             if ( getChildrenCloverDatabases().size() > 0 )
             {
@@ -127,7 +75,7 @@
         // Find out the location of the clover DB relative to the root module.
         // Note: This is a pretty buggy algorithm and we really need a proper solution (see MNG-2180)
         String relativeCloverDatabasePath =
-            this.cloverDatabase.substring(this.project.getBasedir().getPath().length());
+            getCloverDatabase().substring( getProject().getBasedir().getPath().length() );
 
         List dbFiles = new ArrayList();
         for ( Iterator projects = this.reactorProjects.iterator(); projects.hasNext(); )

Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverCheckMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverCheckMojo.java?rev=390676&r1=390675&r2=390676&view=diff
==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverCheckMojo.java (original)
+++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverCheckMojo.java Sat Apr  1 06:35:13 2006
@@ -34,12 +34,6 @@
 public class CloverCheckMojo extends AbstractCloverMojo
 {
     /**
-     * @parameter expression="${project.build.directory}/clover/clover.db"
-     * @required
-     */
-    private String cloverDatabase;
-
-    /**
      * @parameter default-value="70%"
      * @required
      */
@@ -52,14 +46,16 @@
     public void execute()
         throws MojoExecutionException
     {
-        AbstractCloverMojo.waitForFlush( this.waitForFlush, this.flushInterval );
+        super.execute();
+
+        AbstractCloverMojo.waitForFlush( getWaitForFlush(), getFlushInterval() );
 
         Project antProject = registerCloverAntTasks();
 
         getLog().info( "Checking for coverage of " + targetPercentage);
 
         CloverPassTask cloverPassTask = (CloverPassTask) antProject.createTask( "clover-check" );
-        cloverPassTask.setInitString( this.cloverDatabase );
+        cloverPassTask.setInitString( getCloverDatabase() );
         cloverPassTask.setHaltOnFailure( true );
         cloverPassTask.setTarget( new Percentage( this.targetPercentage ) );
         cloverPassTask.setFailureProperty( "clovercheckproperty" );

Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java?rev=390676&r1=390675&r2=390676&view=diff
==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java (original)
+++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java Sat Apr  1 06:35:13 2006
@@ -49,14 +49,6 @@
     private String cloverOutputDirectory;
 
     /**
-     * The location of the <a href="http://cenqua.com/clover/doc/adv/database.html">Clover database</a>.
-     * 
-     * @parameter
-     * @required
-     */
-    private String cloverDatabase;
-
-    /**
      * @parameter expression="${plugin.artifacts}"
      * @required
      */
@@ -92,9 +84,12 @@
     {
         if ( shouldExecute() )
         {
+            // Ensure output directories exist
             new File( this.cloverOutputDirectory ).mkdirs();
             this.cloverOutputSourceDirectory = new File( this.cloverOutputDirectory, "src" ).getPath();
 
+            new File( getCloverDatabase() ).getParentFile().mkdirs();
+
             super.execute();
 
             Set filesToInstrument = computeFilesToInstrument();
@@ -117,8 +112,8 @@
         boolean shouldExecute = true;
 
         // Only execute reports for java projects
-        ArtifactHandler artifactHandler = this.project.getArtifact().getArtifactHandler();
-        File srcDir = new File(this.project.getBuild().getSourceDirectory());
+        ArtifactHandler artifactHandler = getProject().getArtifact().getArtifactHandler();
+        File srcDir = new File( getProject().getBuild().getSourceDirectory() );
 
         if ( !"java".equals( artifactHandler.getLanguage() ) )
         {
@@ -147,34 +142,34 @@
     {
         // Explicitely set the output directory to be the Clover one so that all other plugins executing
         // thereafter output files in the Clover output directory and not in the main output directory.
-        this.project.getBuild().setDirectory( this.cloverOutputDirectory );
+        getProject().getBuild().setDirectory( this.cloverOutputDirectory );
 
         // TODO: Ulgy hack below. Changing the directory should be enough for changing the values of all other
         // properties depending on it!
-        this.project.getBuild().setOutputDirectory( new File( this.cloverOutputDirectory, "classes" ).getPath() );
-        this.project.getBuild().setTestOutputDirectory(
+        getProject().getBuild().setOutputDirectory( new File( this.cloverOutputDirectory, "classes" ).getPath() );
+        getProject().getBuild().setTestOutputDirectory(
             new File( this.cloverOutputDirectory, "test-classes" ).getPath() );
     }
 
     private void redirectSourceDirectories()
     {
-        String oldSourceDirectory = this.project.getBuild().getSourceDirectory();
+        String oldSourceDirectory = getProject().getBuild().getSourceDirectory();
 
-        this.project.getBuild().setSourceDirectory( this.cloverOutputSourceDirectory );
+        getProject().getBuild().setSourceDirectory( this.cloverOutputSourceDirectory );
 
         // Maven2 limitation: changing the source directory doesn't change the compile source roots
         // See http://jira.codehaus.org/browse/MNG-1945
-        List sourceRoots = this.project.getCompileSourceRoots();
+        List sourceRoots = getProject().getCompileSourceRoots();
         for (int i = 0; i < sourceRoots.size(); i++)
         {
-            String sourceRoot = (String) this.project.getCompileSourceRoots().get( i );
+            String sourceRoot = (String) getProject().getCompileSourceRoots().get( i );
             if (sourceRoot.equals(oldSourceDirectory))
             {
-                this.project.getCompileSourceRoots().remove( i );
+                getProject().getCompileSourceRoots().remove( i );
 
                 // Note: Ideally we should add the new compile source root at the same place as the
                 // one we're removing but there's no API for this...
-                this.project.addCompileSourceRoot( this.project.getBuild().getSourceDirectory() );
+                getProject().addCompileSourceRoot( getProject().getBuild().getSourceDirectory() );
             }
         }
     }
@@ -203,9 +198,9 @@
                                                  cloverArtifact.getType() );
 
         // TODO: use addArtifacts when it's implemented, see http://jira.codehaus.org/browse/MNG-2197
-        Set set = new HashSet( this.project.getArtifacts() );
+        Set set = new HashSet( getProject().getArtifacts() );
         set.add( cloverArtifact );
-        this.project.setDependencyArtifacts( set );
+        getProject().setDependencyArtifacts( set );
     }
 
     /**
@@ -234,7 +229,7 @@
         // Note: we shouldn't have to do this but this is a limitation of the Plexus SimpleSourceInclusionScanner
         scanner.addSourceMapping(new SuffixMapping("dummy", "dummy"));
 
-        Iterator roots = this.project.getCompileSourceRoots().iterator();
+        Iterator roots = getProject().getCompileSourceRoots().iterator();
         while (roots.hasNext())
         {
             String sourceRoot = (String) roots.next();
@@ -260,29 +255,29 @@
         List parameters = new ArrayList();
 
         parameters.add( "-p" );
-        parameters.add( this.flushPolicy );
+        parameters.add( getFlushPolicy() );
         parameters.add( "-f" );
-        parameters.add( "" + this.flushInterval );
+        parameters.add( "" + getFlushInterval() );
 
         parameters.add( "-i" );
-        parameters.add( this.cloverDatabase );
+        parameters.add( getCloverDatabase() );
 
         parameters.add( "-d" );
         parameters.add( this.cloverOutputSourceDirectory );
 
-        if ( this.jdk != null )
+        if ( getJdk() != null )
         {
-            if ( this.jdk.equals( "1.4" ) )
+            if ( getJdk().equals( "1.4" ) )
             {
                 parameters.add( "-jdk14" );
             }
-            else if ( this.jdk.equals( "1.5" ) )
+            else if ( getJdk().equals( "1.5" ) )
             {
                 parameters.add( "-jdk15" );
             }
             else
             {
-                throw new MojoExecutionException("Unsupported jdk version [" + this.jdk
+                throw new MojoExecutionException("Unsupported jdk version [" + getJdk()
                     + "]. Valid values are [1.4] and [1.5]");
             }
         }

Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java?rev=390676&r1=390675&r2=390676&view=diff
==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java (original)
+++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java Sat Apr  1 06:35:13 2006
@@ -41,5 +41,6 @@
     public void execute()
         throws MojoExecutionException
     {
+        super.execute();
     }
 }

Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverLogMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverLogMojo.java?rev=390676&r1=390675&r2=390676&view=diff
==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverLogMojo.java (original)
+++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverLogMojo.java Sat Apr  1 06:35:13 2006
@@ -1,7 +1,5 @@
-package org.apache.maven.plugin.clover;
-
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.maven.plugin.clover;
 
 import com.cenqua.clover.tasks.CloverLogTask;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -23,27 +22,24 @@
 /**
  * Provides information on the current Clover database.
  *
+ * @goal log
+ *
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
  * @version $Id$
- * @goal log
  *
  */
 public class CloverLogMojo
     extends AbstractCloverMojo
 {
-    /**
-     * @parameter expression="${project.build.directory}/clover/clover.db"
-     * @required
-     */
-    protected String cloverDatabase;
-
     public void execute()
         throws MojoExecutionException
     {
+        super.execute();
+
         Project antProject = registerCloverAntTasks();
 
         CloverLogTask cloverLogTask = (CloverLogTask) antProject.createTask( "clover-log" );
-        cloverLogTask.setInitString( this.cloverDatabase );
+        cloverLogTask.setInitString( getCloverDatabase() );
         cloverLogTask.setOutputProperty( "cloverlogproperty" );
         cloverLogTask.execute();