[prev in list] [next in list] [prev in thread] [next in thread] 

List:       maven-dev
Subject:    svn commit: r390447 - in /maven/plugins/trunk/maven-clover-plugin/src:
From:       vmassol () apache ! org
Date:       2006-03-31 15:45:39
Message-ID: 20060331154540.9335.qmail () minotaur ! apache ! org
[Download RAW message or body]

Author: vmassol
Date: Fri Mar 31 07:45:38 2006
New Revision: 390447

URL: http://svn.apache.org/viewcvs?rev=390447&view=rev
Log:
MCLOVER-19, MCLOVER-25: Refactored clover:clover mojo and separated the clover \
database aggregation into a clover:aggregate mojo.

Added:
    maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverAggregateMojo.java \
(with props) Modified:
    maven/plugins/trunk/maven-clover-plugin/src/it/maven-clover-plugin-sample-multiproject/pom.xml
  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/CloverReportMojo.java


Modified: maven/plugins/trunk/maven-clover-plugin/src/it/maven-clover-plugin-sample-multiproject/pom.xml
                
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clover-plugin/src/it/mave \
n-clover-plugin-sample-multiproject/pom.xml?rev=390447&r1=390446&r2=390447&view=diff \
                ==============================================================================
                
--- maven/plugins/trunk/maven-clover-plugin/src/it/maven-clover-plugin-sample-multiproject/pom.xml \
                (original)
+++ maven/plugins/trunk/maven-clover-plugin/src/it/maven-clover-plugin-sample-multiproject/pom.xml \
Fri Mar 31 07:45:38 2006 @@ -19,10 +19,6 @@
     <plugins>
       <plugin>
         <artifactId>maven-clover-plugin</artifactId>
-<!--        <configuration>
-          <flushPolicy>threaded</flushPolicy>
-          <flushInterval>100</flushInterval>
-        </configuration>-->
       </plugin>
     </plugins>
   </reporting>
@@ -39,6 +35,7 @@
             <phase>pre-site</phase>
             <goals>
               <goal>instrument</goal>
+              <goal>aggregate</goal>
             </goals>
           </execution>
         </executions>

Added: 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=390447&view=auto
 ==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverAggregateMojo.java \
                (added)
+++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverAggregateMojo.java \
Fri Mar 31 07:45:38 2006 @@ -0,0 +1,172 @@
+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;
+
+/**
+ * Aggregate children module Clover databases if there are any. This mojo should not \
exist. It's only there because + * the site plugin doesn't handle @aggregators \
properly at the moment... + *
+ * @goal aggregate
+ * @aggregator
+ *
+ * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
+ * @version $Id$
+ */
+public class CloverAggregateMojo extends AbstractMojo
+{
+    /**
+     * 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"
+     * @required
+     */
+    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}"
+     * @readonly
+     */
+    private List reactorProjects;
+
+    /**
+     * {@inheritDoc}
+     * @see org.apache.maven.plugin.clover.AbstractCloverMojo#execute()
+     */
+    public void execute()
+        throws MojoExecutionException
+    {
+        // If we're in a module with children modules, then aggregate the children \
clover databases. +        if ( this.project.getModules().size() > 0 )
+        {
+            // Ensure all databases are flushed
+            AbstractCloverMojo.waitForFlush( this.waitForFlush, this.flushInterval \
); +
+            if ( getChildrenCloverDatabases().size() > 0 )
+            {
+                // Ensure the merged database output directory exists
+                new File( this.cloverMergeDatabase ).getParentFile().mkdirs();
+
+                // Merge the databases
+                mergeCloverDatabases();
+            }
+            else
+            {
+                getLog().warn("No Clover databases found in children projects - No \
merge done"); +            }
+        }
+    }
+
+    private List getChildrenCloverDatabases()
+    {
+        // Ideally we'd need to find out where each module stores its Clover \
database. However that's not +        // currently possible in m2 (see \
http://jira.codehaus.org/browse/MNG-2180). Thus we'll assume for now +        // that \
all modules use the cloverDatabase configuration from the top level module. +
+        // 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());
 +
+        List dbFiles = new ArrayList();
+        for ( Iterator projects = this.reactorProjects.iterator(); \
projects.hasNext(); ) +        {
+            MavenProject project = (MavenProject) projects.next();
+
+            File cloverDb = new File(project.getBasedir(), \
relativeCloverDatabasePath); +            if (cloverDb.exists())
+            {
+                dbFiles.add(cloverDb.getPath());
+            }
+            else
+            {
+                getLog().debug("Skipping [" + cloverDb.getPath() + "] as it doesn't \
exist."); +            }
+        }
+
+        return dbFiles;
+    }
+
+    private void mergeCloverDatabases() throws MojoExecutionException
+    {
+        List dbFiles = getChildrenCloverDatabases();
+
+        String[] args = new String[dbFiles.size() + 2];
+        args[0] = "-i";
+        args[1] = this.cloverMergeDatabase;
+
+        int i = 2;
+        for ( Iterator dbs = dbFiles.iterator(); dbs.hasNext(); )
+        {
+            args[i] = (String) dbs.next();
+            i++;
+        }
+
+        int mergeResult = CloverMerge.mainImpl( args );
+        if ( mergeResult != 0 )
+        {
+            throw new MojoExecutionException( "Clover has failed to merge the \
children module databases" ); +        }
+    }
+}

