Quantcast

No code coverage in ant build

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

No code coverage in ant build

Bruce Li
Hi all,

I'm trying to integrate sonar in our project for the first time. Everything works fine except there is no code coverage results in report. Below is my ant target.

<!-- sonar target -->
<target name="sonar" depends="init">
<!-- list of mandatories Sonar properties -->
<property name="sonar.sources" value="src" />

<!-- list of optional Sonar properties -->
<property name="sonar.projectName" value="XmlParser" />
<property name="sonar.binaries" value="bin" />
<property name="sonar.tests" value="test" />
<property name="sonar.libraries" value="" />
<property name="sonar.surefire.reportsPath" value="${build}/reports/tests" />

<!-- The following properties are required to use JaCoCo: -->
<!-- 1. Tells Sonar to run the unit tests -->
<property name="sonar.dynamicAnalysis" value="true" />
<!-- 2. Tells Sonar which "tests" targets to run -->
<property name="sonar.jacoco.antTargets" value="run-tests" />
<!-- 3. Tells Sonar to use JaCoCo as the code coverage engine -->
<property name="sonar.core.codeCoveragePlugin" value="jacoco" />
<!--<property name="sonar.jacoco.reportPath" value="./target" />-->

<sonar:sonar key="XmlParser" version="1.0" xmlns:sonar="antlib:org.sonar.ant" />
</target>

Is there anything I miss? I can see the jacoco.exec file is generated every time I run sonar and the file is not empty.


Regards,
-- Bruce
__________________________________
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

David Racodon-2
Hi Bruce,

Have you installed and defined the Sonar Ant Task?:
  <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonar-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="path/to/sonar/ant/task/lib" />
</taskdef>

If so could you copy the definition of the Sonar Ant Task in your reply?

Thank you

Regards,

David RACODON | SonarSource
Senior Consultant



On 13 July 2012 11:21, Bruce Li <[hidden email]> wrote:
Hi all,

I'm trying to integrate sonar in our project for the first time. Everything works fine except there is no code coverage results in report. Below is my ant target.

<!-- sonar target -->
<target name="sonar" depends="init">
<!-- list of mandatories Sonar properties -->
<property name="sonar.sources" value="src" />

<!-- list of optional Sonar properties -->
<property name="sonar.projectName" value="XmlParser" />
<property name="sonar.binaries" value="bin" />
<property name="sonar.tests" value="test" />
<property name="sonar.libraries" value="" />
<property name="sonar.surefire.reportsPath" value="${build}/reports/tests" />

<!-- The following properties are required to use JaCoCo: -->
<!-- 1. Tells Sonar to run the unit tests -->
<property name="sonar.dynamicAnalysis" value="true" />
<!-- 2. Tells Sonar which "tests" targets to run -->
<property name="sonar.jacoco.antTargets" value="run-tests" />
<!-- 3. Tells Sonar to use JaCoCo as the code coverage engine -->
<property name="sonar.core.codeCoveragePlugin" value="jacoco" />
<!--<property name="sonar.jacoco.reportPath" value="./target" />-->

<sonar:sonar key="XmlParser" version="1.0" xmlns:sonar="antlib:org.sonar.ant" />
</target>

Is there anything I miss? I can see the jacoco.exec file is generated every time I run sonar and the file is not empty.


Regards,
-- Bruce
__________________________________

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

Bruce Li
I have put the jar in my ant lib directory so I simple define the task as below:

        <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        </taskdef>

Is this correct or not?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

David Racodon-2
HI Bruce,

It seems correct.
To make sure, have you tried to define the path to the Sonar Ant Task? Do you confirm that, as well, it does not work?

Could you send the log?
Could you sent you complete build.xml file?
Which versions of Sonar, Ant Task and Ant are you using?

Thank you

Regards,

David RACODON | SonarSource
Senior Consultant



On 17 July 2012 04:19, Bruce Li <[hidden email]> wrote:
I have put the jar in my ant lib directory so I simple define the task as
below:

        <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        </taskdef>

Is this correct or not?

--
View this message in context: http://sonar.15.n6.nabble.com/No-code-coverage-in-ant-build-tp5000869p5000965.html
Sent from the Sonar user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

MaxBernhardt
Hi David,

since there was no answer for a couple of weeks, I'd like to add some info from our setup.

We can reproduce the issue here. I've attached a fairly simple example based on Sonar 3.1.1 and Sonar-Ant-Task 1.4. If the attachment is broken, it might be due to the fact, that I respond via nabble. Please let me know, in that case I'll upload it again via my mail provider.sonar-ex3.zip

I think there are a few issues here:

1) The example from ut-ant-jacoco-runTests will have the same result as stated by Bruce. At least in the example we need to specifiy sonar.jacoco.reportPath, if we don't do that, the coverage will go down to 0%.

