jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
Maven 2.x Cobertura Plugin
  • Maven 2.x Cobertura Plugin
  • MCOBERTURA-52

Ignores and Excludes do nothing

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0
  • Fix Version/s: 2.5.2
  • Labels:
    None
  • Environment:
    Windows
  • Number of attachments :
    3

Description

After adding this to the POM:

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<instrumentation>
<excludes>
<exclude>org/example/**/*Test.class</exclude>
<exclude>$

{basedir}

</exclude>
</excludes>
</instrumentation>
<check>
<haltOnFailure>false</haltOnFailure>
</check>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Cobertura still reports on all classes.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    Issue52Patch2.patch
    05/Dec/11 11:06 AM
    7 kB
    Miguel Almeida
  2. Text File
    Issue52Patch3.patch
    05/Dec/11 12:37 PM
    8 kB
    Miguel Almeida
  3. Text File
    Issue52Patch4.patch
    05/Dec/11 1:00 PM
    8 kB
    Miguel Almeida

Issue Links

is related to

Bug - A problem which impairs or prevents the functions of the product. SONAR-1283 Exclusions are not handled properly by Cobertura

  • Critical - Crashes, loss of data, severe memory leak.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Gary Kind added a comment - 29/Nov/06 2:36 PM

I am having the exact same issue. I cannot get Cobertura to exclude or ignore. The documentation is sparse and very poor for beginners. Can somebody get on this? My management is on my tail trying to get unwanted packages removed from the coverage reports.

Show
Gary Kind added a comment - 29/Nov/06 2:36 PM I am having the exact same issue. I cannot get Cobertura to exclude or ignore. The documentation is sparse and very poor for beginners. Can somebody get on this? My management is on my tail trying to get unwanted packages removed from the coverage reports.
Hide
Permalink
Gary Kind added a comment - 29/Nov/06 6:05 PM

I believe this problem has something to do with a corrupted cobertura.ser file. I somehow got it to work, i.e. it was excluding the proper packages and classes. Since I had a number of exclude statements, I tried to isolate the exclude rules that were getting it to work. It just kept working until I took out all of the rules, then, of course nothing was excluded as expected. I then started putting rules back in until all were back but it still didn't work! I I figured there had to be some sort of caching optimization – something that was keeping track of the previous rules. I took a wild guess and blew away the cobertura.ser file in $

{basedir}

and it started working again! When it was bad, the cobertura.ser was 544K in size. When it was good, its size was only 164K.

I can only conclude that there is a bug here and that it has to do with what is written to the cobertura.ser file.
As a workaround, I would suggest blowing away your cobertura.ser file (noting the file's size) and then trying it again. It should work – take a note of the new file's size-- as long as your excludes are correct.

Show
Gary Kind added a comment - 29/Nov/06 6:05 PM I believe this problem has something to do with a corrupted cobertura.ser file. I somehow got it to work, i.e. it was excluding the proper packages and classes. Since I had a number of exclude statements, I tried to isolate the exclude rules that were getting it to work. It just kept working until I took out all of the rules, then, of course nothing was excluded as expected. I then started putting rules back in until all were back but it still didn't work! I I figured there had to be some sort of caching optimization – something that was keeping track of the previous rules. I took a wild guess and blew away the cobertura.ser file in $ {basedir} and it started working again! When it was bad, the cobertura.ser was 544K in size. When it was good, its size was only 164K. I can only conclude that there is a bug here and that it has to do with what is written to the cobertura.ser file. As a workaround, I would suggest blowing away your cobertura.ser file (noting the file's size) and then trying it again. It should work – take a note of the new file's size-- as long as your excludes are correct.
Hide
Permalink
Trond Andersen added a comment - 18/Dec/07 10:07 AM

I took a look at the code for this plugin with regards to the issue here. There is InstrumentTaskTest which has very limited tests for configuration.

I tried to add the following to the testConfig method so that it now looks like this:

InstrumentTaskTest
    public void testConfig() throws Exception
    {
        ConfigInstrumentation config = new ConfigInstrumentation();
        String demoIgnore = "org.codehaus.mojo.cobertura.demo.*";
        String moreIgnore = "org.codehaus.mojo.cobertura.moredemo.*";
        config.addIgnore(demoIgnore);
        config.addIgnore(moreIgnore);

        task.setConfig( config );

        assertEquals( config, task.getConfig() );

        task.execute();
        assertFalse(task.getCmdLineArgs().getArgs().isEmpty());
        assertEquals("--ignore", task.getCmdLineArgs().getArgs().get(0));
        assertEquals(demoIgnore, task.getCmdLineArgs().getArgs().get(1));
        assertEquals("--ignore", task.getCmdLineArgs().getArgs().get(2));
        assertEquals(moreIgnore, task.getCmdLineArgs().getArgs().get(3));
    }

