Unit test code analysis using "sonar.*" property and maven-sonar-plugin - sonarqube

I'm trying to do code analysis of Java unit test using maven sonar plugin. But the plugin doesn't seem to take into account my sonar properties "sonar.*". I've tried to modify simple examples and it did work either. According to MSONAR-70, the issue has been fixed and I'm using the version 2.4.
For the test, I've tried it on a simple case:
Clone sonar-examples.git
use the project sonar-examples/projects/languages/java/maven/java-maven-simple as example
Renamed src/main to src/test
In the pom.xml, add to the properties section :
<sonar.sources>src/test/java</sonar.sources>
<sonar.binaries>target/test-classes</sonar.binaries>
Run mvn sonar:sonar.
--> the code analysis didn't took into account my settings. The project is created on SonarQube but code as not been analyzed.
If I use the sonar-runner command line, it's analyzing the code:
sonar-runner [...] -Dsonar.sources=src/test/java
-Dsonar.binaries=target/test-classes
-Dsonar.language=java
-Dsonar.sourceEncoding=UTF-8
-Dsonar.projectKey=org.codehaus.sonar:example-java-maven
-Dsonar.projectName="Simple Java Maven Project"
-Dsonar.projectVersion=1.0-SNAPSHOT

According to a previous revision of the question, the OP solved their problem like this:
We were using SonarQube 4.0 version. Updating the version to 4.4, made the properties be taken into account.
That was in 2014; the current version now is 5.5.
The steps to upgrade can be found here:
Stop the old SonarQube server
Download and unzip the new SonarQube distribution in a fresh directory, let's say NEW_SONARQUBE_HOME.
Start it using the default H2 database and use the update center to install the plugins you need.
Manually install any custom plugins.
Stop the new server.
Update the content of the sonar.properties and wrapper.conf files located in the NEW_SONARQUBE_HOME/conf directory with the content of the related files in the OLD_SONARQUBE_HOME/conf directory (web server URL, database settings, etc.). Do not copy-paste the old files.
If a custom JDBC driver is used, copy it into NEW_SONARQUBE_HOME/extensions/jdbc-driver/.
Back up your database.
Remove the data/es directory.
Start the new web server
Browse to http://localhost:9000/setup (replace "localhost:9000" with your own URL) and follow the setup instructions.

Related

Build/Run Elasticsearch Locally with plugins

(On Elasticsearch version 6.5.1)
How can I build/run Elasticsearch from source with local plugins?
I've tried the following command to install the plugins:
./distribution/build/cluster/run\ node0/elasticsear-6.5.1-SNAPSHOT/bin/elasticsearch-plugin install file:/<path_to_plugin_zip> and that says it successfully installed the plugin.
However, when I run elasticsearch via ./gradlew run --debug-jvm, it cleans out the contents of that directory before running ES.
The reason I installed the plugin into that particular directory is that I put a debugger in the PluginsService.java file, and saw that the Path pluginsDirectory parameter in the constructor was set to /Users/jreback/Desktop/elasticsearch/distribution/build/cluster/run node0/elasticsearch-6.5.1-SNAPSHOT/plugins.
So, how can I get my plugin installed on my local ES version and run ES such that the plugin code doesn't get removed as the process starts up? Many thanks in advance!
FWIW, I got this working with some manual code changes (there may be or likely is a more recommended way to do this, but this worked for me).
In my ES checkout, I made the following code change to server/src/main/java/org/elasticsearch/env/Environment.java:
replace this line: pluginsFile = homeFile.resolve("plugins"); with pluginsFile = Paths.get("<path to plugin directory");
(Also, you must import java.nio.file.Paths at the top of that file).
The directory structure for the directory you listed above should look like this:
- plugin parent directory (should whatever you put in the Environment.java file)
- plugin directory (name of the plugin)
- plugin-descriptor.properties file
- plugin jar file (generated from building the plugin in some prior step)
Then you should see that it loaded the plugin you've just added in the logs when you start up ES again.

Sonarqube: You must install a plugin that supports the language 'css'

I have installed Sonarqube 6.7.5 with several plugins, including the Sonar CSS plugin version 1.0.2.611. I ran a scan locally with "publish" mode and everything was good. But then when I ran a scan as part of a Team City job that ran with "preview" mode, I got this failure:
You must install a plugin that supports the language 'css'
I have my 6.7.5 version of Sonarqube running, and when I run a build using the new Sonarqube server, I get that message about the "css" language. None of the Team City build parameters are changing other than the mode--it works when I run in "publish" mode and it gives that error when I run in "preview" mode. My Team City builds use the Gradle sonar scanner (2.6.2).
I believe I haven't spelled the language name incorrectly. The Sonarqube server shows CSS listed under Quality Profiles, with a default profile set:
And it shows under the Quality Profile I am using for this project:
Here's the section from my Gradle build file:
sonarModules {
module {
name "CSS"
property "sonar.language", "css"
property "sonar.projectBaseDir", "."
property "sonar.sources", "jcr_root/etc/designs"
}
}
What could be causing this issue when I run it via the Team City build?
I never did totally figure it out, but here's how I resolved this:
The CSS plugin I had been using was the one listed on the Sonarqube plugins list: SonarCSS version 1.0.2.611
I removed this plugin and instead installed a different CSS plugin, the Sonar-css plugin from https://github.com/racodond/sonar-css-plugin/releases (version 4.18)
This different plugin works for me, both for Publish mode and Preview mode. I presume there is some issue with the module configuration in Preview mode with the plugin that the docs.sonarqube.org site uses. Maybe this will help someone else!