2) Once we specify sonar.jacoco.reportPath, we get coverage (for this example: 85.7%), but a click on the coverage link, shows only coverage for the first directory (one.client) the other directories (one.common, one.server) are not shown. I think this is the same issue as http://jira.codehaus.org/browse/SONARPLUGINS-1431, which is flagged as critical.

3) There is a difference between the coverage shown in the overview (85.7%) and the coverage for the one.client directory (75%). I think the coverage on the overview page is the correct value for all three directories, as the coverage for the single class in the one.client directory is 75%and I'm fairly certain, that the coverage for the other two directories is 100%, so that could explain the 85.7% shown in the overview.

Cheers
Max

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

David Racodon-2
Hi Max,

The 'sonar.jacoco.reportPath' should not be set if you want to let Sonar launch JaCoCo and compute the code coverage.

So, first, we should understand why this ut-ant-jacoco-runTests example does not work on your side.
Could you please send this complete project sample you're running on your server (keeping the changes you've made)?

Which version of Ant are you using?

Regards,

David RACODON | SonarSource
Senior Consultant



On 15 August 2012 12:30, MaxBernhardt <[hidden email]> wrote:
Hi David,

since there was no answer for a couple of weeks, I'd like to add some info
from our setup.

We can reproduce the issue here. I've attached a fairly simple example based
on Sonar 3.1.1 and Sonar-Ant-Task 1.4. If the attachment is broken, it might
be due to the fact, that I respond via nabble. Please let me know, in that
case I'll upload it again via my mail provider.
http://sonar.15.n6.nabble.com/file/n5001979/sonar-ex3.zip sonar-ex3.zip

I think there are a few issues here:

1) The example from ut-ant-jacoco-runTests will have the same result as
stated by Bruce. At least in the example we need to specifiy
sonar.jacoco.reportPath, if we don't do that, the coverage will go down to
0%.

2) Once we specify sonar.jacoco.reportPath, we get coverage (for this
example: 85.7%), but a click on the coverage link, shows only coverage for
the first directory (one.client) the other directories (one.common,
one.server) are not shown. I think this is the same issue as
http://jira.codehaus.org/browse/SONARPLUGINS-1431
http://jira.codehaus.org/browse/SONARPLUGINS-1431 , which is flagged as
critical.

3) There is a difference between the coverage shown in the overview (85.7%)
and the coverage for the one.client directory (75%). I think the coverage on
the overview page is the correct value for all three directories, as the
coverage for the single class in the one.client directory is 75%and I'm
fairly certain, that the coverage for the other two directories is 100%, so
that could explain the 85.7% shown in the overview.

Cheers
Max





--
View this message in context: http://sonar.15.n6.nabble.com/No-code-coverage-in-ant-build-tp5000869p5001979.html
Sent from the Sonar user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

MaxBernhardt
Hi David,

sorry for the delay, I haven't had access to my machine for the last couple of days.

That ut-ant-jacoco-runTests won't run on our env, was a rash assumption, as the attached simple example sonar-ex3 had the described problem, but I was wrong here, a clean checkout of ut-ant-jacoco-runTests works fine. So I checked for the difference between ut-ant-jacoco-runTests and my simple example sonar-ex3 and found one important difference. The location of build-, source- and testfiles relative to each other is quite different between the two setups.

In the setup of ut-ant-jacoco-runTests the source and test folders are located in the same directory as the buildfile. The JaCoCo sensor creates a subdirectory named "target" parallel to the test directory, where it places the execution report. That report is then found by sonar(-ant task) and the results are reported to the sonar server.

I our setup, the three locations (build-,source-and testfiles) all have their own directory trees. Again the JaCoCo agent creates a new directory "target" adjacent to the (first ? ... maybe this explains the second point of my mail) test directory and places its execution report there. This location is now no subdirectory to the path of the main buildfile. And the report doesn't seem to be found by sonar(-ant task). Once we define the location of the execution report, by setting sonar.jacoco.reportPath, the execution report is placed there and can be found.

Sorry I was a little bit rash in assuming ut-ant-jacoco-runTests would fail in the same way, it does not.

Cheers
Max

PS: we're using either Apache Ant(TM) version 1.8.2 compiled on December 3 2011 or Apache Ant version 1.7.1 compiled on September 3 2011 depending on our buildserver.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

David Racodon-2
Hi Max,

The following modifications will fix your issue:
  1. build.junit.xml, line 30: <junit dir="${build.basedir}/one.test/src" => <junit dir="${basedir}"
  2. build.sonar.xml, line 20: remove this line <property name="sonar.jacoco.reportPath" value="${jacoco.result.path}/jacoco.exec" />
Regards,

David RACODON | SonarSource
Senior Consultant



On 20 August 2012 15:41, MaxBernhardt <[hidden email]> wrote:
Hi David,

sorry for the delay, I haven't had access to my machine for the last couple
of days.