As you see from the test that this plugin will add a new --ignore for each ignore configuration that is included. Can anyone say something with regards to if this is correct or not?

Show
Trond Andersen added a comment - 18/Dec/07 10:07 AM I took a look at the code for this plugin with regards to the issue here. There is InstrumentTaskTest which has very limited tests for configuration. I tried to add the following to the testConfig method so that it now looks like this: InstrumentTaskTest public void testConfig() throws Exception { ConfigInstrumentation config = new ConfigInstrumentation(); String demoIgnore = "org.codehaus.mojo.cobertura.demo.*" ; String moreIgnore = "org.codehaus.mojo.cobertura.moredemo.*" ; config.addIgnore(demoIgnore); config.addIgnore(moreIgnore); task.setConfig( config ); assertEquals( config, task.getConfig() ); task.execute(); assertFalse(task.getCmdLineArgs().getArgs().isEmpty()); assertEquals( "--ignore" , task.getCmdLineArgs().getArgs().get(0)); assertEquals(demoIgnore, task.getCmdLineArgs().getArgs().get(1)); assertEquals( "--ignore" , task.getCmdLineArgs().getArgs().get(2)); assertEquals(moreIgnore, task.getCmdLineArgs().getArgs().get(3)); } As you see from the test that this plugin will add a new --ignore for each ignore configuration that is included. Can anyone say something with regards to if this is correct or not?
Hide
Permalink
Paul Benedict added a comment - 22/May/08 1:21 AM

This link shows a different kind of POM configuration. Is it "too old" to be right anymore or is he actually right?
http://markmail.org/message/qnaxkfnumfojcmmg

Show
Paul Benedict added a comment - 22/May/08 1:21 AM This link shows a different kind of POM configuration. Is it "too old" to be right anymore or is he actually right? http://markmail.org/message/qnaxkfnumfojcmmg
Hide
Permalink
Fabian Reichlin added a comment - 03/Jul/08 3:51 AM - edited

I think the <ignore> statement is rather confusing – instead of ignoring entire methods in custom classes, just single method calls within custom methods are filtered out (e.g. logging statements in your methods). So, if entire methods from your classes should be excluded (e.g. when they cannot be tested) in favor of getting a higher code coverage rate, it just would not be possible.

We patched Cobertura and the Maven-Cobertura-Plugin such that entire methods can now be excluded from instrumentation. If you're interested, add ftp://el4.elca-services.ch/htdocs/el4j/maven2repository/ to your mirrors, and use it as follows:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.2-el4j_20080702_1630</version>
    <configuration>
        <instrumentation>
            <!-- Ignore entire methods from being instrumented. -->
            <ignoreMethods>
                <!-- Ignore all methods ending with Untested from
                the com.yourcompany package. -->
                <ignoreMethod>com.yourcompany.*.*Untested</ignoreMethod>
            </ignoreMethods>
        </instrumentation>
    </configuration>
</plugin>

Note that it is also possible to e.g. ignoring setter and getter method, by configuring

<ignoreMethods>
    <!-- Ignore all setter and getter methods in your classes -->
    <ignoreMethod>com.yourcompany.*.set*</ignoreMethod>
    <ignoreMethod>com.yourcompany.*.get*</ignoreMethod>
</ignoreMethods>
Show
Fabian Reichlin added a comment - 03/Jul/08 3:51 AM - edited I think the <ignore> statement is rather confusing – instead of ignoring entire methods in custom classes, just single method calls within custom methods are filtered out (e.g. logging statements in your methods). So, if entire methods from your classes should be excluded (e.g. when they cannot be tested) in favor of getting a higher code coverage rate, it just would not be possible. We patched Cobertura and the Maven-Cobertura-Plugin such that entire methods can now be excluded from instrumentation. If you're interested, add ftp://el4.elca-services.ch/htdocs/el4j/maven2repository/ to your mirrors, and use it as follows: <plugin> <groupId> org.codehaus.mojo </groupId> <artifactId> cobertura-maven-plugin </artifactId> <version> 2.2-el4j_20080702_1630 </version> <configuration> <instrumentation> <!-- Ignore entire methods from being instrumented. --> <ignoreMethods> <!-- Ignore all methods ending with Untested from the com.yourcompany package. --> <ignoreMethod> com.yourcompany.*.*Untested </ignoreMethod> </ignoreMethods> </instrumentation> </configuration> </plugin> Note that it is also possible to e.g. ignoring setter and getter method, by configuring <ignoreMethods> <!-- Ignore all setter and getter methods in your classes --> <ignoreMethod> com.yourcompany.*.set* </ignoreMethod> <ignoreMethod> com.yourcompany.*.get* </ignoreMethod> </ignoreMethods>
Hide
Permalink
Bryce Griner added a comment - 20/Dec/10 2:43 PM

