And detecting the mass of potential bug codes SonarQube

Parameters

Project analysis parameters can be set in multiple places, inheritance follows:

  • Global analysis parameters, through the Web UI settings apply to all items (Configuration -> General -> General set)
  • Item analysis parameters, provided via the WebUI, covering the global parameters (the project level configuration -> Settings set)
  • Item analysis parameters, defined in the setting file analysis items (eg: sonar-project.properties): the analysis parameter setting item, and covering the WebUI analyzer profiles (sonar-runner.properties eg)
  • Command line arguments from the command specified in the beginning of the analysis parameters (such as: -d or / d :), analysis parameters may cover projects

Note: Only the WebUI configuration parameters are stored in the database

The following parameter list is not complete, the WebUI global or project level settings, can be used as analytical parameters, as shown in keywords:

SonarQube_KeyWord.png

Mandatory parameter

Analysis of the implementation of the project must be specified parameters

Keyword description Defaults
sonar.host.url server address http://localhost:9000
sonar.projectKey Key uniquely identifies the project, it can be letters, numbers, '-', '_', and '' ':', but must contain at least one letter  
sonar.projectName project name  
sonar.projectVersion Project version  
sonar.sources Source folder, with a plurality of ',' separate  

Optional parameters

Keyword description Defaults
Authentication    
sonar.login Username or authentication token  
sonar.password User passwords, the use of authentication tokens can ignore this property  
Project Configuration    
sonar.projectDescription project description  
sonar.tests Test file directory, with the plurality ',' separate  
sonar.analysis.mode Analysis mode (publish / preview / issues) publish
sonar.language We need to analyze the source code language, the default implementation of multi-language analysis  
sonar.sourceEncoding Source coding format System encoding format
sonar.projectBaseDir 项目主目录,用于分析开始时的当前目录不是项目主目录的情况,可以是相对目录也可以是绝对目录  
sonar.working.directory 用于SonarQube Runner执行分析时的工作目录,可以是相对目录,也可以是绝对目录 .sonar
分析日志    
sonar.log.level 设置分析过程中的日志级别(INFO/DEBUG/TRACE,其中TRACE级别会输出SQL语句及其执行的事件) INFO

忽略文件

有以下几种方式来缩小要分析源码的范围,如下:

  1. 源代码目录:设置sonar.sources参数指定源代码目录的范围
  2. 文件后缀:许多语言都提供了限制文件后缀名的的参数,’配置’–>’通用’–>’[语言]’,设置File suffixes属性
  3. 选择指定文件
    • sonar.exclusions/sonar.test.exclusions 设置分析除指定文件以外的所有文件
    • sonar.inclusions/sonar.test.inclusions 设置仅仅分析指定的文件

通配符

符号 匹配
* 匹配一个或多个字符
** 匹配一个或多个目录
? 匹配一个字符

如下:

# 排除所有Bean结尾的类
# 匹配org/sonar.api/MyBean.java, org/sonar/util/MyOtherBean.java, org/sonar/util/MyDTO.java等
sonar.exclusions=**/*Bean.java,**/*DTO.java

# 排除src/main/java/org/sonar目录下所有文件
# 但不包括其子目录下的文件
sonar.exclusions=src/main/java/org/sonar/*

# 排除bank目录及其子目录下的所有文件
sonar.exclusions=bank/**/*

# 排除bank目录及其子目录下的所有.cs文件
sonar.exclusions=bank/**/*.cs

比如:
CurrentPath=$(pwd)
CurrentPath=${CurrentPath#\/}
CurrentPath=${CurrentPath//\//_}
echo $CurrentPath

sonar-scanner \
    -X \
  -Dsonar.projectKey=cms \
  -Dsonar.sources=. \
#  -Dsonar.tests=. \
  -Dsonar.exclusions=**/_vgo/** \
  -Dsonar.exclusions=**/vendor/** \
  -Dsonar.host.url=http://{sonar qube server} \
  -Dsonar.login=xxxxxx \
  -Dsonar.projectName=${CurrentPath}

 

 

 

 

For details, see the official documentation

Guess you like

Origin www.cnblogs.com/sunsky303/p/11760353.html