In the past, the focus has been on How to Improve the Quality of the application, not too concerned about the quality of the code level. Recently, due to some factors, we need to pay attention to code-level quality and push the quality work forward as far as possible, in line with the quality control principles. I tried sonarqube (the old version is sonar, ww.sonarqube.org) and it does play a lot of roles in code improvement. sonarqube can measure code quality in seven dimensions. In practice, it is easy to see the role.In particular, it is recommended that you take a good look at the descriptions and examples in rules to improve the quality of your code.
Sonarqube installation:
Sonarqube consists of three parts:
The following installation steps are examples of Linux Installation
Database:
Here I use the MySQL database to directly execute the SQL:
CREATEDATABASEsonarCHARACTERSETutf8COLLATEutf8_general_ci;
Grant the database users connected to Sona the read and write permissions.
Web Services:Modify sonarqube/CONF/sonar. Properties
# Permissions to create tables, indices and triggers must be granted to JDBC user.# The schema must be created first.sonar.jdbc.username=mysql_usernamesonar.jdbc.password=mysql_password# Comment the following line to deactivate the default embedded database.#sonar.jdbc.url=jdbc:h2:tcp://localhost:9092/sonar#----- MySQL 5.x# Comment the embedded database and uncomment the following line to use MySQLsonar.jdbc.url=jdbc:mysql://192.168.22.99:3306/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=tsonar.web.host=0.0.0.0sonar.web.context=/sonarqubesonar.web.port=9001
Sonarqube comes with Web server, performance is good enough, do not need to configure tomcat or something, here all the sonar web service configuration is complete, to sonarqube/bin/linux-x86-64, directory, start sonar. sh start. You can view log: sonarqube/logs/sonar if you have any questions after startup. log, access http: // 192.168.22.99: 9001/sonarqube through a browser, open the login page, the default Administrator account is admin/admin
Analyzer:
Sonarqube supports 20 + languages, such as Java, Python, C #, C/C ++, PL/SQL, and COBOL through plug-ins, but the C language plug-ins are charged. Here the http://docs.codehaus.org/display/SONAR/Plugin+Library downloads the corresponding language plug-ins, placed in sonarqube/extensions/plugins, directory, restart the web service.
Five main analyzer types: sonarqube runner (omnipotent, including the following methods), Maven (integrated with Maven compilation project), sonarqube ant task (integrated with ant compilation project), gradle, CI engine (mainly integrated with CI tools such as Jenkins and Hudson ).
The following describes how to use the sonarqube runner Analyzer:
Download the sonarqube Analyzer: http://docs.codehaus.org/display/SONAR/Installing+and+Configuring+SonarQube+Runner, unzip it and modify the sonar-runner.properties under the conf directory, as shown in the following example.
#----- Default SonarQube serversonar.host.url=http://192.168.23.94:9001/sonarqube#----- PostgreSQL#sonar.jdbc.url=jdbc:postgresql://localhost/sonar#----- MySQLsonar.jdbc.url=jdbc:mysql://192.168.23.99:3306/sonarqube_qa?useUnicode=true&characterEncoding=utf8#----- Oracle#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE#----- Microsoft SQLServer#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor#----- Global database settingssonar.jdbc.username=mysql_usernamesonar.jdbc.password=mysql_password#----- Default source code encodingsonar.sourceEncoding=UTF-8#----- Security (when 'sonar.forceAuthentication' is set to 'true')sonar.login=adminsonar.password=admin
Add sonarruner/bin to the path directory and add sonar_runner_home = "/home // sonarruner" to the environment variable ".
Here, the entire sonarqube runtime environment is fully configured. The next article explains how to run the analyzer.
Use sonarqube to check and Measure code quality-install sonarqube