I am working with the Cobertura 2.4 plugin and this issue still remains. When I put in excludes they are completely ignored.

Show
Bryce Griner added a comment - 20/Dec/10 2:43 PM I am working with the Cobertura 2.4 plugin and this issue still remains. When I put in excludes they are completely ignored.
Hide
Permalink
ggoodwin added a comment - 20/Dec/10 3:54 PM

same type of issue as mentioned above. To get an accurate report, i need to exclude some packages. If there is a workaround, please post. If i cannot get these packages excluded I will have to go to another tool (emma or clover)

Show
ggoodwin added a comment - 20/Dec/10 3:54 PM same type of issue as mentioned above. To get an accurate report, i need to exclude some packages. If there is a workaround, please post. If i cannot get these packages excluded I will have to go to another tool (emma or clover)
Hide
Permalink
Benson Margulies added a comment - 23/Apr/11 1:54 PM

I don't suppose the person who made the patch is still listening and can attach the patch?

Show
Benson Margulies added a comment - 23/Apr/11 1:54 PM I don't suppose the person who made the patch is still listening and can attach the patch?
Hide
Permalink
Dan Ox added a comment - 25/Jul/11 7:22 PM

This appears to still be a problem 5 years later. I've been trying to exclude calls to common logging from instrumentation but it seems to have no effect. Reports and checks still pick up the log calls as relevant. The config I am using looks like:

pom.xml
<plugins>
	<plugin>
		<groupId>org.codehaus.mojo</groupId>
		<artifactId>cobertura-maven-plugin</artifactId>
		<configuration>
			<quiet>false</quiet>
			<instrumentation>
				<ignores>
					<ignore>org.apache.commons.logging.*</ignore>
				</ignores>
			</instrumentation>
			<check>
			...
			</check>
		</configuration>
	</plugin>
<plugins>

I've traced through the plugin and verified that it is sending an ignores parameter to the cobertura program, so I think that they plugin is not at fault unless it is doing something else that invalidates the ignore parameter. This is very frustrating.

Show
Dan Ox added a comment - 25/Jul/11 7:22 PM This appears to still be a problem 5 years later. I've been trying to exclude calls to common logging from instrumentation but it seems to have no effect. Reports and checks still pick up the log calls as relevant. The config I am using looks like: pom.xml <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <configuration> <quiet> false </quiet> <instrumentation> <ignores> <ignore>org.apache.commons.logging.*</ignore> </ignores> </instrumentation> <check> ... </check> </configuration> </plugin> <plugins> I've traced through the plugin and verified that it is sending an ignores parameter to the cobertura program, so I think that they plugin is not at fault unless it is doing something else that invalidates the ignore parameter. This is very frustrating.
Hide
Permalink
Gan Yang added a comment - 27/Jul/11 3:28 AM

I am working with the Cobertura 2.5.1 plugin and this issue still remains. When I put in excludes they are completely ignored.

Show
Gan Yang added a comment - 27/Jul/11 3:28 AM I am working with the Cobertura 2.5.1 plugin and this issue still remains. When I put in excludes they are completely ignored.
Hide
Permalink
Miguel Almeida added a comment - 25/Nov/11 9:10 AM

This patch fixes this issue (for my simple test case).

I would really like to create a test case for it and have it reviewed before I commit it.

Show
Miguel Almeida added a comment - 25/Nov/11 9:10 AM This patch fixes this issue (for my simple test case). I would really like to create a test case for it and have it reviewed before I commit it.
Hide
Permalink
Miguel Almeida added a comment - 05/Dec/11 10:16 AM

2nd version of the patch: I added a test case.

This class is really hard to test, so I made a few changes to ease testing. However, a project maintainer should review this and:

a) Either confirm the test or suggest an alternative location for it

b) Suggest the relevant integration test where this test should be

Show
Miguel Almeida added a comment - 05/Dec/11 10:16 AM 2nd version of the patch: I added a test case. This class is really hard to test, so I made a few changes to ease testing. However, a project maintainer should review this and: a) Either confirm the test or suggest an alternative location for it b) Suggest the relevant integration test where this test should be
Hide
Permalink
Miguel Almeida added a comment - 05/Dec/11 12:37 PM

Use most recent patch - it has an updated IT test in project mcobertura-52

Show
Miguel Almeida added a comment - 05/Dec/11 12:37 PM Use most recent patch - it has an updated IT test in project mcobertura-52
Hide
Permalink
Miguel Almeida added a comment - 05/Dec/11 1:00 PM

Forgot source classes in previous patch

