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 2005/12/21 19:34:36 UTC

svn commit: r358338 - /maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java

Author: vmassol
Date: Wed Dec 21 10:34:32 2005
New Revision: 358338

URL: http://svn.apache.org/viewcvs?rev=358338&view=rev
Log:
MCLOVER-14: http://jira.codehaus.org/browse/MCLOVER-14

Modified:
    maven/plugins/trunk/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverInstrumentMojo.java

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=358338&r1=358337&r2=358338&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 Wed Dec 21 10:34:32 2005
@@ -85,19 +85,34 @@
     public void execute()
         throws MojoExecutionException
     {
-        init();
-
-        registerLicenseFile();
+        // Do not perform anything if there are no source files
+        File srcDir = new File(this.project.getBuild().getSourceDirectory());
+        if (srcDir.exists())
+        {
+            init();
+            registerLicenseFile();
+            instrumentSources();
+            addGeneratedSourcesToCompileRoots();
+            addCloverDependencyToCompileClasspath();
+            redirectOutputDirectories();
+        }
+        else
+        {
+            getLog().debug("No sources found - No Clover instrumentation done");
+        }
+    }
 
+    private void instrumentSources() throws MojoExecutionException
+    {
         int result = CloverInstr.mainImpl( createCliArgs() );
         if ( result != 0 )
         {
             throw new MojoExecutionException( "Clover has failed to instrument the source files" );
         }
+    }
 
-        addGeneratedSourcesToCompileRoots();
-        addCloverDependencyToCompileClasspath();
-
+    private void redirectOutputDirectories()
+    {
         // 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 );
@@ -108,7 +123,7 @@
         this.project.getBuild().setTestOutputDirectory(
             new File( this.cloverOutputDirectory, "test-classes" ).getPath() );
     }
-
+    
     /**
      * @todo handle multiple source roots. At the moment only the first source root is instrumented
      */