SonarRunner crashes due to Findbugs - ant

I am doing a Sonar analysis of my project on a Jenkins Server using SonarRunner within an ant build. Unfortunately, the Analysis crashes with the following lines:
[sonar:sonar] 11:29:57.008 INFO - Execute Findbugs 2.0.3...
[sonar:sonar] 11:29:58.217 DEBUG - Release semaphore on project : org.sonar.api.resources.Project#5c1f0a26[id=3998,key=<key>,qualifier=TRK], with key batch-<key-batch>
[sonar:sonar] 11:29:58.247 DEBUG - To prevent a memory leak, the JDBC Driver [com.mysql.jdbc.Driver] has been forcibly deregistered
BUILD FAILED
<Path>: The following error occurred while executing this line:
<Path>: org.sonar.runner.impl.RunnerException: Unable to execute Sonar
I have other projects running on the same server, which have no problem performing this analysis (and where the analysis is triggered exactly the same way). As you can see, I changed the log level to DEBUG, but, nevertheless, I get no stack trace and I am not able to find useful information in the logs of Jenkins or Sonar.
One other thing, I tried, was to increase the Heap space (with -Xmx) for this ant task in Jenkins but that didn't help either.
Are there any other settings I can take to get useful information or does somebody know about this problem?
Thanks!

Some more information could be useful. E.g.: what SonarQube and SonarRunner versions are you running.
Findbugs is one of the few analyzing plugins that need .class data for analyzing the project. So if you have not changed the directory within your build.xml the ant task may search within the default output folder location.
Please make sure your .class files are located here. To make them appear here you have to compile them before of course

Related

How to solve File can’t be indexed twice error in Run Code Analysis task TFS?

I am using SonarQube version 7.4 and TFS build task Run Code Analysis version 4
I am getting an error File can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
Below is my configuration for Prepare analysis on SonarQube task step
sonar.verbose=true
sonar.sources=(Build.SourcesDirectory)
sonar.inclusions=Code/**
sonar.cs.vstest.reportsPaths=**/*.trx
sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml
sonar.cfamily.build-wrapper-output=(Build.SourcesDirectory)
sonar.cfamily.threads=6
sonar.cfamily.cppunit.reportsPath=**/result.xml
sonar.branch.name=(Build.SourceBranchName) sonar.dependencyCheck.reportPath=(Build.ArtifactStagingDirectory)\dependency-check-report.xml
sonar.dependencyCheck.htmlReportPath=$(Build.ArtifactStagingDirectory)\dependency-check-report.html
Also below is my project folder structure
Client
Code
Lib
Package
Research
Runners
Tools
I want to scan only Code folder, Please help me.
How to solve File can’t be indexed twice error in Run Code Analysis task TFS?
According to your configuration for Prepare analysis on SonarQube task step, it seems that you have not configured the source and test files correctly.
Based on the FAQ on SonarOpenCommunity, we could to know:
Q: ERROR: Caused by: File [...] can't be indexed twice.
A: In case of below error you have to verify your exclusion/inclusion
properties. Please check that inclusion/exclusion patterns produce
disjoint sets for source and test files
So, to resolve this issue, we need to check the inclusion/exclusion patterns produce
disjoint sets for source and test files.
#Naveen Kumar`s solution:
Removed sonar.sources instaed added sonar.inclusions and sonar.exclusions resolved his issue.

Sonarqube Jenkins integration error, no analysis has been performed

I'm trying to integrate Sonar analysis into my Jenkins. I have set up a multi module configuration, and I think the analysis runs as it should, based on the jenkins build logs.
INFO: Analysis report generated in 234ms, dir size=774 KB
INFO: Analysis reports compressed in 94ms, zip size=199 KB
INFO: Analysis report uploaded in 74ms
INFO: ANALYSIS SUCCESSFUL, you can browse
http://localhost:9000/dashboard/index/perso
INFO: Note that you will be able to access the updated dashboard once the
server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?
id=AVwVnhRax2vtJSkdxag8
INFO: Task total time: 9.919 s
INFO: ---------------------------------------------------------------------
INFO: EXECUTION SUCCESS
But when I head over to the Sonar dashboard, all I get is this.
No analysis has been performed since creation. The only available section is the configuration.
I checked out the Sonar log, where it shows the error but sadly I couldn't solve the issue based on that.
Error: https://pastebin.com/N50RhBT3
The final cause was an SSL connection exception, but since both servers are running local, why would there be SSL?
Used versions: Sonar plugin 2.6.1, Sonarqube server 6.3.1, Sonarqube Scanner 3.0.3.778. , Jenkins 2.59
Thanks,
peter
Turns out this was basically a java not found error. Due to an annoying Jenkins bug, previously I had to reinstall Java. This change only partially went through sonarqube, and it caused the error above. The solution was pointing sonar to that java_home with the wrapper config file.

