SonarQube

代码质量管理java

 Sonar 是一个用于代码质量管理的开放平台。经过插件机制,Sonar 能够集成不一样的测试工具,代码分析工具,以及持续集成工具。与持续集成工具(例如 Hudson/Jenkins 等)不一样,Sonar 并非简单地把不一样的代码检查工具结果(例如 FindBugs,PMD 等)直接显示在 Web 页面上,而是经过不一样的插件对这些结果进行再加工处理,经过量化的方式度量代码质量的变化,从而能够方便地对不一样规模和种类的工程进行代码质量管理。
        在对其余工具的支持方面,Sonar 不只提供了对 IDE 的支持,能够在 Eclipse 和 IntelliJ IDEA 这些工具里联机查看结果;同时 Sonar 还对大量的持续集成工具提供了接口支持,能够很方便地在持续集成中使用 Sonar。
此外,Sonar 的插件还能够对 Java 之外的其余编程语言提供支持,对国际化以及报告文档化也有良好的支持。mysql

Sonar部署linux

Sonar的相关下载和文档能够在下面的连接中找到:http://www.sonarqube.org/downloads/,须要注意最新版的Sonar须要至少JDK 1.8及以上版本。git

  • yum install -y java-1.8.0
  • cd /usr/local/src
  • wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-7.5.zip
  • unzip sonarqube-5.6.zip
  • mv sonarqube-7.5 /usr/local/
  • ln -s /usr/local/sonarqube-7.5/ /usr/local/sonarqube

准备Sonar数据库github

  • mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
  • mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar@pw';
  • mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar@pw';
  • mysql> FLUSH PRIVILEGES;

配置Sonarweb

  • cd /usr/local/sonarqube/conf/
  • sonar.properties wrapper.conf
  • 编写配置文件,修改数据库配置
  • sonar.properties
  • sonar.jdbc.username=sonar
  • sonar.jdbc.password=sonae@pw
  • sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

启动Sonarsql

你能够在Sonar的配置文件来配置Sonar Web监听的IP地址和端口,默认是9000端口数据库

  • sonar.properties
  • sonar.web.host=0.0.0.0
  • sonar.web.port=9000
  • /usr/local/sonarqube/bin/linux-x86-64/sonar.sh start

访问Sonar
    http://IP:9000编程

插件管理app

  • /usr/local/sonarqube/extensions/plugins

代码分析插件

    • https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
    • Https://github.com/SonarSource 各类语言测试范例,sonar-example

Sonar-scanner插件目录结构

  • [root@localhost local]# cat sonar-scanner/conf/sonar-scanner.properties
  • #Configure here general information about the environment, such as SonarQube server connection details for example
  • #No information about specific project should appear here
  • #----- Default SonarQube server
  • sonar.host.url=http://sonarqube地址:9000
  • #----- Default source code encoding
  • sonar.sourceEncoding=UTF-8
  • sonar.jdbc.username=sonar(数据库用户)
  • sonar.jdbc.password=sonar@pw(数据库密码)
  • sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp:characterEncoding=utf8

Sonar-example语言测试范例

  • [root@localhost local]# cat sonar-project.properties
  • sonar.projectKey=demo
  • sonar.projectName=demo
  • sonar.projectVersion=1.0
  • sonar.sources=./
  • sonar.language=java
  • sonar.sourceEncoding=UTF-8

Sonar-scanner检测命令

  • [root@localhost local]# /usr/local/sonar-scanner/bin/sonar-scanner

访问Sonar
    http://IP:9000 就会看到示例,检测什么样的语言,提早按照好插件,Chinese Pack是中文插件

相关文章
相关标签/搜索