I am working on Cobertura and my problem is as follows :

As there is still no Maven2 Cobertura plug-in, I am trying to integrate it under an ant task. Everything goes well but the report Cobertura creates has always 0% coverage. The reason is that Cobertura needs to know where are all the classes (instrumented, non-instrumented, test, etc) it needs. To resolve that I need to pass these directories whre are all my classes to the classpath. Under Ant, it is easy : you just need to add the <classpath location="target/cobertura/instrumented-classes" /> for example in the Junit task. But in Maven2, as the JUnit task is automatic it is not so easy...

Here is an extract of my pom.xml trying to do that :

<build>
    <plugins>
        
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <classpathElements>
<classpathElement>target/cobertura/instrumented-classes</ classpathElement>
            </classpathElements>
          </configuration>
       </plugin>

       <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
          <id>instrument-phase</id>
          <phase>compile</phase>
            <configuration>
        
              <tasks>
<taskdef classpath="/Users/mvanderwhale/.m2/repository/cobertura/cobertura/1.7/ cobertura-1.7.jar" resource="tasks.properties"/>
                
                <property file="build.properties" />

                <path id="cobertura_classpath">
                        <fileset dir="${cobertura.dir}">
                                <include name="cobertura.jar" />
                        </fileset>
                        <fileset dir="${lib.dir}">
                                <include name="**/*.jar" />
                        </fileset>
                </path>
                
                <delete file="${basedir}/cobertura.ser"/>
                <delete dir="target/cobertura" />
                
                <cobertura-instrument 
todir="target/cobertura/instrumented-classes">
                        <ignore regex="org.apache.log4j.*" />
                        <fileset dir="target/classes">
                                <include name="**/*.class" />
                                <exclude name="**/*Test.class" />
                        </fileset>
                </cobertura-instrument>
                        
              </tasks>
            </configuration>
        
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
          <execution>
            <id>report-phase</id>
            <phase>test</phase>
            <configuration>
              <tasks>
                
<taskdef classpath="/Users/mvanderwhale/.m2/repository/cobertura/cobertura/1.7/ cobertura-1.7.jar" resource="tasks.properties"/>
                
                <property file="build.properties" />

                <path id="cobertura_classpath">
                        <fileset dir="${cobertura.dir}">
                                <include name="cobertura.jar" />
                        </fileset>
                        <fileset dir="${lib.dir}">
                                <include name="**/*.jar" />
                        </fileset>
                </path>
        
<cobertura-report format="html" destdir="target/cobertura/report" srcdir="src/main/java/Mat" />
                        
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>


As you can see, I tried to edit the surefire plug-in in order to add <classpathElement>target/cobertura/instrumented-classes</ classpathElement> so that Cobertura knows where are these classes it needs. Unfortunately, it leads to this error :


+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------ ----
[INFO] Building Maven Quick Start Archetype
[INFO]    task-segment: [test]
[INFO] ------------------------------------------------------------------------ ----
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
Compiling 1 source file to /Users/mvanderwhale/Documents/workspace/JUnitTest/test_app/target/ classes
[INFO] [antrun:run {execution: instrument-phase}]
[INFO] Executing tasks
[delete] Deleting: /Users/mvanderwhale/Documents/workspace/JUnitTest/test_app/ cobertura.ser [delete] Deleting directory /Users/mvanderwhale/Documents/workspace/JUnitTest/test_app/target/ cobertura [cobertura-instrument] Cobertura 1.7 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file [cobertura-instrument] Instrumenting 3 classes to /Users/mvanderwhale/Documents/workspace/JUnitTest/test_app/target/ cobertura/instrumented-classes
[cobertura-instrument] Cobertura: Saved information on 1 classes.
[cobertura-instrument] Instrument time: 390ms
[INFO] Executed tasks
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
Compiling 1 source file to /Users/mvanderwhale/Documents/workspace/JUnitTest/test_app/target/test- classes [INFO] ------------------------------------------------------------------------ ----
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------ ---- [INFO] Error configuring: org.apache.maven.plugins:maven-surefire-plugin. Reason: ERROR: Cannot override read-only parameter: classpathElements in goal: surefire:test [INFO] ------------------------------------------------------------------------ ----
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Error configuring: org.apache.maven.plugins:maven-surefire-plugin. Reason: ERROR: Cannot override read-only parameter: classpathElements in goal: surefire:test at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Default LifecycleExecutor.java:559) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifec ycle(DefaultLifecycleExecutor.java:472) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultL ifecycleExecutor.java:451) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandle Failures(DefaultLifecycleExecutor.java:303) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments( DefaultLifecycleExecutor.java:270) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifec ycleExecutor.java:139) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:249)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Impl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.PluginConfigurationException: Error configuring: org.apache.maven.plugins:maven-surefire-plugin. Reason: ERROR: Cannot override read-only parameter: classpathElements in goal: surefire:test at org.apache.maven.plugin.DefaultPluginManager.validatePomConfiguration(De faultPluginManager.java:868) at org.apache.maven.plugin.DefaultPluginManager.getConfiguredMojo(DefaultPl uginManager.java:578) at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginMa nager.java:410) at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Default LifecycleExecutor.java:530)
        ... 16 more
[INFO] ------------------------------------------------------------------------ ----
[INFO] Total time: 14 seconds
[INFO] Finished at: Wed Jan 04 15:38:48 CET 2006
[INFO] Final Memory: 3M/9M
[INFO] ------------------------------------------------------------------------ ----

Does anyone know how to edit this surefire plugin or another way to use Cobertura in order to have correct reports?

Mathieu Vanderwhale

___________________________________________

DENALI sa - http://www.denali.be
Château de Clerlande - 1340 Ottignies - Belgium
Tel +32 (0) 10 43 99 51 - Fax +32 (0) 10 43 99 52
___________________________________________


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to