Sonar does not shows up Code Coverage after build successful with Jenkins Sonar plugin

I am trying to get code coverage with Sonar and Jenkins. I see Jenkins' Sonar plugin successfully executes JUnit test cases and completes build successfully. But Sonar does not show Code Coverage results (always shows 0.0% as the code coverage) on the project. But Sonar does show "Unit test success".
I am using Maven with Jenkins and Sonar.
I get the below message in Jenkins logs while executing the Sonar plugin:
Project coverage is set to 0% as no JaCoCo execution data has been dumped: .../sonar/target/jacoco.exec
Can any one help me how to get correct code coverage on any Sonar project.
Just because Sonar invoked Surefire correctly (and you received the "Unit test success" message) doesn't mean that JaCoCo instrumented your code.
Try executing JaCoCo directly. You might find out why JaCoCo is failing directly:
mvn jacoco:prepare-agent test jacoco:report
JaCoCo will place jacoco.exec as well as its XML/HTML reports within target/jacoco. Or it will fail, and hopefully you'll have a better idea as to why.
One very common problem is that the JaCoCo javaagent will not run if you've changed the Surefire argLine at all, because jacoco:prepare-agent just sets the argLine property which in this scenario, is conveniently ignored. You can set prepare-agent's propertyName property to something else (like jacocoArgLine) and include that in your argLine config:
<argLine>-Xmx1024m ${jacocoArgLine}</argLine>
I read https://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Unit+Tests+for+Java+Project and used cobertura as my code coverage plugin then I see code coverage displays for small projects. When I check for a big project in sonar I just see code coverage as - that means its empty. In logs I could find that Cobertura report was not found at /.../coverage.xml path.
coverage.xml was not generated due to OutOfMemeryError:heapspace. Since my project is such a big project when I set heap memory to 2GB and cobertura plugin memory to 1.5GB sonar gets code coverage displayed.
According to this blog post, you probably forget to set the sonar.binaries property in your project properties
Don’t forget sonar.binaries, otherwise, you might get something like « Project coverage is set to 0% since there is no directories with classes. » in your logs.
[...]
sonar.surefire.reportsPath=target/surefire-reports
sonar.jacoco.reportPath=target/jacoco.exec
sonar.binaries=target/classes
[...]
Your Sonar plug-in cannot find the report file generated by Jacoco.
In your pom(parent or child) look for the <destFile> tag under jacoco/prepare-agent execution. Change the name and the location to target/jacoco.exec and you are good to go!
Instead of using the Jenkins sonar plugin for running sonar, try to do it with maven, by executing the sonar goal. Usually this is easier then setting up an additional build step and tweaking all the paths till sonar finds all the relevant files.
In your case I guess it can read the junit/testng report, but can't find the jacoco results (jacoco.exec). Is the path sonar outputs(../sonar/target/jacoco.exec) correct?

Sonar displaying 0% Emma coverage report

I agree that this question is asked many a times by many people and many solutions are already been provided. However, after referring to umpteen links, not being able to display the Emma report in Sonar is driving me crazy. Below is a description of what I am trying to do.
My java project is a multi module maven project. We are using EMMA as the code coverage tool and Jenkins to build the project, Sonar to analyze the code and configured Sonar for our build job using the Jenkins sonar plugin. Up to this point, the story is great. The problem comes when I try to reuse the reports generated by Emma during Sonar analysis. There is no apparent error in the Sonar analysis logs during the build, however, in Sonar project dashboard the coverage report is 0%. Below is configuration data that I provide in the Sonar configuration section of my Jenkins build job.
-Dsonar.core.codeCoveragePlugin=emma
-Dsonar.emma.reportPath=/target
-Dsonar.dynamicAnalysis=reuseReports
-Dsonar.surefire.reportsPath=/target/surefire-reports
Sonar Version : 3.0
Emma plugin versions:
emma-maven-plugin : 1.0-alpha-2
Sonar Emma Plugin :1.0.1
emma : 2.0.5312
The Maven build generates the coverage.em files in the individual modules' target folder. No coverage.ec file is generated. Is it mandatory to have both coverage.ec and coverage.em files for Sonar?
The coverage.es,html,txt,xml files are generated in the project build directory/emma folder
The Sonar analysis logs for a module looks like below.
[INFO] [15:06:02.829] Sensor org.sonar.plugins.emma.EmmaSensor#bfc33...
[WARN] [15:06:02.844] Resource will be ignored in next Sonar versions, index is locked: com.mycompany.mypackage.tests.util.Activator
[INFO] [15:06:02.876] Sensor org.sonar.plugins.emma.EmmaSensor#bfc33 done: 47 ms
The above logs make me think that Sonar is indeed doing something with the generated Emma reports, but not displaying anything on the Sonar project dashboard.
Please let me know where I may be going wrong or what additional thing needs to be done to get this working.
I think this thread might me useful. http://sonar.15.n6.nabble.com/Receiving-quot-index-is-locked-quot-warning-when-Emma-sensor-runs-td4676490.html
It describes the same problem and gives you some workarounds

