Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The second part of Sonar6.0 application: Sonar Web interface configuration and command line code analysis integrated with Runner and Scanner

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

First, after installing the SonarQube server, log in to the browsers of other computers and begin to install other programming language detection plug-ins

The language plug-ins that have been installed in the system:

Downloaded the languages commonly used in software projects: Android, CSS, Web, XML

JAVA related: Checkstyle, Findbugs, PMD

Java static analysis tools analyze objects

Applied technology

Checkstyle

Java source files, defect pattern matching

FindBugs

Bytecode, defect pattern matching; data flow analysis

PMD

Java source code, defect pattern matching

Restart the service after downloading the analysis language rules

Second, install the command line analysis terminal

There are two kinds of sonar command line analysis software: Runner and Scanner. The official website document is Scanner, but Runner and its installation and use are basically the same.

1. Install sonar-runner-dist-2.4 on 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/

Configure PATH path

Vim / etc/profile

Add the following at the end of the file, save and exit.

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

Export PATH

Configure the sonar-runner startup configuration file

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

After removing or adding the first # of the following, save and exit

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

Restart the server after the installation is successful, run the above command on the command line and echo it, indicating that the operation is successful.

[root@sonar local] # sonar-runner-h

INFO:

INFO: usage: sonar-runner [options]

INFO:

INFO: Options:

INFO:-Djue Musi define Define property

INFO:-ejingle talk errors Produce execution error messages

INFO:-hmai Whitman help Display help information

INFO:-vmam copyright version Display version information

INFO:-Xpumi talk debug Produce execution debug output

2. Install sonar-scanner2.8 on CentOS

Cd / usr/local/src/wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.8.zipunzip sonar-scanner-2.8.zipmv sonar-scanner-2.8/ / usr/local/

Configure PATH path

Vim / etc/profile

Add the following at the end of the file, save and exit.

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

Export PATH

Configure the sonar-scanner startup configuration file

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

After removing or adding the first # of the following, save and exit

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

Restart the server after the installation is successful, run the above command on the command line and echo it, indicating that the operation is successful.

[root@sonar local] # sonar-scanner-h

INFO:

INFO: usage: sonar-scanner [options]

INFO:

INFO: Options:

INFO:-Djue Musi define Define property

INFO:-hmai Whitman help Display help information

INFO:-vmam copyright version Display version information

INFO:-Xpumi talk debug Produce execution debug output

INFO:-Imam Murray interactive Run interactively

Third, package the source code of the development program into a zip file and upload it to the server where Runner or Scanner is installed

Extract the uploaded source code:

Cd / usr/local/

Unzip whale.zip

Fourth, use sonar-scanner for code quality analysis

1. Set up a configuration file on the server that you want to execute with Scanner

Cd whale/

Vim sonar-project.properties

2. The contents of the file are as follows:

# must be unique in a given SonarQube instance

Sonar.projectKey=whale:scanner

# this is the name and version displayed in 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 property 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. Run the command for analysis after saving and exiting (Findbugs3.4.3 analysis cannot be performed in the analysis, but can be analyzed normally after the rule is uninstalled on the web):

Sonar-scanner

4. View the results of Scanner code quality analysis in web.

Fifth, use sonar-Runner for code quality analysis

1. Modify the configuration file when Scanner is executed.

Cd / usr/local/whale/

Vim sonar-project.properties

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

# must be unique in a given SonarQube instance

Sonar.projectKey=whale:runner

# this is the name and version displayed in 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 property 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. Run the command for analysis after saving and exiting (Findbugs3.4.3 analysis cannot be performed in the analysis, but can be analyzed normally after the rule is uninstalled on the web):

Sonar-runner

4. View the results of runner code quality analysis in web.

The result is the same, proving that Runner and Scanner are similar in function.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report