I'm trying to feed sonar with emma results for a multimodule project
mvn sonar:sonar -Dsonar.dynamicAnalysis='true' -Dsonar.core.codeCoveragePlugin=emma -Dsonar.emma.reportPath=target
For each module I get:
instrumentation path processed in 1798 ms
[146 class(es) instrumented, 19 resource(s) copied]
metadata merged into [<module>/target/coverage.em] {in 152 ms}
and later:
[INFO] [12:24:32.514] Sensor EmmaSensor...
[INFO] [12:24:32.514] Parse reports: <module>/target
[WARN] [12:24:32.514] No coverage (*.ec) file found in <module>/target
[INFO] [12:24:35.123] Sensor EmmaSensor done: 2609 ms
So I get 0% coverage in sonar
Why is it trying to find .ec files instead of .em files?
Sonar version is: 3.5.1
Thanks
It would be nice if you mentioned the Sonar version you use.
However I think that the parameter sonar.dynamicAnalysis should have the value of 'reuseReports' and not 'true'
Also make sure that the em files are existing under the target folder
For more information see http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Unit+Tests+for+Java+Project
and
http://docs.codehaus.org/display/SONAR/Emma+Plugin
Related
I am using jenkins pipeline for my React project to with test, build and deploy steps.
I integrated sonarqube with my project. But sonar's jacoco doesn't assess my coverage report which is in generic coverage format(test-report.xml)
Is there a way to get my report as "jacocoTestReport.xml" in my React project without using maven or gradle. I couldn't find any document or 3rd party tools?
My related pipeline script:
sh '''
${scannerHome}/bin/sonar-scanner \
-Dsonar.projectKey=xxxxxxxxxxxxxx \
-Dsonar.sources=. \
-Dsonar.sources=. \
-Dsonar.coverage.jacoco.xmlReportPaths=test-report.xml \
-Dsonar.testExecutionReportPaths=test-report.xml \
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info \
-Dsonar.coverageReportPaths=test-report.xml \
-Dsonar.host.url=https://xxxxxxxxxxxxxx \
-Dsonar.login=xxxxxxxxxx
'''
The related error is like:
: Sensor Generic Coverage Report
INFO: Parsing /var/jenkins_home/workspace/**********/test-report.xml
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 36.948s
INFO: Final Memory: 49M/690M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
ERROR: Error during parsing of the generic coverage report '/var/jenkins_home/workspace/*******/test-report.xml'. Look at SonarQube documentation to know the expected XML format.
ERROR: Caused by: Unknown XML node, expected "coverage" but got "testExecutions" at line 2
I assume you are only building a react application, hence that it is just JavaScript/TypeScript and my answer is based on that assumption.
If that is the case you can simply ignore the sonar.coverage.jacoco.xmlReportPaths property. You are already providing that information via the lcov.info file. Sonarqube will be able to read the coverage information from this file.
Furthermore the test-report.xml normally only contains a list of the executed tests and their outcome. You will normally find no kind of coverage information in there. Therefore your build might also break on the sonar.coverageReportPaths property (my suggestion is also to remove that one).
I am currently using the sonarqube server 5.6 with scanner 2.6.1 and I keep getting errors during analysis for a java project.
It appears to complain about some java files not compiled in the binaries folder (there aren't any at all in the binaries folder).
Once I add the -X parameter I get more exceptions (flagged as ignored), see below.
any clues?
sonar-project.properties followed by logs
sonar.projectKey=myproj
sonar.projectName=myproj
sonar.projectVersion=1.1
sonar.branch=1.1
sonar.sources=./java
sonar.binaries=./deploy
sonar.log.level=DEBUG
sonar.verbose=false
sonar.sourceEncoding=UTF-8
INFO: Execute Checkstyle 6.12.1 done: 2365 ms
INFO: Sensor CheckstyleSensor (done) | time=2377ms
INFO: Sensor SCM Sensor (wrapped)
INFO: SCM provider for this project is: svn
INFO: 9 files to be analyzed
DEBUG: Working directory: D:\Apps\xxxx
DEBUG: Annotate file java/src/xxxx.java
DEBUG: Annotate file java/src/xxxx.java
DEBUG: Annotate file java/src/xxxx.java
DEBUG: Annotate file java/src/xxxx.java
DEBUG: Annotate file java/src/xxxx.java
DEBUG: Annotate file java/src/xxxx.java
DEBUG: Annotate file java/src/xxxx.java
DEBUG: Annotate file java/src/xxxx.java
DEBUG: Annotate file java/src/xxxx.java
INFO: 9/9 files analyzed
INFO: Sensor SCM Sensor (wrapped) (done) | time=3289ms
INFO: Sensor FindBugs Sensor (wrapped)
WARN: Findbugs needs sources to be compiled. Please build project before
executing sonar or check the location of compiled classes to make it possible for Findbugs to analyse your project.
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
execution without the -e param
WARN: Findbugs needs sources to be compiled. Please build project before executing sonar or check the location of compiled classes to make it possible for Findbto analyse your project.
then
java.lang.IllegalStateException: Can not execute Findbugs
Caused by: java.lang.IllegalStateException: This project contains Java source files that are not compiled.
at org.sonar.plugins.findbugs.FindbugsConfiguration.getFindbugsProject(FindbugsConfiguration.java:120)
at org.sonar.plugins.findbugs.FindbugsExecutor.execute(FindbugsExecutor.
with the -X parameter
com.puppycrawl.tools.checkstyle.api.CheckstyleException: missing key 'severity' in SuppressionCommentFilter
then multiple exceptions
DEBUG: Keep looking, ignoring exception
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to find class for com.puppycrawl.tools.checkstyle.checks.sizes.WhitespaceAroundCheck
then
WARN: Findbugs needs sources to be compiled. Please build project before executing sonar or check the location of compiled classes to make it possible for
then
INFO: EXECUTION FAILURE
It works for me after defining :
sonar.java.binaries=[YOUR_BUILD_DIR] (target/classes)
seen in :
https://github.com/SonarQubeCommunity/sonar-findbugs/issues/49
We had the same issue for some projects (mainly Play Framework projects). I reverted the FindBugs plugin in SonarQube from version 3.4.3 to 3.3 (that I used on SonarQube 5.5) and then the analysis worked again.
My working configuration for SonarQube 6.2 with Maven-Multi-Module project
Parent
-- Module1
-- Module2
sonar.projectKey=projectKey
sonar.projectName=Project Name
sonar.projectVersion=1.0
sonar.modules=Module1,Module2
sonar.sources=src
sonar.sourceEncoding=UTF-8
sonar.language=java
I used Jacoco eclipse plugin to measure unit test coverage and I was able to export a report using it. I want to integrate that report with sonar so I gave the path to it in the project properties file.
My properties file looks like this
# Required metadata
sonar.projectKey=key
sonar.projectName=name
sonar.projectVersion=1.0
sonar.jacoco.reportPath=jacoco.exec
sonar.tests=junit
sonar.dynamicAnalysis=reuseReports
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportMissing.force.zero=true
# Comma-separated paths to directories with sources (required)
sonar.sources=src
# Comma-separated paths to directories with tests (optional)
sonar.tests=test
# Encoding of the source files
sonar.sourceEncoding=UTF-8
# Language
sonar.language=java
When I executed sonar-runner the following lines were there in the console output
16:23:13.219 INFO - Sensor JaCoCoItSensor...
16:23:13.219 INFO - No JaCoCo analysis of project coverage can be done since there is no class files.
16:23:13.219 INFO - Sensor JaCoCoItSensor done: 0 ms
16:23:13.219 INFO - Sensor JaCoCoOverallSensor...
16:23:13.219 INFO - Sensor JaCoCoOverallSensor done: 0 ms
16:23:13.219 INFO - Sensor JaCoCoSensor...
16:23:13.219 INFO - No JaCoCo analysis of project coverage can be done since there is no class files.
Also the unit test coverage widget indicated "No Data".
Why am I not able to get Sonar to display the coverage results? What is the correct way to do this?
This is my first experience with Jacoco and I'm also new to Sonar, so detailed guides are very much appreciated.
You must specify "sonar.binaries" property that points to the folder where your classes are compiled.
Following Jenkins documentation jenkins docs
I can use the POM_VERSION environment variable to take the current version from the pom file.
But for some reason the POM_VERSION environment variable is not being refreshed from build to build. for example:
I changed the version number manually but the build number that exported was the last from the previous build.
From my python script:
print 'Current version is ' + os.environ['POM_VERSION']
which gives the following log Current version is 0.1.5 which is clearly wrong because i changed it. you can further see it in my maven versions goal output:
[INFO]
[INFO] --- versions-maven-plugin:2.1:set (default-cli) # ep-reporter ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /var/lib/jenkins/jobs/exchange-planner- reporter/workspace
[INFO] Processing com.exelate:ep-reporter
[INFO] Updating project com.company:ep-reporter
[INFO] from version 0.1.8 to 0.1.6
Props: {project.version=0.1.6, project.artifactId=ep-reporter, project.groupId=com.company}
note that it went from 0.1.5 because i have a script that advances it. but maven clearly states that its changing it from 0.1.8 to 0.1.6 which is not what POM_VERSION says
Thanks.
That environment variable is set at the time Jenkins first reads your POM file. You are clearly changing it during the build.
If you are changing it during the build, you know what you are changing to, and you should use the same mechanism to display it later.
I had the same problem and I resolved it by setting "Check-out Strategy" option to "Always checkout a fresh copy" in Source Code Management section.
I have a project that contains javascript files in src/main/webapp/js. In order to analyze these, I am executing the following:
mvn install org.codehaus.sonar:sonar-maven-plugin:3.5:sonar -Dsonar.branch=js -Dsonar.language=js -Dsonar.sources=src/main/webapp/js -Dsonar.login=sonar -Dsonar.password=sonar
I have also attempting this with: -Dsonar.importSources=true
When I execute this, I get a build success. However, when I look at the js project I created, it contains no data. When I look at the logs, I see this which leads me to believe that the sonar.sources property is not being read.
[INFO] [17:38:42.273] Base dir: /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace
[INFO] [17:38:42.273] Working dir: /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace/target/sonar
[INFO] [17:38:42.273] Source dirs: /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace/src/main/java, /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace/target/generated-sources/wsimport
[INFO] [17:38:42.273] Test dirs: /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace/src/test/java
[INFO] [17:38:42.273] Binary dirs: /home/mw-sandbox/.jenkins/jobs/ssi-wdf-re/workspace/target/classes
[INFO] [17:38:42.273] Source encoding: UTF-8, default locale: en_US
Can anyone suggest a solution for this?
For now, it is not possible to use properties such as "sonar.sources" when the analysis is triggered with Maven. See http://docs.codehaus.org/display/SONAR/Analysis+Parameters. But it should be soon. See http://jira.codehaus.org/browse/SONAR-4536.
So, you can work with Maven profiles to override source directories.
A work-around have been found in this post :
Empty metrics in sonar for web and javascript projects
It is a bit messy with the maven profiles, but I tried it, it does the job...