How to solve File can’t be indexed twice error in Run Code Analysis task TFS? - 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.

Related

Sonar Scanner coverage empty and test file analysis

Some context
I am trying to configure the plugin 'Sonar Scanner' in our Jenkins, the trigger and the project validation is "working", I added the " " because it is actually validating everything, even the test files and it is not checking the coverage.
Things you should know before
I have no access to Jenkins machine
I have no access to SonarQube machine
All plugins installed from Jenkins are the most recent versions
My Config
My project folder structure looks like this (Java project):
.git
.scannerwork
bl
commons
datafeed
keyfiles
persistence
post-aggregator
project-setup
webapp
webapp-server
.gitignore
pom.xml
My Sonar Scanner config is:
#required metadata
sonar.projectKey=inventory
sonar.projectName=Inventory1
sonar.language=java
sonar.sourceEncoding=UTF-8
#sonar.tests=**/.*Test.java
sonar.exclusions=**/*Dto*, **/*Entity*
sonar.binaries=build/classes
sonar.java.binaries=/data/application/jenkins/jenkins/workspace/$JOB_NAME
#Adding more info to the log
sonar.verbose=true
#Path to source directory
sonar.sources=/data/application/jenkins/jenkins/workspace/$JOB_NAME
The problems
Test coverage is 0
Checking the report I see that the current Scanner config checks everything, even the tests
So.. the questions are:
My test files are spread all around in the project, how can (or if it is even possible) to add a regex to the "sonar.tests"? i have been trying to do it but no success, all my tests ends with Test.java
How can I avoid properly Sonar to scan the test files.
Do I need jacoco as well in order to make this work or its possible to do it without it? (we are configuring the jacoco-maven in the project)
Thank you for your time!

How to check the pmd results in Jenkins?

Have a Java project and just automated it's build process using Jenkins Here is my console output of Jenkin console
18:50:22 Started by user suresh
18:50:22 Building in workspace C:\Program Files (x86)\Jenkins\workspace\pmdtest
18:50:23 [PMD] Collecting PMD analysis files...
18:50:23 [PMD] Finding all files that match the pattern **/pmd.xml
18:50:23 [PMD] Computing warning deltas based on reference build #6
18:50:23 Finished: SUCCESS
I can see that there are messages related to PMD.
May be I need to give something in the below configuration ? above output is when the below box (in image) is empty. Want to PMD all the js files. So tried
However, I do not know how to check the generated report? Is there any location that I have to go and check the results ?
What exactly needs to give there? May be that solves the other problem ?
The Jenkins PMD Plugin doesn't do any analysis, this must be done by the maven pmd plugin. The Jenkins plugin can just display the results.
Try to add the goal pmd:pmd to your maven command, this will generate a result file target/pmd.xml which you need to add to the config (PMD results).

SonarRunner crashes due to Findbugs

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

is sonar multi-module broken?

trying to make a multi module project I dowloaded the samples in github: I use this folder
https://github.com/SonarSource/sonar-examples/tree/master/projects/multi-module/sonar-runner/java-sonar-runner-modules-own-configuration-file as a project base dir
In a command line in this folder, I type /opt/sonar-runner/bin/sonnar-runner
First thing I find is that sonar-project.properties has a property named sonar.sources=src, but executing throws
Exception in thread "main" org.sonar.runner.RunnerException: You must define mandatory properties: sources
Then I correct this property with sources=src and runner execution finish, adds the project to my sonar server, but no code, modules or file is detected. It is like if all project is empty.
It is exactly the same with other examples and with my own project. No matter if is java, python...
Any help is welcome
You are using an old version of Sonar Runner and/or Sonar. Please update to the latest versions (Sonar Runner 2.2 and Sonar 3.5.1).

Using Gallio with OpenCover coverage-report file contais result but Sonar reports 0%

I have the problem that the code coverage for some reason aren't presented in Sonar.
The result of the unit tests is performed and showed correctly but not the result of the code coverage. The project is build by Jenkins. I have registered the opencover.profiler.dll file as suggested in some threads but still I get no result. Neither I get any error messages in Jenkins when performing the build.
I would be most grateful for any tips on what to do.
Best regards Dan
I think this happens because your Jenkins service is running as "Local System account", but Sonar is running OpenCover with the -register:user switch under the hoods. You should be able to bypass this either by running the Jenkins service as a regular user account, or patch the Sonar-runner to omit the -register:user switch.
It turned out however that the PDB-files caused the problems. They were included in the repository and were for some reason not recreated by the build in Jenkins. The PDB-files therefor contained the wrong path to the actual code files.
Thanks for the help!
Check for version conflicts between OpenCover and the Gallio plugin.
I found that the later versions of OPenCover (starting with Version 4.0.1229) inserted a new tag in the coverage-report.xml file - which the Gallio plugin could not understand. When I rolled back to an older version of OpenCover (4.0.804) the coverage worked again.
You can find more details on http://sonar.15.n6.nabble.com/coverage-report-xml-is-generated-but-sonar-says-coverage-is-0-td5008850.html
It looks like the Gallio plug-in has been updated, but I haven't pursued that yet (wanted to first confirm that this was the cause of the problem).

Resources