Android code check tool SonarQube and androidsonarqube

Source: Internet
Author: User

Android code check tool SonarQube and androidsonarqube


The code check tool can help us check some hidden bugs. The sonar in the code check tool is better. Official Website


Sonar Overview


Sonar is an open platform for code quality management. With the plug-in mechanism, Sonar can integrate different test tools, code analysis tools, and continuous integration tools. Unlike continuous integration tools (such as Hudson/Jenkins), Sonar does not simply display different code check tool results (such as FindBugs and PMD) on the Web page, instead, different plug-ins are used to reprocess these results and quantify the changes in code quality. This allows you to conveniently manage code quality for projects of different sizes and types.
In terms of support for other tools, Sonar not only provides support for IDE, but can view the results online in Eclipse and IntelliJ IDEA tools; at the same time, Sonar also provides Interface Support for a large number of continuous integration tools to facilitate the use of Sonar in continuous integration.
In addition, the Sonar plug-in can also provide support for programming languages other than Java, as well as good support for internationalization and report docalization.
Main features
· Code coverage: unit test shows the code lines selected.
· Improved Coding rules
· Search encoding rules: query by name, plug-in, activation level, and category
· Project search: query by project name
· Comparison data: Compare the trend of any measurement in the same table


Sonar Installation


Sonar is an open-source project in Codehaus, using LGPL V3 software license. We can download its source code and installation package from its official website. The source code must be checked Out using the distributed version control software Git. The command line is as follows:
Git clone git: // github.com/SonarSource/sonar.git
This article describes how to use Sonar and how to install the Android studio plug-in. You only need to download the latest release package from the Sonar website. The latest version is 4.5.1 when writing this article. After downloading the zip package, directly decompress the package to any directory. Because Sonar comes with the Jetty 6 Application server environment, it can be used without additional installation, it is worth mentioning that Sonar can also be deployed on the Apache Tomcat application server. In windows, directly start the windows-x86-64 \ StartSonar. bat under the bin directory of Soanr. Then access: http: // localhost: 9000/in the browser (the Chinese package needs to be downloaded in the Chinese version ):



For documentation and some jar packages and plug-ins, click run analysis:



First, log on to the configuration project:


The default value is admin and admin.

After Login



Click Provisioning, click Create, and enter the keywords and project name (preferably the same as the project name of the check code ):



Other settings are not required and can be skipped.

If you do not need to integrate the plug-in, it is difficult to use it. The following describes how to install and use the sonar plug-in Android studio (intellij idea is similar ).



Click "Install" and restart the installation.

The configuration is as follows:



After installation, click the sonarqube option to add a server, enter the default address and user name and password, and test the connection. OK.

Right-click the project and associate it with the backend server project:



Enter the project name, OK:



Right-click analyze -- "inspect code (you can also select run inspection by name and enter sonarqube issue). The result is displayed on the console.




Analysis result:



The above is the form of plug-ins, but there is no graphical display, the following introduces another implementation method:

:



This is much clearer. The detailed steps are as follows:

There are several methods for running analysis. Here we use the officially recommended method to download SonarQube Runner

Address: http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip

Decompress the package to any directory. It is best not to include the Chinese path.

Set the environment variable SONAR_RUNNER_HOME, and set the value to your decompression directory.

Add the decompressed directory/bin to the path environment variable. Open the command line and enter sonar-runner-h.

Output after Successful Configuration:

usage: sonar-runner [options] Options: -D,--define <arg>     Define property -e,--errors           Produce execution error messages -h,--help             Display help information -v,--version          Display version information -X,--debug            Produce execution debug output

Add a file: sonar-project.properties under the project root directory to be debugged

Enter the following content:

# Required metadata# Key and name are the fields entered during project creation. Enter your project name and key here.sonar.projectKey=my:projectsonar.projectName=My projectsonar.projectVersion=1.0 # Path to the parent source code directory.# 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=src # Encoding of the source codesonar.sourceEncoding=UTF-8 # Additional parameterssonar.my.property=value

Run the command line to enter your project and directory, and run sonar-runner.

Example: D: \ AndroidStudioWork \ wodou> sonar-runner open the console and you will be able to see the visual data.



If you have any questions, please leave a message and repeat the source.

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.