Hi Laurie,

I worked yetserday on the plug-in Patrick suggested and finally found a solution so that Cobertura is now running well under Maven 2 for my project.

Here are the instructions :

- download the Cobertura Maven 2 plug-in at http://jira.codehaus.org/secure/attachment/17669/cobertura-mojo -20051120.tar.bz2 as Patrick told you
        - uncompress the downloaded file
- go to the directory where you uncompressed it and type 'mvn install' such that the Cobertura pug-in will be installed in your local repository - type 'mvn site' so a site will be created in target/site with the documentation of Cobertura - add to your pom.xml (i don't know how it works with modules...) the following lines :

...
<build>
        ...
        <plugin>
                <groupId>org.codehaus.mojo</groupId>
                 <artifactId>cobertura-maven-plugin</artifactId>
                 <version>0.2-SNAPSHOT</version>
                 <configuration>
<instrumentedDirectory>main/cobertura/instrumented-classes</ instrumentedDirectory>
                        <outputDirectory>main/cobertura/report</outputDirectory>
                 </configuration>
                <executions>
                        <execution>
                                <id>instrument</id>
                                <phase>test-compile</phase>
                                 <goals>
                                                 <goal>instrument</goal>
                                </goals>
                         </execution>
                         <execution>
                                 <id>report</id>
                                 <phase>test</phase>
                                <goals>
                                                <goal>report</goal>
                                </goals>
                        </execution>
                         </executions>
      </plugin>
        ...
</build>
...
<reporting>
        <plugins>
                ...
                 <plugin>
                         <groupId>org.codehaus.mojo</groupId>
                                <artifactId>cobertura-maven-plugin</artifactId>
                 </plugin>
                ...
        </plugins>
</reporting>
...

!!! this is an example for the standard directories of Maven 2 : target/classes for normal classes and target/test-classes for test classes. But as you told me, you have a different directory structure : main/core. So you need to tell Cobertura where to find your normal classes and your test classes. And I don't how to do that. I guess you need to tell Maven 2 where your java classes are so that Cobertura will know it as well. Something like this should work (replace the '...' by the location of your various directories):

        ...
         <build>
                 <directory>...</directory>
                 <outputDirectory>...</outputDirectory>
                <finalName>${artifactId}-${version}</finalName>
                <testOutputDirectory>...</testOutputDirectory>
                 <sourceDirectory>...</sourceDirectory>
                 <scriptSourceDirectory>...</scriptSourceDirectory>
                 <testSourceDirectory>...</testSourceDirectory>
                 <resources>
                        <resource>
                                 <directory>...</directory>
                         </resource>
                </resources>
                <testResources>
                        <testResource>
                                        <directory>...</directory>
                        </testResource>
                </testResources>
                ...
         </build>
        ...

        - finally, type 'mvn test' or 'mvn install'

Voilà! I don't know if I answered to your request but this case works for me. If it still does not work, don't hesitate to mail me for helping. I can try to send you a solution for Ant as well.

Good luck, ;-)

Mathieu


Le Jan 10, 2006, à 2:51 PM, Laurie Tynor a écrit :



Thanks for the response!

I just tried the other plugin that Patrick suggested, but it doesn't
work for me either.  Pending whether I can resolve it, I may resort to
ant as well.

So you are running all of your unit tests inside of your ant script
instead of using surefire...  We really liked the ability to run
surefire and see which unit tests failed from looking at the target
directory results.

Did you end up re-implementing that functionality inside of your ant
script?

Did you try to get surefire to point to the instrumented classes and
then just let surefire run?  I was thinking of trying it that way, in
order to retain surefire.



Thanks,
Laurie

----------------------------------------------------------------------


Hi Laurie,

Hi faced problems with the Cobertura plugin for M2 as well. I tried =20 some tricks but I finally gave up. And reading some Cobertura news on =20=

the Net, it seems the Cobertura developpers are working on this plugin =20=

for Maven 2.

So I decided to find another solution : integrate a Cobertura ant task =20=

in my pom.xml. I know it is a little bit against the Maven philosophy =20=

but while the Cobertura plugin is not working, I think this is the only =20=

solution to your problem.

Here is a part of my pom.xml :


  <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
           <configuration>
=09
            <skip>true</skip>
=09
           </configuration>
  </plugin>

<plugin>
         <artifactId>maven-antrun-plugin</artifactId>
         <executions>
           <execution>
            <phase>test</phase>
            <configuration>
              <tasks>
=09
                <ant antfile=3D"${basedir}/build.xml" =
inheritRefs=3D"true">
                   <target name=3D"cobertura"/>
                 </ant>
=09
              </tasks>
             </configuration>
             <goals>
               <goal>run</goal>
             </goals>
           </execution>
         </executions>
       </plugin>

As you can see, you must skip the test executed by Maven, otherwise, =20
the tests will be executed twice. Hi called my Cobertura ant task =20
'cobertura' in my build.xml so it can be referenced by my target in my =20=

pom.xml.

If not alredy done, I advise you to subscribe to the Cobertura mailing =20=

list : [EMAIL PROTECTED]

Enjoy,

Le Jan 6, 2006, =E0 11:19 PM, Laurie Tynor a =E9crit :





I'm pretty new to maven, so this may be an obvious question to those
with more experience. I have looked through all the docs however, and
am unable to resolve it, and would appreciate any help/information.

I am using maven2 (2.0.1) and am trying to get the cobertura plugin to
work.  I am able to run cobertura under ant, but not with maven2.

