generic coverage does not use good source folder

92 views
Skip to first unread message

jero...@gmail.com

unread,
Nov 11, 2016, 5:30:54 AM11/11/16
to SonarQube
Hi everybody.

I'm trying to use the sonar generic coverage plugin on my projet. This is a multi-module maven project, let's say something like this :

root
|-- module1
|    |-- sources
|    |   |-- com.foo.Foo.java
|    |   |-- ...
|    |-- tests
|    |   |-- com.foo.FooTest.java
|    |   |-- ...
|-- module2
|    |   |-- com.bar.Bar.java
|    |   |-- ...
|    |-- tests
|    |   |-- com.bar.BarTest.java
|    |   |-- ...
.... many many modules (jar, ejb, war, ear)

As you can see, projects don't use the standard maven (src/main/java, src/test/java), and it is probably the reason of my problems.

In maven, we configure the <sourceDirectory> to sources and <testSourceDirectory> to tests, normal.

I use the plugin com.qualinsight.mojo.cobertura to get the coverage of my tests and it works well, coverage.xml and converted-coverage.xml are generated in each module (target/cobertura/ut/).

Then, when running mvn sonar:sonar from the root project, i have the message in each module :
[INFO] Imported coverage data for 0 files
[INFO] coverage data ignored for x unknown files, including....

I first tried to allow import unknown files but did not change anything.

So I cloned the projet (generic coverage) and add some logs in the ReportParser#parseFiles method. 
First I logged the fileSystem with all() predicate. I obtained something logical:
D:\workspace\module1\source\com\foo\Foo.java

Then, i logged the filePath (retrieve with mandatoryAttribute(fileCursor, "path")) and here is the trouble:
src/main/java/com/foo/Foo.java 

Why is it src/main/java ? What is SMInputCursor, SMHierarchyCursor, ... and why it does not use the maven source directory configuration ?

I tried to configure sonar with the following properties :
<sonar.sources>.</sonar.sources>
<sonar.exclusions>target/**, tests/**</sonar.exclusions>

But it does not change anything except that sonar browse more files...

Please, anyone has an idea ?

Thanks.

Jerome

jero...@gmail.com

unread,
Nov 11, 2016, 7:41:29 AM11/11/16
to SonarQube
I tried to replace src/main/java with source in the code of the plugin, just to go further waiting an answer here... And it actually works. In the logs, I can see

[INFO] Imported coverage data for x files

So why does it try to use src/main/java instead of my declared sourceDirectory ?

Thanks in advance.

Michel Pawlak

unread,
Nov 11, 2016, 8:29:55 AM11/11/16
to SonarQube, jero...@gmail.com
Why oh why

Probably because the path was hardcoded instead of using Maven properties...

Please indicate the file where the problem is located, I'll correct the plugin and submit a PR (or simply correct it yourself then submit a PR)

Michel

jero...@gmail.com

unread,
Nov 11, 2016, 8:35:17 AM11/11/16
to SonarQube
Trouble is I don't know where the bug come from. I've just hacked the method ReportParser#parseFiles() but the problem come from elsewhere : SMInputCursor, SMHierarchyCursor...

Michel Pawlak

unread,
Nov 11, 2016, 9:04:17 AM11/11/16
to SonarQube, jero...@gmail.com
I just realized that you're using qualinsight-mojo-cobertura (sorry about that, I should have read your message more carefully, escpecially as I'm the author of qualinsight-mojo-cobertura

I'm pretty sure that it's not a problem with the generic coverage plugin, but rather a qualinsight-mojo-cobertura plugin misconfiguration (missing baseDirectoryPath) . You can verify it by opening converted-coverage.xml file. If the path contains src/main then bingo : you forgot to configure the plugin properly.

Can you please paste your qualinsight-mojo-cobertura plugin configuration ?

Michel

P.S. by the way have a look at the documentation : https://github.com/QualInsight/qualinsight-mojo-cobertura

jero...@gmail.com

unread,
Nov 11, 2016, 9:14:03 AM11/11/16
to SonarQube, jero...@gmail.com
Sorry, I already did it :

<plugin>
   	<groupId>com.qualinsight.mojo.cobertura</groupId>
	<artifactId>qualinsight-mojo-cobertura-core</artifactId>
	<version>1.1.0</version>
	<executions>
		<execution>
			<id>instrument-ut</id>
			<goals>
				<goal>instrument-ut</goal>
			</goals>
		</execution>
		<execution>
			<id>report-ut-coverage</id>
			<goals>
				<goal>report-ut-coverage</goal>
			</goals>
		</execution>
	</executions>
	<configuration>				
		<baseDirectoryPath>${project.basedir}/source</baseDirectoryPath>
	</configuration>
</plugin>

Michel Pawlak

unread,
Nov 11, 2016, 10:20:36 AM11/11/16
to SonarQube, jero...@gmail.com
As I wrote in my previous email, can you please check the content of your converted-coverage.xml (i.e. paths) ? Or better: create a simple project that reproduces the issue.

In your first message, you wrote "sources" but then in the other ones, you wrote "source", which one is the correct one ?

root
|-- module1
|    |-- sources

Try to set baseDirectoryPath to ${project.basedir}/source/ (i.e. add a trailing "/")

BTW, the issue you're facing is the one that was fixed in #28

jero...@gmail.com

unread,
Nov 11, 2016, 11:31:06 AM11/11/16
to SonarQube
hehe, it was due to the missing "/", damn !

And also, i had 0% coverage because of a surefire configuration in a parent parent ... pom.

Thanks, have a nice weekend ;)

Michel Pawlak

unread,
Nov 11, 2016, 11:37:15 AM11/11/16
to SonarQube, jero...@gmail.com
Glad to hear that you solved your issue.

I'll add a check to the mojo to detect this kind of misconfiguration.

Have a nice week end too.

Michel
Reply all
Reply to author
Forward
0 new messages