In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Introduction to Sonar
Sonar is an open source platform for code quality management, which manages the quality of source code and can detect code quality from seven dimensions.
In the form of plug-ins, you can support code quality management and testing in more than 20 programming languages, including java,C#,C/C++,PL/SQL,Cobol,JavaScrip,Groovy
What can sonarQube bring?
Developers' Seven Deadly Sins
1. Poor complexity distribution
Files, classes, methods, etc. will be difficult to change if the complexity is too high, which will make it difficult for developers to understand them.
And without automated unit testing, changes to any component in the program may lead to the need for comprehensive regression testing
two。 Repetition
Obviously, the quality of the code that contains a lot of copy and paste in the program is poor.
Sonar can show serious repetition in the source code.
3. Lack of unit testing
Sonar can easily count and display unit test coverage.
4. There is no code standard.
Sonar can standardize code writing through code rule detection tools such as PMD,CheckStyle,Findbugs.
5. There are not enough or too many comments
The lack of comments will worsen the readability of the code, especially when there are inevitable personnel changes, the readability of the program will be greatly reduced.
On the other hand, too many comments will cause developers to spend too much energy on reading comments, which is also against the original intention.
6. Potential bug
Sonar can detect potential bug through code rule detection tools such as PMD,CheckStyle,Findbugs
7. Bad design (original Spaghetti Design, spaghetti design)
Through sonar, you can find the loop and show the interdependence between package and package, class and class.
Can detect custom schema rules
Third-party jar packages can be managed through sonar
You can use LCOM4 to detect the application of individual task rules
Detection coupling
About Spaghetti Design: http://docs.codehaus.org/display/SONAR/Spaghetti+Design
Through sonar, we can effectively detect the above seven problems in the process of program development.
SonarQube installation
Preset condition
1. The Java environment is installed
two。 The MySQL database is installed
Software download address: http://www.sonarqube.org/downloads/
Download SonarQube and SonarQube Runner
Download the Chinese patch pack: http://docs.codehaus.org/display/SONAR/Chinese+Pack
1. Database configuration
Enter database command
# mysql-u root-p
Mysql > CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci
Mysql > CREATE USER 'sonar' IDENTIFIED BY' sonar'
Mysql > GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY' sonar'
Mysql > GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY' sonar'
Mysql > FLUSH PRIVILEGES
two。 Install sonar and sonar-runner
Extract the downloaded sonar-3.7.zip package to a path such as / usr/local in Linux
Extract the downloaded sonar-runner-dist-2.3.zip package to a certain path / usr/local
Add SONAR_HOME, SONAR_RUNNER_HOME environment variables, and add SONAR_RUNNER_HOME to PATH
Modify sonar configuration file
Edit / conf/sonar.properties file, configure database settings, and support all kinds of databases by default
Mysql is used here, so uncomment the mysql module
# vi sonar.properties
Sonar.jdbc.username: sonar
Sonar.jdbc.password: sonar
Sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
# Optional properties
Sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
Modify the configuration file of sonar-runner
Change to the installation directory of sonar-runner and modify sonar-runner.properties
Cancel the comments according to the actual use of the database
# Configure here general information about the environment, such as SonarQube DB details for example
# No information about specific project should appear here
#-Default SonarQube server
Sonar.host.url= http://localhost:9000
#-PostgreSQL
# sonar.jdbc.url=jdbc:postgresql://localhost/sonar
#-MySQL
Sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?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 settings
Sonar.jdbc.username=sonar
Sonar.jdbc.password=sonar
#-Default source code encoding
Sonar.sourceEncoding=UTF-8
#-Security (when 'sonar.forceAuthentication' is set to' true')
Sonar.login=admin
Sonar.password=admin
3. Add a database driver
Except for Oracle database, other database drivers are provided by default, and these added drivers are the only ones supported by sonar, so there is no need to modify them.
If it is an Oracle database, you need to copy the JDBC driver to / extensions/jdbc-driver/oracle directory
4. Start the service
Directory change to the / bin/linux-x86-64 / directory of sonar to start the service
#. / sonar.sh start start the service
#. / sonar.sh stop stops service
#. / sonar.sh restart restart the service
At this point, sonar is installed.
Just visit http:\\ localhost:9000
5.sonar Chinese Patch Pack installation
Chinese package installation
You can install the Chinese patch pack by visiting http:\\ localhost:9000. After opening sonar, go to the Update Center to install it.
Or download the Chinese patch pack, put it in the SONARQUBE_HOME/extensions/plugins directory, and then restart the SonarQube service
Sonar starts itself as a Linux service and boots
Create a new file / etc/init.d/sonar and enter the following:
#! / bin/sh
#
# rc file for SonarQube
#
# chkconfig: 345 96 10
# description: SonarQube system (www.sonarsource.org)
#
# BEGIN INIT INFO
# Provides: sonar
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: SonarQube system (www.sonarsource.org)
# Description: SonarQube system (www.sonarsource.org)
# END INIT INFO
/ usr/bin/sonar $*
SonarQube Boot self-boot (Ubuntu, 32-bit):
Sudo ln-s $SONAR_HOME/bin/linux-x86-32/sonar.sh / usr/bin/sonar
Sudo chmod 755 / etc/init.d/sonar
Sudo update-rc.d sonar defaults
SonarQube boot self-boot (RedHat, CentOS, 64-bit):
Sudo ln-s $SONAR_HOME/bin/linux-x86-64/sonar.sh / usr/bin/sonar
Sudo chmod 755 / etc/init.d/sonar
Sudo chkconfig-add sonar
Use SonarQube Runner to analyze source code
Preset condition
SonarQube Runner is installed and environment variables are configured, that is, sonar-runner commands can be executed in any directory
1. Create a sonar-project.properties configuration file in the root directory of the project source code
Take the Android project as an example:
Sonar.projectKey=android-sonarqube-runner
Sonar.projectName=Simple Android project analyzed with the SonarQube Runner
Sonar.projectVersion=1.0
Sonar.sources=src
Sonar.binaries=bin/classes
Sonar.language=java
Sonar.sourceEncoding=UTF-8
Sonar.profile=Android Lint
Note: to use Android Lint
Rule analysis requires first visiting the http:\\ localhost:9000 update center to add an Android Lint plug-in so that it can analyze Android Lint rules
two。 Executive analysis
Change to the project source root directory and execute the command
# sonar-runner
After a successful analysis, visit http:\\ localhost:9000 to view the analysis results.
The meaning of different parameters:
Http://docs.codehaus.org/display/SONAR/Analysis+Parameters
Download examples of source code analysis for different projects:
Https://github.com/SonarSource/sonar-examples/zipball/master
Associate with IDE
Finally, of course, it has to be associated with IDE to make it easier to view it in real time.
Take Eclipse as an example, see: http://docs.sonarqube.org/display/SONAR/SonarQube+in+Eclipse
Attached:
SonarQube official website address: http://www.sonarqube.org/
SonarQube official document address: http://docs.codehaus.org/display/SONAR/Documentation
SonarQube sample address: http://nemo.sonarqube.org/
Two other related articles on the Internet: http://www.cnblogs.com/gao241/p/3190701.html
Http://www.myexception.cn/open-source/1307345.html
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.