Propchange: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverAggregateMojo.java
                
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverAggregateMojo.java
                
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

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/ja \
va/org/apache/maven/plugin/clover/CloverCheckMojo.java?rev=390447&r1=390446&r2=390447&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 \
Fri Mar 31 07:45:38 2006 @@ -45,6 +45,10 @@
      */
     private String targetPercentage;
 
+    /**
+     * {@inheritDoc}
+     * @see org.apache.maven.plugin.clover.AbstractCloverMojo#execute()
+     */
     public void execute()
         throws MojoExecutionException
     {

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/ja \
va/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java?rev=390447&r1=390446&r2=390447&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 \
Fri Mar 31 07:45:38 2006 @@ -83,6 +83,10 @@
 
     private String cloverOutputSourceDirectory;
 
+    /**
+     * {@inheritDoc}
+     * @see org.apache.maven.plugin.clover.AbstractCloverMojo#execute()  
+     */
     public void execute()
         throws MojoExecutionException
     {

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/ja \
va/org/apache/maven/plugin/clover/CloverInstrumentMojo.java?rev=390447&r1=390446&r2=390447&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 \
Fri Mar 31 07:45:38 2006 @@ -34,6 +34,10 @@
  */
 public class CloverInstrumentMojo extends AbstractCloverMojo
 {
+    /**
+     * {@inheritDoc}
+     * @see org.apache.maven.plugin.clover.AbstractCloverMojo#execute()
+     */
     public void execute()
         throws MojoExecutionException
     {

Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverReportMojo.java
                
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-clover-plugin/src/main/ja \
va/org/apache/maven/plugin/clover/CloverReportMojo.java?rev=390447&r1=390446&r2=390447&view=diff
 ==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverReportMojo.java \
                (original)
+++ maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverReportMojo.java \
Fri Mar 31 07:45:38 2006 @@ -33,8 +33,10 @@
  * is an external report generated by Clover itself. If the project generating the \
                report is a top level project and
  * if the <code>aggregate</code> configuration element is set to true then an \
                aggregated report will also be created.
  *
+ * Note: This report mojo should be an @aggregator and the \
<code>clover:aggregate</code> mojo shouldn't exist. This + * is a limitation of the \
site plugin which doesn't support @aggregator reports... + *
  * @goal clover
- * @aggregator
  *
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
  * @version $Id$
@@ -113,75 +115,21 @@
     private List reactorProjects;
 
     /**
-     * Whether to build an aggregated report at the root in addition to building \
                individual reports or not.
-     *
-     * @parameter expression="${aggregate}" default-value="true"
-     */
-    protected boolean aggregate;
-
-    /**
      * @see org.apache.maven.reporting.AbstractMavenReport#executeReport(java.util.Locale)
                
      */
     public void executeReport( Locale locale ) throws MavenReportException
     {
-        // Note: It seems we need to check whether or not we should generate a \
                report here again because even though
-        // the canGenerateReport() method is called automatically when the "mvn \
                site" phase is called, it's not called
-        // when the "mvn clover:clover" goal is called! Probably someone Maven2 \
                should improve, see
-        // http://jira.codehaus.org/browse/MNG-2188
-        if ( canGenerateReport() )
+        File singleModuleCloverDatabase = new File( this.cloverDatabase );
+        if ( singleModuleCloverDatabase.exists() )
         {
-            AbstractCloverMojo.waitForFlush( this.waitForFlush, this.flushInterval \
                );
-
-            // Only generate module level report for Java projects
-            if ( isJavaProject(this.project) )
-            {
-                createCloverHtmlReport();
-            }
-
-            // If we're in a module with children modules, then create an extra \
                report by aggregating the children
-            // clover databases.
-            if ( this.aggregate && ( getProject().getModules().size() > 0 ) )
-            {
-                // Ensure the merged database output directory exists
-                new File( this.cloverMergeDatabase ).getParentFile().mkdirs();
-
-                // Merge the databases
-                mergeCloverDatabases();
-
-                // Generate the merged report
-                createMasterCloverHtmlReport();
-            }
+            createCloverHtmlReport();
         }
-    }
 
-    private List getChildrenCloverDatabases()
-    {
-        // Ideally we'd need to find out where each module stores its Clover \
                database. However that's not
-        // currently possible in m2 (see http://jira.codehaus.org/browse/MNG-2180). \
                Thus we'll assume for now
-        // that all modules use the cloverDatabase configuration from the top level \
                module.
-
-        // 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(getProject().getBasedir().getPath().length());
                
-
-        List dbFiles = new ArrayList();
-        for ( Iterator projects = this.reactorProjects.iterator(); \
projects.hasNext(); ) +        File mergedCloverDatabase = new File ( \
this.cloverMergeDatabase ); +        if ( mergedCloverDatabase.exists() )
         {
-            MavenProject project = (MavenProject) projects.next();
-
-            File cloverDb = new File(project.getBasedir(), \
                relativeCloverDatabasePath);
-            if (cloverDb.exists())
-            {
-                dbFiles.add(cloverDb.getPath());
-            }
-            else
-            {
-                getLog().debug("Skipping [" + cloverDb.getPath() + "] as it doesn't \
                exist.");
-            }
+            createMasterCloverHtmlReport();
         }
-
-        return dbFiles;
     }
 
     /**
@@ -217,28 +165,6 @@
         }
     }
 
-    private void mergeCloverDatabases() throws MavenReportException
-    {
-        List dbFiles = getChildrenCloverDatabases();
-
-        String[] args = new String[dbFiles.size() + 2];
-        args[0] = "-i";
-        args[1] = this.cloverMergeDatabase;
-
-        int i = 2;
-        for ( Iterator dbs = dbFiles.iterator(); dbs.hasNext(); )
-        {
-            args[i] = (String) dbs.next();
-            i++;
-        }
-
-        int mergeResult = CloverMerge.mainImpl( args );
-        if ( mergeResult != 0 )
-        {
-            throw new MavenReportException( "Clover has failed to merge the module \
                databases" );
-        }
-    }
-
     public String getOutputName()
     {
         return "clover/index";
@@ -308,32 +234,29 @@
     }
 
     /**
-     * Generate reports for Java projects and for projects which have a Clover \
database available. +     * Generate reports if a Clover module database or a Clover \
                merged database exist.
      *
-     * @return true if a project should be generated using the algorithm defined \
above +     * @return true if a project should be generated
      * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport()
      */
     public boolean canGenerateReport()
     {
         boolean canGenerate = false;
 
-        // Check if we have at least one project which is a java project
-        for ( Iterator projects = this.reactorProjects.iterator(); \
projects.hasNext(); ) +        AbstractCloverMojo.waitForFlush( this.waitForFlush, \
this.flushInterval ); +
+        File singleModuleCloverDatabase = new File( this.cloverDatabase );
+        File mergedCloverDatabase = new File ( this.cloverMergeDatabase );
+
+        if (singleModuleCloverDatabase.exists() || mergedCloverDatabase.exists() )
+        {
+            canGenerate = true;
+        }
+        else
         {
-            MavenProject project = (MavenProject) projects.next();
-            if ( isJavaProject(project) && !getChildrenCloverDatabases().isEmpty() )
-            {
-                canGenerate = true;
-                break;
-            }
+            getLog().warn("No Clover database found, skipping report generation");
         }
 
         return canGenerate;
-    }
-
-    private boolean isJavaProject(MavenProject project)
-    {
-        ArtifactHandler artifactHandler = \
                project.getArtifact().getArtifactHandler();
-        return "java".equals( artifactHandler.getLanguage() );
     }
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic