|Steinar Bang 3ce8ca2261 Change the docker build maven command to reflect that image building has been bound to the maven package build phase||2 months ago|
|docker||2 months ago|
|jacoco-coverage-report||2 months ago|
|sonar-collector-webhook||2 months ago|
|.editorconfig||2 years ago|
|.gitignore||2 years ago|
|.travis.yml||3 months ago|
|LICENSE||2 years ago|
|README.org||2 months ago|
|pom.xml||2 months ago|
SonarQube is a code analysis tool that shows key numbers about code quality, e.g. code coverage, code complexity and various code practices.
SonarQube has a web GUI that allows exploring the analysis results.
However, SonarQube has no storage of build quality history. To keep statistics about code quality one either have to manually type the key numbers of each analysed application into a spreadsheet, or use something like this tool.
This utility consists of a servlet that serves as a webhook that is called by Sonar when completing an analysis. The webhook POST data doesn't have the necessary information (which are some key metrics of the build).
So when receiving a POST, the servlet will do a callback to the SonarQube REST API to retrieve the metrics, which will then be stored in a PostgreSQL database.
The servlet has been written as a microservice that can be installed into an apache karaf instance.
file:https://travis-ci.org/steinarb/sonar-collector.svg?branch=master file:https://coveralls.io/repos/steinarb/sonar-collector/badge.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.sonar.sonar-collector%3Asonar-collector&metric=alert_status#.svg file:https://maven-badges.herokuapp.com/maven-central/no.priv.bang.sonar.sonar-collector/sonar-collector/badge.svg
file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.sonar.sonar-collector%3Asonar-collector&metric=ncloc#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.sonar.sonar-collector%3Asonar-collector&metric=bugs#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.sonar.sonar-collector%3Asonar-collector&metric=vulnerabilities#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.sonar.sonar-collector%3Asonar-collector&metric=code_smells#.svg file:https://sonarcloud.io/api/project_badges/measure?project=no.priv.bang.sonar.sonar-collector%3Asonar-collector&metric=coverage#.svg
|1.2.0||<2020-04-20 Mon>||Use jackson-databind 18.104.22.168, make liquibase script work with h2|
|1.1.0||<2019-11-14 Thu>||Use pax-jdbc-config to set up the database, build with openjdk 11, jackson security upgrade|
|1.0.0||<2017-12-18 Mon>||First release|
(this assumes that you have an apache karaf already installed on your development computer, as well as git, maven, and a Java development kit)
/Note/: You will need to have a suitable PostgreSQL database to write to for this servlet to be meaningful. See the sections Create the database and Using a database running on a different host for more detail. The database just have to be a blank, freshly created database, that the servlet can write to, either on localhost with the curent user, or using JDBC credentials configured from the karaf console (this is what's covered in Using a database running on a different host).
/Note/: The docker image is actually provisioned at startup time by the latest sonar-collector release to maven central, so don't be mislead by the creation date of the image. The most recent relase to maven central is what will be run.
|he values that can be overridden by setting environment variables on container start, are|
|JDBC_DRIVER_FEATURE||postgresql||Karaf feature to load the driver|
|JDBC_DRIVER_NAME||PostgreSQL JDBC Driver||Identify correct driver for OSGi service dependency injection|
|JDBC_USER||No default to make it possible to have no username|
|JDBC_PASSWORD||No default to make it possible to have no password|
|RDBMS type||Karaf feature||JDBC_DRIVER_NAME||example JDBC_URL||Default port|
|PostgreSQL||postgresql||PostgreSQL JDBC Driver||jdbc:postgresql://somehost.company.com/sonar-collector||5432|
|Derby (aka. JavaDB)||pax-jdbc-derby||derby||jdbc:derby://somehost.company.com:1527/sonar-collector||1527|
|H2||pax-jdbc-h2||H2 JDBC Driver||jdbc:h2:tcp://somehost.company.com/~/sonar-collector||9092|
|MSSQL||pax-jdbc-mssql||Microsoft JDBC Driver for SQL Server||jdbc:sqlserver://somehost.company.com:1433;databaseName=sonar-collector||1433|
(This procedure doesn't require development tools or building the project yourself. The servlet, and its attached karaf feature has been deployed to maven central)
This describes how to install and run the program on a debian GNU/linux system.
As root, do the following command:
apt-get update apt-get install postgresql
(the application has been installed into maven central, which is a repository that is builtin to karaf)
The above example shows connecting to a PostgreSQL database running on localhost, authenticating with ident authentication (ie. no password).
This example shows how to connect to a PostgreSQL database running on a different host, authenticating using username and password.
The "config:update" command will cause the sonar collector to be restarted, it will pick up the new configuration, and connect to the remote server, and if the "sonar-collector" database exists as a blank database, create the schema and be ready to store data there.
Side note: The configuration will be stored in standard .properties file format, in the file /etc/karaf/no.priv.bang.sonar.collector.webhook.SonarCollectorServlet.cfg and be persistent across restarts and reinstallations of the karaf .deb package (the .deb package will only uninstall/reinstall unchanged known files in this directory, and won't touch unknown files at all).
Note that PostgreSQL out of the box on debian only accepts domain connections and localhost connections.
To make PostgreSQL listen on all network connections, two files must be edited and the PostgreSQL daemon must be restarted.
WARNING! This is not regularily tested (i.e. won't be tested before releases) and I don't plan to actually use sonar-collector with anything except PostgreSQL myself.
In a hosted SonarQube the webhook can be set globally across all projects.
This utility is licensend under the Apache license v. 2. See the LICENSE file for details.
Then just trigger an analysis in the locally installed SonarQube and debug when the breakpoint is triggered:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login=a51f2ab9a8790abd91773f0a7d2f6d2dc9d97975
(as the sonar.login argument, use the token that SonarQube returns when using the setup wizard of the quick start)
Precondition: docker running on the build server