maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vmas...@apache.org
Subject svn commit: r525546 - in /maven/plugins/trunk/maven-clover-plugin/src: it/license-file/ it/license-file/src/ it/license-file/src/main/ it/license-file/src/main/java/ it/license-file/src/main/java/org/ it/license-file/src/main/java/org/apache/ it/licens...
Date Wed, 04 Apr 2007 16:01:36 GMT
Author: vmassol
Date: Wed Apr  4 09:01:35 2007
New Revision: 525546

URL: http://svn.apache.org/viewvc?view=rev&rev=525546
Log:
MCLOVER-45: Excluded files should be added to compiled sources

Added:
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/maven/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/maven/plugin/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/maven/plugin/clover/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/maven/plugin/clover/samples/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/maven/plugin/clover/samples/license/
    maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/maven/plugin/clover/samples/license/Simple.java
Modified:
    maven/plugins/trunk/maven-clover-plugin/src/it/simple/pom.xml
    maven/plugins/trunk/maven-clover-plugin/src/it/simple/src/main/java/org/apache/maven/plugin/clover/samples/simple/Simple.java
    maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java

Added: maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/maven/plugin/clover/samples/license/Simple.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/maven/plugin/clover/samples/license/Simple.java?view=auto&rev=525546
==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/maven/plugin/clover/samples/license/Simple.java
(added)
+++ maven/plugins/trunk/maven-clover-plugin/src/it/license-file/src/main/java/org/apache/maven/plugin/clover/samples/license/Simple.java
Wed Apr  4 09:01:35 2007
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2007 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+package org.apache.maven.plugin.clover.samples.license;
+
+public class Simple
+{
+    public void someMethod()
+    {
+        int i = 0;
+        if (i > 0)
+        {
+            i = i + 1;
+        }
+    }
+}

Modified: maven/plugins/trunk/maven-clover-plugin/src/it/simple/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/it/simple/pom.xml?view=diff&rev=525546&r1=525545&r2=525546
==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/it/simple/pom.xml (original)
+++ maven/plugins/trunk/maven-clover-plugin/src/it/simple/pom.xml Wed Apr  4 09:01:35 2007
@@ -60,7 +60,8 @@
           <!-- 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 -->
+          <!-- Verify that we can exclude some files from the instrumentation. Make sure
the file we are excluding
+               is referenced by other classes to ensure excluding is only done at the Clover
level -->
           <excludes>
             <exclude>**/*Dummy*.java</exclude>
           </excludes>

Modified: maven/plugins/trunk/maven-clover-plugin/src/it/simple/src/main/java/org/apache/maven/plugin/clover/samples/simple/Simple.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/it/simple/src/main/java/org/apache/maven/plugin/clover/samples/simple/Simple.java?view=diff&rev=525546&r1=525545&r2=525546
==============================================================================
--- maven/plugins/trunk/maven-clover-plugin/src/it/simple/src/main/java/org/apache/maven/plugin/clover/samples/simple/Simple.java
(original)
+++ maven/plugins/trunk/maven-clover-plugin/src/it/simple/src/main/java/org/apache/maven/plugin/clover/samples/simple/Simple.java
Wed Apr  4 09:01:35 2007
@@ -20,7 +20,10 @@
     public void someMethod()
     {
         assert true == true : "true was not true";
-        
+
+        // Reference a class that we exclude in the instrumentation
+        new Dummy();
+
         int i = 0;
         if (i > 0)
         {

Modified: maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentInternalMojo.java?view=diff&rev=525546&r1=525545&r2=525546
==============================================================================
--- 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
Wed Apr  4 09:01:35 2007
@@ -29,14 +29,11 @@
 import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner;
 import org.codehaus.plexus.compiler.util.scan.InclusionScanException;
 import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
+import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
-import java.util.List;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Collections;
+import java.io.IOException;
+import java.util.*;
 
 /**
  * Instrument source roots.
@@ -138,7 +135,7 @@
 
         if ( isJavaProject() )
         {
-            Set filesToInstrument = computeFilesToInstrument();
+            Map filesToInstrument = computeFilesToInstrument();
             if ( filesToInstrument.isEmpty() )
             {
                 getLog().warn( "No Clover instrumentation done as no matching sources files
found" );
@@ -146,6 +143,11 @@
             else
             {
                 instrumentSources( filesToInstrument );
+
+                // We need to copy excluded files as otherwise they won't be in the new Clover
source directory and
+                // thus won't be compiled by the compile plugin. This will lead to compilation
errors if any other
+                // Java file depends on any of these excluded files.
+                copyExcludedFiles();
             }
         }
 
@@ -177,7 +179,7 @@
         return isJavaProject;
     }
 
-    private void instrumentSources( Set filesToInstrument ) throws MojoExecutionException
+    private void instrumentSources( Map filesToInstrument ) throws MojoExecutionException
     {
         int result = CloverInstr.mainImpl( createCliArgs( filesToInstrument ) );
         if ( result != 0 )
@@ -186,6 +188,40 @@
         }
     }
 
+    /**
+     * Copy all files that have been excluded by the user (using the excludes configuration
property). This is required
+     * as otherwise the excluded files won't be in the new Clover source directory and thus
won't be compiled by the
+     * compile plugin. This will lead to compilation errors if any other Java file depends
on any of them.
+     *
+     * @throws MojoExecutionException if a failure happens during the copy
+     */
+    private void copyExcludedFiles() throws MojoExecutionException
+    {
+        Map filesToCopy = computeExcludedFilesToCopy();
+
+        for ( Iterator sourceRoots = filesToCopy.keySet().iterator(); sourceRoots.hasNext();
)
+        {
+            String sourceRoot = (String) sourceRoots.next();
+            Set filesInSourceRoot = (Set) filesToCopy.get( sourceRoot );
+
+            for ( Iterator files = filesInSourceRoot.iterator(); files.hasNext(); )
+            {
+                File file = (File) files.next();
+
+                try
+                {
+                    FileUtils.copyFile( file, new File( this.cloverOutputSourceDirectory,
+                        file.getPath().substring(sourceRoot.length() ) ) );
+                }
+                catch (IOException e)
+                {
+                    throw new MojoExecutionException( "Failed to copy excluded file [" +
file + "] to ["
+                        + this.cloverOutputSourceDirectory + "]", e );
+                }
+            }
+        }
+    }
+
     private void redirectOutputDirectories()
     {
         // Explicitely set the output directory to be the Clover one so that all other plugins
executing
@@ -431,25 +467,47 @@
         return scanner;
     }
 
