Sonar6.0 Application II: Sonar Web Interface Configuration and command line code analysis with runner, scanner integration

Source: Internet
Author: User
Tags checkstyle

First, install the Sonarqube service end, in other Computer browser landing, start to install other programming language detection plug-ins

The system has installed language plug-ins:

Download the languages that are commonly used in software projects:Android,CSS,Web,XML

Java-Related:Checkstyle,Findbugs,PMD

Java Static Analysis tool profiling objects

Application Technology

Checkstyle

Java source files, defect pattern matching

Findbugs

Byte code, defect pattern matching; Data Flow analysis

Pmd

Java source code, bug pattern matching

Restart the service after downloading the analysis language rule

second, the installation command line analysis End

Sonar's command-line analysis software has two different runner and scanner, the official website document is written in scanner, but runner and it installation, use are basically consistent.

1, install the sonar-runner-dist-2.4 on the CentOS

cd/usr/local/src/

wget Http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip

Unzip Sonar-runner-dist-2.4.zip

MV sonar-runner-2.4//usr/local/

Configuring the Path Path

Vim/etc/profile

At the end of the file add the following content, save and exit.

Path= $PATH:/usr/local/sonar-runner-2.4/bin
Export PATH

Configuring the Sonar-runner Boot configuration file

Vim/usr/local/sonar-runner-2.4/conf/sonar-runner.properties

Save and exit before the # number is removed or added to the following contents

Sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useunicode=true&characterencoding=utf8
sonar.jdbc.username=sonar  
sonar.jdbc.password=sonar  
sonar.host.url=http:// 192.168.1.190
sonar.login=admin  
sonar.password=admin reboot the server after successful installation, running the above command at the command line and echoing back to indicate that the operation was successful.

[Root@sonar local]# Sonar-runner-h
INFO:
Info:usage:sonar-runner [Options]
INFO:
Info:options:
INFO: D,--define <arg> define Property
INFO:-e,--errors produce execution error messages
INFO:-H,--help Display Help information
INFO:-V,--version Display version information
INFO:-x,--debug produce execution debug output

2, install the sonar-scanner2.8 on the CentOS

cd/usr/local/src/

wget Https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.8.zip

Unzip Sonar-scanner-2.8.zip

MV sonar-scanner-2.8//usr/local/

Configuring the Path Path

Vim/etc/profile

At the end of the file add the following content, save and exit.

Path= $PATH:/usr/local/sonar-runner-2.4/bin:/usr/local/sonar-scanner-2.8/bin
Export PATH

Configuring the Sonar-scanner Boot configuration file

Vim/usr/local/sonar-scanner-2.8/conf/sonar-scanner.properties

Save and exit before the # number is removed or added to the following contents

Sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useunicode=true&amp;characterencoding=utf8
Sonar.jdbc.username=sonar
Sonar.jdbc.password=sonar
sonar.host.url=http://192.168.1.190
Sonar.login=admin
Restart the server after the Sonar.password=admin installation succeeds, run the above command at the command line and echo back to indicate that the operation was successful.

[Root@sonar local]# Sonar-scanner-h
INFO:
Info:usage:sonar-scanner [Options]
INFO:
Info:options:
INFO: D,--define <arg> define Property
INFO:-H,--help Display Help information
INFO:-V,--version Display version information
INFO:-x,--debug produce execution debug output
INFO:-I,--interactive Run interactively

Package The source code of the development program into a ZIP file and upload it to a server with runner or scanner installed on it.

Unzip the uploaded source code:

cd/usr/local/

Unzip Whale.zip

Four, use Sonar-scanner to carry on the Code quality analysis

1. Create a configuration file on the server to be executed with scanner

CD whale/

Vim Sonar-project.properties

2, the establishment of the contents of the document are as follows:

# must be unique in a given Sonarqube instance
Sonar.projectkey=whale:scanner
# This is the name and version displayed the Sonarqube UI. was mandatory prior to sonarqube 6.1.
Sonar.projectname=whale-scanner
sonar.projectversion=1.0

# Path is relative to the sonar-project.properties file. Replace ' \ ' by '/' on Windows.
# Since Sonarqube 4.2, this is optional if sonar.modules is set.
# If not set, Sonarqube starts looking for source code from the directory containing
# The Sonar-project.properties file.
Sonar.sources=.

# Encoding of the source code. Default is default system encoding
#sonar. Sourceencoding=utf-8

3, save and exit after the operation of the command analysis (analysis can not perform Findbugs3.4.3 analysis, after the Web side uninstall this rule can be normal analysis):

Sonar-scanner

4. View the results of scanner code quality analysis in the Web.

v. Use Sonar-runner for code quality analysis

1, modify the scanner execution of the configuration file

cd/usr/local/whale/

Vim Sonar-project.properties

2. The contents of the modified documents are as follows:

# must be unique in a given Sonarqube instance
Sonar.projectkey=whale:runner
# This is the name and version displayed the Sonarqube UI. was mandatory prior to sonarqube 6.1.
Sonar.projectname=whale-runner
sonar.projectversion=1.0

# Path is relative to the sonar-project.properties file. Replace ' \ ' by '/' on Windows.
# Since Sonarqube 4.2, this is optional if sonar.modules is set.
# If not set, Sonarqube starts looking for source code from the directory containing
# The Sonar-project.properties file.
Sonar.sources=.

# Encoding of the source code. Default is default system encoding
#sonar. Sourceencoding=utf-8

3, save and exit after the operation of the command analysis (analysis can not perform Findbugs3.4.3 analysis, after the Web side uninstall this rule can be normal analysis):

Sonar-runner

4. View the results of runner Code quality analysis in the Web.

As it turns out, runner and scanner functions are similar.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.