sonarqube应用

1.     SonarQube 4.4系统要求

l  OpenJDK 7 以上

MySQL 5.7

Microsoft Internet Explorer 910

2.     SonarQube Platform Overview


3.     安装服务端

下载解压后修改配置sonar.propertieswrapper.conf文件

4.     安装分析器

a)    SonarQubeRunner: recommended for all non-Maven projects

解压后配置SONAR_RUNNER_HOME、PATH环境变量

修改<install_directory>/conf/sonar-runner.properties

在工程根目录下新建sonar-project.properties

sonar-project.properties

# Required metadata

sonar.projectKey=my:project

sonar.projectName=My project

sonar.projectVersion=1.0

# Path to the parent source code directory.

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.

# Since SonarQube 4.2, this property is optional if sonar.modules is set.

# If not set, SonarQube starts looking for source code from the directory containing

# the sonar-project.properties file.

sonar.sources=src

# Encoding of the source code

sonar.sourceEncoding=UTF-8

# Additional parameters

sonar.my.property=value

 

在工程目录下执行 sonar-runner命令

Maven: recommended for all projects built with Maven

b)    SonarQube Ant Task:to integrate with projects built with Ant

·        Ant1.7.1 or higher

·        Java1.6 or higher

build.xml

<projectname="My Project"default="all"basedir="."xmlns:sonar="antlib:org.sonar.ant">

<!-- Define the SonarQube global properties (the most usual way is to pass these properties via the command line) -->

<propertyname="sonar.jdbc.url"value="jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8"/>

<propertyname="sonar.jdbc.username"value="sonar"/>

<propertyname="sonar.jdbc.password"value="sonar"/>

<!-- Define the SonarQube project properties -->

<propertyname="sonar.projectKey"value="org.codehaus.sonar:example-java-ant"/>

<propertyname="sonar.projectName"value="Simple Java Project analyzed with the SonarQube Ant Task"/>

<propertyname="sonar.projectVersion"value="1.0"/>

<propertyname="sonar.language"value="java"/>

<propertyname="sonar.sources"value="src"/>

<propertyname="sonar.binaries"value="build/*.jar"/>

<!-- Define the SonarQube target -->

<targetname="sonar">

<taskdefuri="antlib:org.sonar.ant"resource="org/sonar/ant/antlib.xml">

<!-- Update the following line, or put the "sonar-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->

<classpath path="path/to/sonar/ant/task/lib/sonar-ant-task-*.jar" />

</taskdef>

<!-- Execute the SonarQube analysis -->

<sonar:sonar/>

</target>

 

Gradle: to integrate with projects built with Gradle

c)    CI Engine:seeJenkins pluginorHudson pluginor Bamboo plugin or AnthillPro plugin. Note that other CI engines can be usedeven if there is no SonarQube plugin available.

http://docs.codehaus.org/display/SONAR/Configuring+SonarQube+Jenkins+Plugin

 

 

5.     sonarqube eclipse插件

http://dist.sonar-ide.codehaus.org/eclipse/

 

 

Sonar支持多种插件,插件的下载地址为:http://docs.codehaus.org/display/SONAR/Plugin+Library

将下载后的插件上传到${SONAR_HOME}extensions\plugins目录下,重新启动sonar。

sonar默认集成了Java Ecosystem插件,该插件是一组插件的合集

1)Java [sonar-java-plugin]:java源代码解析,计算指标等

2)Squid [sonar-squid-java-plugin]:检查违反Sonar定义规则的代码

3)Checkstyle [sonar-checkstyle-plugin]:使用CheckStyle检查违反统一代码编写风格的代码

4)FindBugs [sonar-findbugs-plugin]:使用FindBugs检查违反规则的缺陷代码

5)PMD [sonar-pmd-plugin]:使用pmd检查违反规则的代码

6)Surefire [sonar-surefire-plugin]:使用Surefire执行单元测试

7)Cobertura [sonar-cobertura-plugin]:使用Cobertura获取代码覆盖率

8)JaCoCo [sonar-jacoco-plugin]:使用JaCOCO获取代码覆盖率

下面列出了一些常用的插件:

1)JavaScript代码检查:http://docs.codehaus.org/display/SONAR/JavaScript+Plugin

2)python代码检查:http://docs.codehaus.org/display/SONAR/Python+Plugin

3)Web页面检查(HTML、JSP、JSF、Ruby、PHP等):http://docs.codehaus.org/display/SONAR/Web+Plugin

4)xml文件检查:http://docs.codehaus.org/display/SONAR/XML+Plugin

5)scm源码库统计分析:http://docs.codehaus.org/display/SONAR/SCM+Stats+Plugin

6)文件度量:http://docs.codehaus.org/display/SONAR/Tab+Metrics+Plugin

7)中文语言包:http://docs.codehaus.org/display/SONAR/Chinese+Pack

8)时间表显示度量结果:http://docs.codehaus.org/display/SONAR/Timeline+Plugin

9)度量结果演进图:http://docs.codehaus.org/display/SONAR/Motion+Chart+Plugin

b)插件配置示例(本段内容来自http://www.ibm.com/developerworks/cn/java/j-lo-sonar/)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值