Our build directory uses maven modules.  It's structure is like this:
main/
main/pom.xml (which has module declarations for core, etc)
main/core/
main/core/pom.xml (which has some additional dependencies for core =20
classes)
  <etc>

The pom.xml in the main level produces no artifacts.  The main
directory has no classes just has a few subdirectories.  The
subdirectories have the classes, resources, and unit tests.  The
main-level pom.xml has the surefire plugin, which is working fine
traversing the subdirectories.


Here are the details for my cobertura attempts.  Any help is
appreciated:

1.  Version from the svn sandbox (which uses cobertura 1.7), and
specifies the instrument goal in the lifecycle.xml file as part of the
process-classes phases:

    a) When I call "mvn install", which should trigger the
    instrumentation goal, nothing happens.  It looks like
    instrumentation is not attempted

    b) When I call "mvn site", I get this null-pointer exception =20
(which I think is because the target/generated-classes directory was =20=

never produced from the mvn install):
[INFO]    task-segment: [site]
[INFO] =20
=
---------------------------------------------------------------------- -=20=

--
---
[INFO] Preparing surefire-report:report
[INFO] No goals needed for project - skipping
[INFO] Preparing cobertura:cobertura
[INFO] =20
=
---------------------------------------------------------------------- -=20=

--
---
[ERROR] FATAL ERROR
[INFO] =20
=
---------------------------------------------------------------------- -=20=

--
---
[INFO] null
[INFO] =20
=
---------------------------------------------------------------------- -=20=

--
---
[INFO] Trace
java.lang.NullPointerException
        at =20
org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor
(DefaultLifecycleExecutor.java:884)
        at =20
org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkProjectLifecy
cle(DefaultLifecycleExecutor.java:842)
        at =20
org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkLifecycle(Def
aultLifecycleExecutor.java:729)
        at =20
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:521)
        at =20
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLi
        <etc>


    c) When I try to call the instrument target directly, I get a
    "BUILD ERROR" that says "Unable to prepare instrumentation
    directory.  Source directory doesn't exist".  The
    target/generated-classes/cobertura directory is created so I can
    tell that it did try to instrument



2. Version from the maven auto-download. This one uses cobertura 1.6,
and specifies instrumentation as part of the generate-sources phase
(which I don't think is correct):

    a) When I call "mvn install", which should trigger the
instrumentation goal, nothing happens as with the sandbox version.

    b) When I call "mvn site", I get an error that the cobertura.ser
    file doesn't exist (which it doesn't because the install did
    nothing)

    c) When I try to call the instrument target directly, I get this
error:
[INFO] Trace
java.lang.IllegalStateException: basedir C:<etc>\target\classes does =20=

not exist
        at =20
org.codehaus.plexus.util.DirectoryScanner.scan(DirectoryScanner.java:
542)
        at =20
org.codehaus.plexus.util.FileUtils.getFileNames(FileUtils.java:1402)
        at =20
org.codehaus.plexus.util.FileUtils.getFileNames(FileUtils.java:1368)
        at =20
org.codehaus.mojo.cobertura.tasks.InstrumentTask.execute(InstrumentTa
sk.java:97)
        at =20
org.codehaus.mojo.cobertura.CoberturaInstrumentMojo.execute(Cobertura
InstrumentMojo.java:91)
        at =20
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:432)
        at =20
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:530)
        at =20
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
Goal(DefaultLifecycleExecutor.java:485)
        at =20
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:455)
        at =20
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:303)
        at =20
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen

        <etc>


3.  Here is the top-level pom.xml file contents (with a little bit
blanked out).   (I've also tried the plugin tag under build to have
the
<executions><execution><goals><goal>clean</goal></goals></ execution></=20=

executions>
but that didn't seem to affect anything)


<project xmlns=3D"http://maven.apache.org/POM/4.0.0"; =20
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance";
         xsi:schemaLocation=3D"http://maven.apache.org/POM/4.0.0 =20
http://maven.apache.org/maven-v4_0_0.xsd";>
    <modelVersion>4.0.0</modelVersion>
    <groupId>MyId</groupId>
    <artifactId>MyArtifact</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Field Equipment Simulator</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.12</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>1.8.0.1</version>
        </dependency>

        <!-- test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- plugins -->

    </dependencies>

    <modules>
        <module>MyModule1</module>
        <module>MyModule2</module>
        <module>MyModule3</module>
        <module>MyModule4</module>
        <module>MyModule5</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>2.0-beta-4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
      </plugin>
        </plugins>


    </build>

    <reporting>

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>surefire-report-maven-plugin</artifactId>
                <version>2.0-beta-1</version>
                <!--
                <configuration>
                    =20
<outputDirectory>${project.build.directory}/site</outputDirectory>
                    =20
<reportsDirecotry>${project.build.directory}/surefire-reports</=20
reportsDirecotry>
                </configuration>
                -->
            </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
      </plugin>
        </plugins>
    </reporting>

    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Repository Switchboard</name>
            <layout>default</layout>
            <url>http://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>

        <repository>
            <id>MyLocalRepository</id>
            <name>MyLocaalRepositoryName</name>
            <url>http://MyLocalRepositoryUrl</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>snapshot</id>
            <name>Maven Snapshot Repository</name>
            <layout>default</layout>
            <url>http://snapshots.maven.codehaus.org/maven2/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <developers>
        <developer>
            <name>MyDeveloper</name>
        </developer>
    </developers>
</project>

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



Mathieu Vanderwhale

___________________________________________

DENALI sa - http://www.denali.be
Ch=E2teau 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]


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