-    /**
-     * @return the list of files to instrument taking into account the includes and excludes
specified by the user
-     */
-    private Set computeFilesToInstrument()
+    private SourceInclusionScanner getExcludesScanner()
     {
-        Set filesToInstrument = new HashSet();
-        SourceInclusionScanner scanner = getScanner();
-        
-        // Decide whether to instrument all source roots or only the main source root.
-        Iterator sourceRoots;
-        if ( this.includesAllSourceRoots )
+        SourceInclusionScanner scanner = null;
+
+        if ( excludes.isEmpty() )
         {
-            sourceRoots = getProject().getCompileSourceRoots().iterator();
+            scanner = new SimpleSourceInclusionScanner( Collections.EMPTY_SET, Collections.EMPTY_SET
);
         }
         else
         {
-            sourceRoots = Collections.singletonList( getProject().getBuild().getSourceDirectory()
).iterator();
+            scanner = new SimpleSourceInclusionScanner( excludes, Collections.EMPTY_SET );
         }
 
+        // Note: we shouldn't have to do this but this is a limitation of the Plexus SimpleSourceInclusionScanner
+        scanner.addSourceMapping( new SuffixMapping( "dummy", "dummy" ) );
+
+        return scanner;
+    }
+
+    /**
+     * @return the list of excluded files that we'll need to copy. See {@link #copyExcludedFiles()}.
+     */
+    private Map computeExcludedFilesToCopy()
+    {
+        return computeFiles(getExcludesScanner());
+    }
+
+    /**
+     * @return the list of files to instrument taking into account the includes and excludes
specified by the user
+     */
+    private Map computeFilesToInstrument()
+    {
+        return computeFiles(getScanner());
+    }
+
+    private Map computeFiles(SourceInclusionScanner scanner)
+    {
+        Map files = new HashMap();
+
+        // Decide whether to instrument all source roots or only the main source root.
+        Iterator sourceRoots = getSourceRoots().iterator();
         while ( sourceRoots.hasNext() )
         {
             File sourceRoot = new File( (String) sourceRoots.next() );
@@ -457,7 +515,7 @@
             {
                 try
                 {
-                    filesToInstrument.addAll( scanner.getIncludedSources( sourceRoot, null
) );
+                    files.put( sourceRoot.getPath(), scanner.getIncludedSources( sourceRoot,
null ) );
                 }
                 catch ( InclusionScanException e )
                 {
@@ -466,13 +524,28 @@
             }
         }
 
-        return filesToInstrument;
+        return files;
+    }
+
+    private List getSourceRoots()
+    {
+        List sourceRoots;
+        if ( this.includesAllSourceRoots )
+        {
+            sourceRoots = getProject().getCompileSourceRoots();
+        }
+        else
+        {
+            sourceRoots = Collections.singletonList( getProject().getBuild().getSourceDirectory()
);
+        }
+
+        return sourceRoots;
     }
 
     /**
      * @return the CLI args to be passed to CloverInstr
      */
-    private String[] createCliArgs( Set filesToInstrument ) throws MojoExecutionException
+    private String[] createCliArgs( Map filesToInstrument ) throws MojoExecutionException
     {
         List parameters = new ArrayList();
 
@@ -509,10 +582,14 @@
             }
         }
 
-        for ( Iterator files = filesToInstrument.iterator(); files.hasNext(); )
+        for ( Iterator sourceRoots = filesToInstrument.keySet().iterator(); sourceRoots.hasNext();
)
         {
-            File file = (File) files.next();
-            parameters.add( file.getPath() );
+            Set filesInSourceRoot = (Set) filesToInstrument.get( (String) sourceRoots.next()
);
+            for ( Iterator files = filesInSourceRoot.iterator(); files.hasNext(); )
+            {
+                File file = (File) files.next();
+                parameters.add( file.getPath() );
+            }
         }
 
         // Log parameters



Mime
View raw message