SonarQube-5.6.3 代码分析平台搭建使用

python代码分析 官网主页:

http://docs.sonarqube.org/display/PLUG/Python+Plugin

 

Windows下安装使用:

快速使用:

1.下载jdk http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

2.下载解压sonarhttp://www.sonarqube.org/downloads/

下载解压sonar scannerhttp://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

3. 启动sonar,运行sonarqube-5.6.3\bin\windows-x86-64\StartSonar.bat

4. 进入目录sonar-examples-master\projects\languages\java\sonar-runner\java-sonar-runner-simple, 运行sonar-scanner-2.8\bin\sonar-scanner.bat, 跑了一个实例了(如果不能正常运行,检查jdk

5.可在这查看运行结果: http://localhost:9000 (首次登陆账号密码:admin

6.设置中文:登陆后 Administration -> System -> Update Center -> Available -> 搜索( Chinese 插件) -> 安装后提示重启,生效

 

进阶:

1、安装MySQL,配置sonar数据库;

mysql -u root -p

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE USER 'sonar' IDENTIFIED BY 'sonar';

GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';

GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';

FLUSH PRIVILEGES;

2、 修改配置文件 /conf/sonar.properties:

sonar.jdbc.username=sonar

sonar.jdbc.password=sonar

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

sonar.login=admin

sonar.password=admin

   

3、修改配置文件sonar-scanner.properties:

#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

 

#----- Default source code encoding

sonar.sourceEncoding=UTF-8

 

#----- Global database settings (not used for SonarQube 5.2+)

sonar.jdbc.username=sonar

sonar.jdbc.password=sonar

 

#----- 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

 

#----- Security (when 'sonar.forceAuthentication' is set to 'true')  

sonar.login=admin  

sonar.password=admin  

 

4、运行setup更新一下, http://localhost:9000/setup

5、检测代码:

  1. 因为sonar服务器默认没安装python检测插件,此处用python代码做例子下载插件:主页->配置->系统->更新中心->Available->搜索Python插件,安装后按提示重启sonar
  2. 进入需要检测的项目根目录下,新建配置文件sonar-project.properties (这里是检测python代码)

# Required metadata

sonar.projectKey=org.sonarqube:python-simple-sonar-scanner

sonar.projectName=Python :: Simple Project : SonarQube Scanner

sonar.projectVersion=1.0

# Comma-separated paths to directories with sources (required)

sonar.sources=src

Language

sonar.language=py

# Encoding of the source files

sonar.sourceEncoding=UTF-8

  1. 增加 C:\sonar-scanner-2.8\bin 为全局环境变量
  2. 进入项目 根目录,运行 sonar-runner
  3. 分析成功:

http://localhost:9000/overview?id=org.sonarqube%3Apython-simple-sonar-scanner 查看

 

 

扩展:

  1. 自定义规则:

http://docs.sonarqube.org/display/DEV/Adding+Coding+Rules+using+XPath

    1. Login as an Quality Profile Administrator
    2. Go to Rules page
    3. Select the Language for which you want to create the XPath rule
    4. Tick the Template criterion and select "Show Templates Only" 
    5. Look for the XPath rule template:
       
    6. Click on it to create a new instance of XPath rule: 
    7. Feed the form:
    8. Paste in the XPath query (it should comply to XPath 1.0) you wrote and tested using the SSLR toolkit:
    9. Once your rule is added to SonarQube, activate it in a Quality Profile and run an analysis.

 

转载于:https://www.cnblogs.com/GO-NO-1/p/6163609.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值