sonar control code quality

http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

Sonar overview

Sonar is an open platform for code quality management. Through the plugin mechanism, Sonar can integrate different testing tools, code analysis tools, and continuous integration tools.

Different from continuous integration tools (such as Hudson/Jenkins, etc.), Sonar does not simply display the results of different code inspection tools (such as FindBugs, PMD, etc.) directly on the Web page, but through different plug-ins to reproduce these results. Process, measure the change of code quality in a quantitative way, so that it can easily manage the code quality of projects of different scales and types.

In terms of support for other tools, Sonar not only provides IDE support, you can view the results online in tools such as Eclipse and IntelliJ IDEA; at the same time, Sonar also provides interface support for a large number of continuous integration tools, which can be very convenient for continuous integration. Sonar is used in the integration.

In addition, Sonar's plug-ins can provide support for programming languages ​​other than Java, as well as good support for internationalization and report documentation.

Installation of Sonar

Sonar is an open source project on Codehaus, using the LGPL V3 software license. We can download its source code and installation package on its official website.

Its source code needs to be checked out using the distributed version control software Git. The command line method is as follows:

git clone git://github.com/SonarSource/sonar.git

This article mainly introduces how to use Sonar. You only need to download the latest release package from the Sonar website . The latest version at the time of writing this article is 2.11.

After downloading the zip package, unzip it directly to any directory. Since Sonar comes with the application server environment of Jetty 6, it can be used without additional installation. It is worth mentioning that Sonar also supports deployment in the Apache Tomcat application server.

In the windows environment, directly start windows-x86-64\StartSonar.bat in the bin directory of Soanr.

Then visit in the browser: http://localhost:9000/

Figure 1. Sonar access interface

Figure 1. Sonar access interface

In this way, Sonar is successfully installed and started, but no plug-ins are installed, and users need to download and install the plug-ins they need. This section takes Quality Index Plugin as an example to introduce how to download and install the Sonar plug-in.

First visit the Dashboard > Sonar > Documentation > Sonar Plugin Library path in the Sonar homepage

Figure 2. Download of Sonar plugin

Figure 2. Download of Sonar plugin

Enter the Quality Index plugin, click the download path

Figure 3. Quality Index Plugin download

Figure 3. Quality Index Plugin download

Then put the downloaded sonar-quality-index-plugin-1.1.3.jar file in the sonar-2.11\extensions\plugins path. Restart Sonar and the plugin is running and working on Sonar's platform.

Database settings

Sonar uses the Derby database by default, but this database is generally used for evaluation builds or testing purposes. For commercial use and high database requirements, other databases are recommended. Sonar can support most mainstream relational databases (such as Microsoft SQL Server, MySQL, Oracle, PostgreSQL, etc.)

This article uses MySQL as an example to explain how to change Sonar's database settings:

  1. Create a sonar user in MySQL
    CREATE USER sonar IDENTIFIED BY 'sonar';
    
    GRANT ALL PRIVILEGES ON *.* TO 'sonar'@'localhost' \
    IDENTIFIED BY 'sonar' WITH GRANT OPTION;
  2. Copy the MySQL driver file (such as mysql-connector-java-5.1.13.jar) to the sonar-2.11\extensions\jdbc-driver\mysql directory
  3. Modify the sonar-2.11\conf\sonar.properties file, annotate the original Derby configuration items with #, and open the MySQL database configuration items:
    # Comment the following lines to deactivate the default embedded database.
    #sonar.jdbc.url: jdbc:derby://localhost:1527/sonar;create=true
    #sonar.jdbc.driverClassName: org.apache.derby.jdbc.ClientDriver
    #sonar.jdbc.validationQuery: values(1)
    
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    #----- MySQL 5.x/6.x
    # Comment the embedded database and uncomment the following
    #properties to use MySQL. The validation query is optional.
    sonar.jdbc.url: \
    jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
    sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
    #sonar.jdbc.validationQuery: select 1
  4. Restart Sonar.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326304901&siteId=291194637