That ut-ant-jacoco-runTests won't run on our env, was a rash assumption, as
the attached simple example sonar-ex3 had the described problem, but I was
wrong here, a clean checkout of ut-ant-jacoco-runTests works fine. So I
checked for the difference between ut-ant-jacoco-runTests and my simple
example sonar-ex3 and found one important difference. The location of
build-, source- and testfiles relative to each other is quite different
between the two setups.

In the setup of ut-ant-jacoco-runTests the source and test folders are
located in the same directory as the buildfile. The JaCoCo sensor creates a
subdirectory named "target" parallel to the test directory, where it places
the execution report. That report is then found by sonar(-ant task) and the
results are reported to the sonar server.

I our setup, the three locations (build-,source-and testfiles) all have
their own directory trees. Again the JaCoCo agent creates a new directory
"target" adjacent to the (first ? ... maybe this explains the second point
of my mail) test directory and places its execution report there. This
location is now no subdirectory to the path of the main buildfile. And the
report doesn't seem to be found by sonar(-ant task). Once we define the
location of the execution report, by setting sonar.jacoco.reportPath, the
execution report is placed there and can be found.

Sorry I was a little bit rash in assuming ut-ant-jacoco-runTests would fail
in the same way, it does not.

Cheers
Max

PS: we're using either Apache Ant(TM) version 1.8.2 compiled on December 3
2011 or Apache Ant version 1.7.1 compiled on September 3 2011 depending on
our buildserver.






--
View this message in context: http://sonar.15.n6.nabble.com/No-code-coverage-in-ant-build-tp5000869p5002087.html
Sent from the Sonar user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

MaxBernhardt
Hi David,

Thanks a lot for the proposed changes ! I applied the changes and they fix the first issue, i.e. the target directory is now created in the base directory and the results are found just fine.

But that leaves the other two issues open.
 - coverage is only shown for the first of three directories (one.client is covered, one.common and one.server are not)
 - coverage values are unclear (85.7% for the whole project, 75% for one.client)

Can you reproduce any of those issues, or have I made another stupid error ?

Cheers
Max
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

David Racodon-2
Hi Max,

 - coverage is only shown for the first of three directories (one.client is
covered, one.common and one.server are not)

Watch out. At project level, when you click on the code coverage percentage, Sonar will only show you the worst values for the metric. As one.common has 100% code coverage, it won't be displayed. But if you go to its dashboard through the Components item in the left menu, you will see that one.common is covered at 100%.

Regarding one.server, indeed, there is an issue. It comes from the fact that only the first element of the sonar.binaries property is taken into account. Same cause that leads to your issue with FindBugs: http://jira.codehaus.org/browse/SONARPLUGINS-2155. This issue depends on http://jira.codehaus.org/browse/SONARPLUGINS-2155 that must be fixed in Sonar.

As a workaround, in build.sonar.xml, replace your code regarding sonar.binaries by:

    <property name="sonar.binaries" value="${build.bin.path}" />


Regards,

David RACODON | SonarSource
Senior Consultant



On 20 August 2012 18:24, MaxBernhardt <[hidden email]> wrote:
Hi David,

Thanks a lot for the proposed changes ! I applied the changes and they fix
the first issue, i.e. the target directory is now created in the base
directory and the results are found just fine.

But that leaves the other two issues open.
 - coverage is only shown for the first of three directories (one.client is
covered, one.common and one.server are not)
 - coverage values are unclear (85.7% for the whole project, 75% for
one.client)

Can you reproduce any of those issues, or have I made another stupid error ?

Cheers
Max



--
View this message in context: http://sonar.15.n6.nabble.com/No-code-coverage-in-ant-build-tp5000869p5002096.html
Sent from the Sonar user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

MaxBernhardt
Hi David,

changing the sonar.binaries property worked just fine. Thank you! Now the displayed coverage values also are just as I expect them.

Some of my expectations were based on the assumption, that sonar would show a complete coverage report on project level instead of showing just the "lowlights". This is not configurable, I assume ?

Cheers
Max
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No code coverage in ant build

David Racodon-2
Hi Max,

Some of my expectations were based on the assumption, that sonar would show
a complete coverage report on project level instead of showing just the
"lowlights". This is not configurable, I assume ?

No, it's not because it is against the Sonar 'philosophy':
  • The objective of drilldowns is to hunt for bad practices, so only worst values are displayed.
  • To display all values, you need to use filters.

Regards,

David RACODON | SonarSource
Senior Consultant



On 22 August 2012 14:32, MaxBernhardt <[hidden email]> wrote:
Hi David,

changing the sonar.binaries property worked just fine. Thank you! Now the
displayed coverage values also are just as I expect them.

Some of my expectations were based on the assumption, that sonar would show
a complete coverage report on project level instead of showing just the
"lowlights". This is not configurable, I assume ?

Cheers
Max



--
View this message in context: http://sonar.15.n6.nabble.com/No-code-coverage-in-ant-build-tp5000869p5002177.html
Sent from the Sonar user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Loading...