`

Sonar Eclipse 代码覆盖率工具(二)

 
阅读更多


Sonar Eclipse provides a comprehensive Sonar integration for Eclipse. The objective of this Eclipse plugin is that developers do not have to leave their favorite IDE to get valuable information on code quality. Most of the information displayed in the Sonar Web interface is now available in Eclipse.

Installing Sonar Eclipse is pretty simple. For instructions, prerequisites and a demonstration video go to Installing Sonar Eclipse.

Features

  • Get quality measures on resource (project, package and files)
  • Get hotspots on given metrics (files with most duplicated lines, most complex files...)
  • Displays markers on source code upon violation of a coding standard
  • Get comprehensive list of violations on a resource
  • Bridge to Sonar Web server for access additional services (clouds, treemap...)
  • Remote or local mode
  • Track reviews assigned to the current user

Configure Sonar Eclipse

Sonar Eclipse is pre-configured to access local Sonar server listening on http://localhost:9000/. To use an other address, you need first to define this server by using the Eclipse global Preferences window :

Link projects to Sonar server

Once Sonar server is defined, the next step is to "link" eclipse projects with projects defined and analysed in Sonar server(s). This linkage operation can be done by right-clicking on the the project into the "Package explorer", and then by choosing "Configure -> Associate with Sonar..." :


You are now all done with configuration and can start using Sonar Eclipse.

In some cases the eclipse project may not be automatically associated to a Sonar project. If that happens, you need to manually enter the groupId and the artifactId of the Sonar project.
For instance for the following Sonar project http://nemo.sonarsource.org/dashboard/index/org.codehaus.sonar-plugins:sonar-flex-plugin, the groupId is "org.codehaus.sonar-plugins" and the artifactId is "sonar-flex-plugin".

Unlink a project from Sonar server

This operation can be done by right-clicking on the the project into the "Package explorer", and then by choosing "Configure -> Remove Sonar Nature" :

Use Sonar Eclipse

Sonar Eclipse provides one eclipse perspective and four eclipse views. Those eclipse views can of course be used outside the "Sonar" eclipse perspective, but this tutorial describes the default "Sonar" eclipse perspective layout.

To activate the "Sonar" eclipse perspective, click on "Windows -> Open Perspective -> Other ..." and select "Sonar" :

Measures view

The Measures view allows to gather all available measures on the selected ressource. Most of the time, developers focus their attention on only a few metrics like complexity, uncovered lines of code by unit tests, duplicated lines, ... and want to get a quick overview on those metrics. That's why favourite metrics are displayed on the top of the Measures view. Adding or Removing a metric from the favourites list is possible by right clicking on the metric name :

Violations view

The Violations view displays the list of violations to quality rules for the selected ressource :

A double-click on a violation opens the source code editor and highlights the violation :

Once a violation has been fixed, you can simply delete it by clicking on the violation icon and then by selecting the "Delete violation" item. Deleting a violation also removes it from the Violations view :

Hotspots view

The Hotspots view allows to quickly identify hotspots on files according to favourite metrics (defined in the Measures view). You can for instance look at files with the greatest number of duplicated lines, greatest number of violations, greatest number of uncovered lines by unit tests...

Web view

The Web view displays the web Sonar dashboard (for projects and packages) or the web Sonar ressource viewer (for files). This web page can be used to access information and services (cloud, treemap, ...) that are not yet natively available in Sonar Eclipse :

Local analysis

By default Sonar Eclipse takes care to automatically collect information from the Sonar Web server and decorates the source code on-the-fly. This default behavior is pretty useful as it doesn't consume any CPU or memory on the developer's computer while quickly displaying valuable quality information as soon as a new source file is opened. But if lot of source code is modified locally, quality information available remotely might be desynchronized after a while. In that case, a local quality analysis can be run before committing any chances to the source code repository and with the same quality profile used to analyse the project remotely.

Switching from the remote to the local mode can be done by right-clicking on the the project into the "Package explorer", and then by choosing "Configure -> Sonar -> Analyse -> Locally". As soon as this mode is selected a local analysis is launched to update Violations and Measures views.

Later, at any time, you can run a new local analysis by choosing "Configure -> Sonar -> Run Local Analysis. 

Be Careful
Even in local mode, the Hotspots and Web views still display remote data.

Reviews

Feature available since Sonar Eclipse 2.1

A Sonar Mylyn connector allows to track all open reviews assigned to the current user. To start using this feature, a new Sonar task repository and a query to get all reviews assigned to the current user must be first created (see the Mylyn documentation page) :

Then the "Task List" view must be used to start working on all those assigned reviews :


From there, double clicking on a review open the detail of that review :

All operations on reviews available through the Sonar web interface are also available in Mylyn, so a review can be commented, fixed, reassigned, flagged as false-positive and reopened. Moreover a review can be created directly from the Eclipse source code editor on an existing violation  : 
 This Mylyn extension has currently the following limitations that should be quickly fixed

  • There is no way to create a review that doesn't relate to an existing violation
  • There is no way to create a Mylyn query with filters in order for instance to retrieve reviews only on a project, or reviews assigned to another user 
分享到:
评论

相关推荐

    sonar-eclipse-plugin

    - **代码指标**:展示代码的复杂性、重复度、覆盖率等关键指标,帮助理解代码健康状况。 - **个性化配置**:可以根据团队需求调整分析规则,定制自己的代码质量标准。 **3. 安装与配置** 安装Sonar Eclipse Plugin...

    jenkins集成jacoco获取代码覆盖率.docx

    JaCoCo,全称Java Code Coverage Library,是一个专为Java开发的开源覆盖率工具。JaCoCo能够提供详尽的代码覆盖率报告,帮助开发者评估他们的测试覆盖率,确保代码的健壮性和质量。它可以通过多种方式进行集成,包括...

    sonar安装及使用(1).pdf

    Sonar 是一个强大的静态代码分析和代码质量管理工具,主要用于检测代码中的潜在缺陷、代码异味、重复片段、单元测试覆盖率等问题,以提升代码质量和遵循编码规范。Sonar 不仅仅是一个插件,它是一个完整的平台,包括...

    Sonar实战资料

    - **全方位的代码质量管理**:Sonar不仅支持静态代码分析,还支持动态分析,如单元测试覆盖率检查等,确保代码质量从多个维度得到保障。 - **灵活的集成方式**:Sonar可以作为Web客户端或者Eclipse插件使用,并且...

    sonar-runner-1.0下载

    6. **报告和度量**:SonarRunner会生成详细的报告,包括代码覆盖率、复杂性、重复代码等关键指标,这些信息有助于团队理解代码的健康状况并作出改进决策。 7. **插件机制**:SonarRunner允许扩展,通过安装额外的...

    持续集成环境下运行单元测试和代码校验详细过程

    - **Sonar 仪表盘**:Sonar 的仪表盘展示了项目的整体质量概况,包括代码覆盖率、漏洞、代码复杂度等关键指标。通过这些信息,团队可以快速了解项目的健康状况。 此外,为了在开发过程中实时获取代码质量反馈,我们...

    sonarqube版本7.7代码质量分析工具下载即用

    4. **度量标准**:SonarQube引入了一系列度量标准,如代码覆盖率、复杂度、重复代码、技术债务等,这些度量可以帮助开发者理解代码的健康状况,并为改进提供依据。 5. **用户界面与报告**:SonarQube 7.7拥有直观的...

    Java持续集成工具.doc

    10. **Emma, Clover**: 这些代码覆盖率工具测量单元测试覆盖了多少源代码,帮助确定测试的完整性。 11. **JAVANCSS**: 用于度量代码的复杂度,帮助识别可能难以理解和维护的代码段。 12. **JDepend**: JDepend度量...

    sonarqube7.4配置完整开箱即用附带maven配置

    SonarQube不仅关注代码质量,还支持集成单元测试结果,以评估代码覆盖率。通过配置Maven插件(如`maven-surefire-plugin`和`maven-failsafe-plugin`),可以将JUnit或其他测试框架的结果引入SonarQube分析。此外,...

    SonarQube使用手册.zip

    SonarQube提供了Web界面,允许用户查看项目的质量报告,包括代码覆盖率、技术债务、新发现的问题等指标。用户可以设置质量门限,当某个项目不符合设定标准时,SonarQube会发出警告,阻止代码提交或发布。此外,还...

    最新版windows sonarqube-8.2.0.32929.zip

    2. **度量标准**:SonarQube提供了一套全面的代码质量度量,包括代码复杂性、单元测试覆盖率、技术债务等。这些度量可以帮助团队了解项目的整体健康状况,并设定改进目标。 3. **规则定制**:SonarQube允许用户根据...

    SonarQube代码质量管理平台的配置与使用

    指标是衡量代码质量的关键,SonarQube提供了丰富的指标,如代码覆盖率、复杂度、重复代码等,这些指标有助于量化和追踪代码质量的改善。 最后,仪表盘是SonarQube的可视化工具,允许用户自定义展示项目的关键指标和...

    windos版本的sonarqube-7.8.rar

    - 结果展示:分析完成后,SonarQube服务器会显示项目质量报告,包括问题列表、代码覆盖率、技术债务等指标。 - 规则定制:用户可以根据需要自定义质量标准,例如修改规则的严重级别,或创建新的规则。 4. **集成...

    ResponseTimeTool:适用于iOS和Android的响应时间测试工具

    1.6+ Eclipse:Luna Service Release 2(4.4.2)+ Gradle:2.4+ 编码:UTF-8 测试NG 哈科科声纳奔跑者Log4j贡献代码git clone 导入EclipseGradle干净的Eclipse构建Test-TestNG gradle clean test 代码覆盖率-...

    Sonarqube+jenkins持续集成

    6. 运行分析:当Jenkins作业被触发时,SonarQube Scanner会执行代码分析,结果会展示在SonarQube界面上,包括代码质量问题、覆盖率等指标。 7. 结果反馈:开发者可以在SonarQube中查看分析报告,对发现的问题进行...

    javasonarqube

    SonarQube是一款开源平台,它提供了一整套的代码质量管理解决方案,包括静态代码分析、代码复杂度计算、单元测试覆盖率报告以及代码异味检测等。通过SonarQube,开发者可以定期对项目进行全面的代码审查,找出潜在的...

    sonarqube-5.1.2

    3. **度量指标**:SonarQube提供了丰富的度量指标,如代码复杂度、单元测试覆盖率、重复代码比例等,这些指标有助于量化项目的质量状况。 4. **历史追踪**:系统记录了每次分析的结果,用户可以查看代码质量随时间...

Global site tag (gtag.js) - Google Analytics