How do I make Jenkins, Sonar and the JaCoCo plugin work together for Eclipse Tycho Plugin Projects (or maybe Cobertura)?

my setup is:
Jenkins 1.448
Sonar 2.13
Jenkins Sonar Plugin 1.72
a MySql database for Sonar
I have the following project:
Eclipse Plugin Project
using Maven
multiple modules (parent maven project, source plugin project, test fragment project)
a simple JUnit test testing a class of the source plugin project
What the process is at the moment:
Jenkins checks out the parent project from SVN
Jenkins builds the project and its modules using Maven and Tycho
Jenkins uses Surefire to execute the tests and produce a report
Jenkins uses the Jenkins Sonar plugin to start mvn sonar:sonar to execute code analysis
Static code analysis is done on each module
JaCoCo fails
Sonar has static code analysis statistics available and test success percentage is shown.
The only thing that's missing is JaCoCo's code coverage...or maybe even Cobertura's code coverage.
I don't really care at this point, I just want one of these things to produce code coverage results.
Cobertura seems to be unable to produce results possibly because either
- it can't instrument the code
- it looks for the instrumented code at the wrong place
- it can't cope with Tycho or the separate source/test code setup
JaCoCo should be able to "watch" the code coverage on the fly, but its output is
[INFO] [17:44:04.708] Sensor JaCoCoSensor...
[INFO] [17:44:04.717] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/jobs/testPlugin/workspace/testSource/target/jacoco.exec
[INFO] [17:44:04.854] Sensor JaCoCoSensor done: 146 ms
[INFO] [17:44:10.587] Sensor JaCoCoSensor...
[INFO] [17:44:10.587] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/jobs/testPlugin/workspace/testTest/target/jacoco.exec
[INFO] [17:44:10.631] Sensor JaCoCoSensor done: 44 ms
[INFO] [17:44:12.402] Sensor JaCoCoSensor...
[INFO] [17:44:12.402] Project coverage is set to 0% as build output directory doesn't exists: /var/lib/jenkins/jobs/testPlugin/workspace/testParent/target/classes
[INFO] [17:44:12.402] Sensor JaCoCoSensor done: 0 ms
What am I doing wrong? Do I need to enable JaCoCo in my pom.xml somewhere? Do I need surefire? What do I need to do to use Cobertura?
I've found a page with an example tycho multi-module project (separate source and test projects). After copying some of the properties and configurations...
it seems that I now use a maven jacoco plugin to generate the jacoco code coverage report and then tell Sonar where to find the report and reuse it.
Why on earth is there next to no documentation for this? Or why is it so hard to find?
https://github.com/Godin/sonar-experiments/tree/master/jacoco-examples/tycho-example
You can have a look on the blog post I wrote few months ago : http://mdwhatever.free.fr/index.php/2011/09/quality-analysis-on-eclipse-plugins-with-tycho-sonar-jacoco-and-swtbot/
When the code is done being instrumented, surefire has to be ran on that specific code that the instrumentation generates. I've not used your setup, but your error seems very similar to what I got when I was getting Clover code coverage to work; I had to point surefire to run tests out of the directory that the compiled instrumented code was being stored in.
Also, I found specifying the -X option on the Maven command line to be invaluable as reading the logs of each plugin during a build shows you exactly where it's looking for whatever it's trying to find.
Edit:
Instrumented code will have to be compiled before surefire can run against it, so you'll want to point to the post-compilation directory and not the instrumented source itself.

Resources