1
votes

I am trying to generate code coverage for webapp for manual testing using jacoco and sonar.

I am able to generate jacoco.exec file by modifying the catalina.bat in following way:

SET JACOCO=-javaagent:\jacoco-0.7.5.201505241946\lib\jacocoagent.jar=destfile=C:\jacoco.exec,append=true,includes=* set JAVA_OPTS=%JAVA_OPTS% %JACOCO% I then copy the jacoco.exec file to a target folder inside sonarcube and run ant sonar. The build.xml has following entries:

    <!-- The following properties are required to use JaCoCo: -->
<property name="sonar.dynamicAnalysis" value="reuseReports" />
<property name="sonar.java.coveragePlugin" value="jacoco" />
<property name="sonar.jacoco.reportPath" value="target/jacoco.exec" />

<!-- Define the SonarQube target -->
<target name="sonar">

    <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="../apache-ant-1.9.6/lib/sonar-ant-task-2.3.jar"/>
    </taskdef> 
        <!-- Execute the SonarQube analysis -->
        <sonar:sonar/>

</target>

</project>

The output I get from ant if following. I don't see any coverage in the report at the url http://localhost:9000/dashboard/index/org.codehaus.sonar:example-java-ant

Am I missing something?

c:\sonarqube>ant sonar
Buildfile: c:\sonarqube\build.xml

sonar:
[sonar:sonar] Apache Ant(TM) version 1.9.6 compiled on June 29 2015
[sonar:sonar] SonarQube Ant Task version: 2.3
[sonar:sonar] Loaded from: file:/C:/apache-ant-1.9.6/lib/sonar-ant-task-2.3.jar
[sonar:sonar] INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
[sonar:sonar] INFO: Work directory: c:\sonarqube\.sonar
[sonar:sonar] INFO: SonarQube Server 5.2
[sonar:sonar] 17:18:52.370 INFO  - Load global repositories
[sonar:sonar] 17:18:52.959 INFO  - Load global repositories (done) | time=588ms
[sonar:sonar] 17:18:53.034 INFO  - User cache: C:\Users\Administrator\.sonar\cache
[sonar:sonar] 17:18:53.932 INFO  - Load plugins index
[sonar:sonar] 17:18:53.952 INFO  - Load plugins index (done) | time=20ms
[sonar:sonar] 17:18:54.677 INFO  - Process project properties
[sonar:sonar] 17:18:57.381 INFO  - Load project repositories
[sonar:sonar] 17:18:57.493 INFO  - Load project repositories (done) | time=112ms
[sonar:sonar] 17:18:57.535 INFO  - Apply project exclusions
[sonar:sonar] 17:18:57.667 INFO  - Load quality profiles
[sonar:sonar] 17:18:57.983 INFO  - Load quality profiles (done) | time=315ms
[sonar:sonar] 17:18:58.039 INFO  - Load active rules
[sonar:sonar] 17:19:00.610 INFO  - Load active rules (done) | time=2571ms
[sonar:sonar] 17:19:00.636 WARN  - 'sonar.dynamicAnalysis' is deprecated since version 4.3 and should no longer be used.
[sonar:sonar] 17:19:00.797 WARN  - SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.
scm.provider to define SCM of your project.
[sonar:sonar] 17:19:00.800 INFO  - Publish mode
[sonar:sonar] 17:19:00.805 INFO  - -------------  Scan Simple Java Project analyzed with the SonarQube Ant Task
[sonar:sonar] 17:19:01.844 INFO  - Language is forced to java
[sonar:sonar] 17:19:01.887 INFO  - Load server rules
[sonar:sonar] 17:19:02.373 INFO  - Load server rules (done) | time=486ms
[sonar:sonar] 17:19:02.755 INFO  - Base dir: c:\sonarqube
[sonar:sonar] 17:19:02.756 INFO  - Working dir: c:\sonarqube\.sonar
[sonar:sonar] 17:19:02.781 INFO  - Source paths: src
[sonar:sonar] 17:19:02.786 INFO  - Source encoding: windows-1252, default locale: en_US
[sonar:sonar] 17:19:02.787 INFO  - Index files
[sonar:sonar] 17:19:02.854 INFO  - 0 files indexed
[sonar:sonar] 17:19:02.857 INFO  - Quality profile for java: Sonar way
[sonar:sonar] 17:19:02.999 INFO  - Sensor Lines Sensor
[sonar:sonar] 17:19:03.005 INFO  - Sensor Lines Sensor (done) | time=6ms
[sonar:sonar] 17:19:03.006 INFO  - Sensor QProfileSensor
[sonar:sonar] 17:19:03.095 INFO  - Sensor QProfileSensor (done) | time=89ms
[sonar:sonar] 17:19:03.096 INFO  - Sensor SCM Sensor
[sonar:sonar] 17:19:03.097 INFO  - No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
[sonar:sonar] 17:19:03.100 INFO  - Sensor SCM Sensor (done) | time=4ms
[sonar:sonar] 17:19:03.100 INFO  - Sensor Code Colorizer Sensor
[sonar:sonar] 17:19:03.106 INFO  - Sensor Code Colorizer Sensor (done) | time=6ms
[sonar:sonar] 17:19:03.107 INFO  - Sensor CPD Sensor
[sonar:sonar] 17:19:03.108 INFO  - JavaCpdEngine is used for java
[sonar:sonar] 17:19:03.110 INFO  - Sensor CPD Sensor (done) | time=3ms
[sonar:sonar] 17:19:03.304 INFO  - Analysis reports generated in 192ms, dir size=5 KB
[sonar:sonar] 17:19:03.320 INFO  - Analysis reports compressed in 15ms, zip size=2 KB
[sonar:sonar] 17:19:03.758 INFO  - Analysis reports sent to server in 424ms
[sonar:sonar] 17:19:03.762 INFO  - ANALYSIS SUCCESSFUL, you can browse 
1

1 Answers

0
votes

Looking at log of analysis we cannot see any JaCoCo sensor executed. JaCoCo sensor is executed only if you have java file in your analysis which you don't as you can see per 0 files indexed line in your log.

To explain this behaviour you have to understand that JaCoCo sensor will only report coverage on files indexed so if there are no java files, there is no point to execute it.

So to report and compute coverage you would have to import a coverage report related to some source files you analyze in your project.