Configure Multiple SonarQube Instances in a Gradle Build

In our CI environment, we currently have one build server (based on Atlassian Bamboo) and two SonarQube instances (versions 6.0 and 6.5). Initially, our CI server was configured to communicate with the 6.0 SonarQube instance. This has been configured in the /home/bamboo/.gradle/gradle.properties file on our CI server like this:
systemProp.sonar.host.url=<http url of SonarQube 6.0 instance>
systemProp.sonar.login=<username here>
systemProp.sonar.password=<password here>
Now we have another Gradle-based project running on our CI server which shall talk to the new SonarQube 6.5 instance. I tried configuring this but failed all the time.
Things I have done so far:
Added commandline arguments to gradle wrapper command:
I have tried adding -Dsonar.host.url=, -Dsonar.login=, -Dsonar.password= to the Gradle command. As this didn't seem to work, I have also tried to set commandline arguments as SonarQube system properties using -DsystemProp.sonar.host.url=, -DsystemProp.sonar.login=, -DsystemProp.sonar.password=. This didn't work either.
Added properties to the build.gradle file
- Added properties to the build.gradle file like this:
sonarqube {
properties {
property "sonar.host.url", "<http url of SonarQube 6.0 instance>"
property "sonar.login", "<username here>"
property "sonar.password", "<password here>"
...<other SonarQube analysis settings here>...
}
}
In all cases, the CI server talked to the wrong SonarQube instance (6.0). My question is, whether it is possible to configure a single project to talk to another SonarQube instance. As you have seen, we use Gradle 3.2.1 as a build tool. And we are using the org.sonarqube Gradle plugin too.
Thank you for any help.
André
Your first try did not work, because you set the system properties from the commandline, but setting it from the project properties later on resets the system properties to the configured values.
Your second try did not work, because the systemProp.sonar.login syntax is only suppored in gradle.properties files, not via -P commandline project properties.
Your third try did not work because the SonarQube scanner prefers the system property values over the value configured via the DSL, so that one can change what is configured in the build script with the help of local configuration.
You need to set the system properties in your build script manually, this then overwrite what was automatically set from the project property. Using the project gradle.properties file does not work as the user file overwrite the project file. So you need something like System.properties.'sonar.login' = '...' in your build script. You can either hard-code it there, or then use project properties that you can set in your gradle.properties file or via -P parameters.
Besides that, I'd never depend on having any configuration in Gradle User dir on a build server. Most buildservers use build agents that might run on distributed machines, so you would always have to make sure that all build agents are configured the same and so on. I'd always configure in the build setup of the build server the according configuration, either by setting system properties, or environment properties or commandline arguments.
Just my 2ct.

How to get the sonar-report.json file created with sonarqube?

I am runnig Sonarqube 5.3 and has integrated it with Jenkins. I want to post Sonareqube issues as Gerrit comments.
Then I need to specify the path to and name of the data generated from sonarqube, e.g. build/sonar/sonar-report.json
The file sonar-report.json is not generated and I have found some setting for Sonarqube that shouold make sonareqube create the file.
sonar.report.export.path=sonar-report.json
sonar.issuesReport.html.enable=true
sonar.issuesReport.json.enable=true
sonar.issuesReport.console.enable=true
I have tried to set these in the file
<sonar-installation-directory>/conf/sonar.properties
I have restarted the Sonare service and restarted the computer but the sonar-report.json file is still not created.
Those properties are not meant to be configured on the server side, they are passed on the scanner side, and are valid only for analysis in preview mode (by the way no need for sonar.issuesReport.json.enable). That's what SonarLint for Command Line is about.
Why preview mode ? Because the goal is to analyse a diff (to comment the code review in your case). You don't want a full analysis to be submitted to SonarQube if the code is not yet pushed to the repo.
Example:
$ sonar-runner -Dsonar.analysis.mode=preview -Dsonar.issuesReport.html.enable=true -Dsonar.report.export.path=report.json -Dsonar.host.url=http://localhost:9000
[...]
$ ls .sonar/
issues-report report.json
(careful with the JSON report, looks like it will ultimately be removed, see SONAR-7247)
P.S.: I guess you might be using the sonar-gerrit Jenkins plugin, which is essentially saying the same thing:
This plugin is intended to work with report provided by SonarQube running on your project in preview mode

sonar-pdfreport-plugin-1.4 with Sonar 4.5.1

I am using Sonar 4.5.1 and sonar-pdfreport-plugin-1.4 to run the build. PDF report is not getting generated an is showing below message : Internal error: Can't retrieve project info. Parent project node is empty. Authentication?.
I saw a bug posted for this (https://jira.sonarsource.com/browse/SONARPLUGINS-3854) but would like to know what is the workaround available for this issue. User Authentication is already set for this in General Settings->Pdf report but doesn't work either.
This issue has been fixed in commit a49b8f61afbf47b5f7976d0a759cb0efcd6c5bce.
For now you cannot download jar with this fix, but you can download sources and build custom version:
fetch sources (by git clone https://github.com/SonarQubeCommunity/sonar-pdf-report.git or download zip)
execute maven command mvn clean install
copy generated jar to sonar/data/extensions/plugins

Resources