Show
Miguel Almeida added a comment - 05/Dec/11 1:00 PM Forgot source classes in previous patch
Hide
Permalink
Robert Scholte added a comment - 05/Dec/11 2:09 PM

The exclude is not a problem (anymore), the ignore is. Let's first figure out why there are two options which kind of do the same thing based on the name.

Show
Robert Scholte added a comment - 05/Dec/11 2:09 PM The exclude is not a problem (anymore), the ignore is. Let's first figure out why there are two options which kind of do the same thing based on the name.
Hide
Permalink
Miguel Almeida added a comment - 06/Dec/11 4:14 AM

According to http://maven.40175.n5.nabble.com/Cobertura-what-is-ignore-used-for-in-maven-I-don-t-see-it-mentioned-td114935.html :

"I'm guessing that ignore will still measure the coverage, but if you are enforcing a minimum coverage number, that package will be ignored. Exclude will not even bother measuring the coverage "

Show
Miguel Almeida added a comment - 06/Dec/11 4:14 AM According to http://maven.40175.n5.nabble.com/Cobertura-what-is-ignore-used-for-in-maven-I-don-t-see-it-mentioned-td114935.html : "I'm guessing that ignore will still measure the coverage, but if you are enforcing a minimum coverage number, that package will be ignored. Exclude will not even bother measuring the coverage "
Hide
Permalink
Robert Scholte added a comment - 08/Dec/11 4:13 PM

I figured out the difference: include/exclude has to do with the files to instrument.
According to the docs of Cobertura

Parameter Required? Description Default Value
--ignore No Specify a regular expression to filter out certain lines of your source code. This is useful for ignoring logging statements, for example. You can have as many <ignore/> statements as you want. No files are ignored.

It's a shame there's no example. I'll have to search for that, add a FAQ entry for it and document it better in the code.

Show
Robert Scholte added a comment - 08/Dec/11 4:13 PM I figured out the difference: include/exclude has to do with the files to instrument. According to the docs of Cobertura Parameter Required? Description Default Value --ignore No Specify a regular expression to filter out certain lines of your source code. This is useful for ignoring logging statements, for example. You can have as many <ignore/> statements as you want. No files are ignored. It's a shame there's no example. I'll have to search for that, add a FAQ entry for it and document it better in the code.
Hide
Permalink
Robert Scholte added a comment - 10/Dec/11 5:22 AM

Fixed in rev. 15530
The excludes was already fixed somewhere in the past. I've added a FAQ entry about the meaning of ignores.

Show
Robert Scholte added a comment - 10/Dec/11 5:22 AM Fixed in rev. 15530 The excludes was already fixed somewhere in the past. I've added a FAQ entry about the meaning of ignores .
Hide
Permalink
Dmitry Goldenberg added a comment - 09/Jan/12 11:38 AM

Folks,

I can see that this is fixed in 2.6 according to this issue. When is this version going to be officially available? http://repo1.maven.org/maven2/ only has versions up to 2.5.1 but not 2.6.

Also it seems that includes don't work E.g. shouldn't the following work effectively as an exclude? I.e. if I have com.foo.pkg1 and com.foo.pkg2, shouldn't the below only instrument pkg1 and leave pkg2 not included?

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<instrumentation>
<includes>
<include>com/foo/pkg1/*.class</include>
</includes>
</instrumentation>
</configuration>
<executions>
<execution>
<id>clean</id>
<phase>pre-site</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<id>instrument</id>
<phase>site</phase>
<goals>
<goal>instrument</goal>
<goal>cobertura</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

Show
Dmitry Goldenberg added a comment - 09/Jan/12 11:38 AM Folks, I can see that this is fixed in 2.6 according to this issue. When is this version going to be officially available? http://repo1.maven.org/maven2/ only has versions up to 2.5.1 but not 2.6. Also it seems that includes don't work E.g. shouldn't the following work effectively as an exclude? I.e. if I have com.foo.pkg1 and com.foo.pkg2, shouldn't the below only instrument pkg1 and leave pkg2 not included? <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <configuration> <instrumentation> <includes> <include>com/foo/pkg1/*.class</include> </includes> </instrumentation> </configuration> <executions> <execution> <id>clean</id> <phase>pre-site</phase> <goals> <goal>clean</goal> </goals> </execution> <execution> <id>instrument</id> <phase>site</phase> <goals> <goal>instrument</goal> <goal>cobertura</goal> <goal>check</goal> </goals> </execution> </executions> </plugin>

People

  • Assignee:
    Robert Scholte
    Reporter:
    Jim Wilson
Vote (16)
Watch (12)

Dates

  • Created:
    09/Nov/06 3:54 PM
    Updated:
    10/Sep/12 12:13 PM
    Resolved:
    10/Dec/11 5:22 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.