SonarQube没有产生"重复"信息

时间:2015-09-17 14:37:30

标签: maven java-8 sonarqube sonarqube5.1

我使用SonarSource的官方docker镜像设法安装了SonarQube 5.1。

我实际上使用默认的H2数据库运行声纳,我几乎已经为我的演示Java项目做了一些事情:覆盖范围,单元测试和问题。

但重复次数为0%。我用以下代码创建了一个测试类:

public class Test {

public Test() {
    for(int i = 0; i < 10; i++)
    {
        System.out.println("Test");
        System.out.println("Test");
        System.out.println("Test");
    }

    for(int i = 0; i < 10; i++)
    {
        System.out.println("Test");
        System.out.println("Test");
        System.out.println("Test");
    }
}

如何重复0%?我觉得有些东西在我的设置中不起作用......

此外,Sonar在我的班级中发现了一些重大问题,但没有任何与重复相关的内容:

  • 隐藏此公共构造函数
  • 用记录器
  • 替换System.out或System.err的这种用法

为了生成声纳报告,我正在使用maven执行声纳:声纳。这是输出:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building demoservice 0.1.0.-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- sonar-maven-plugin:2.6:sonar (default-cli) @ demoservice ---
[INFO] SonarQube version: 5.1
INFO: Default locale: "en_GB", source code encoding: "UTF-8"
INFO: Work directory: W:\DemoService\target\sonar
INFO: SonarQube Server 5.1
[INFO] [15:52:47.080] Load global repositories
[INFO] [15:52:47.290] Load global repositories (done) | time=212ms
[INFO] [15:52:47.293] Server id: 20150917085707
[INFO] [15:52:47.295] User cache: C:\Users\jose.valencia\.sonar\cache
[INFO] [15:52:47.303] Install plugins
[INFO] [15:52:47.402] Install JDBC driver
[INFO] [15:52:47.412] Create JDBC datasource for jdbc:h2:tcp://localhost:9092/sonar
[INFO] [15:52:48.524] Initializing Hibernate
[INFO] [15:52:50.183] Load project repositories
[INFO] [15:52:51.840] Load project repositories (done) | time=1657ms
[INFO] [15:52:51.841] Load project settings
[INFO] [15:52:52.252] Load technical debt model
[INFO] [15:52:52.285] Apply project exclusions
[INFO] [15:52:53.136] -------------  Scan demoservice
[INFO] [15:52:53.139] Load module settings
[INFO] [15:52:53.238] Language is forced to java
[INFO] [15:52:53.244] Load rules
[INFO] [15:52:53.437] Base dir: W:\DemoService
[INFO] [15:52:53.437] Working dir: W:\DemoService\target\sonar
[INFO] [15:52:53.438] Source paths: pom.xml, src/main/java
[INFO] [15:52:53.438] Test paths: src/test/java
[INFO] [15:52:53.439] Binary dirs: target/classes
[INFO] [15:52:53.439] Source encoding: UTF-8, default locale: en_GB
[INFO] [15:52:53.439] Index files
[INFO] [15:52:53.456] 9 files indexed
[INFO] [15:52:53.642] Quality profile for java: Sonar way
[INFO] [15:52:53.672] Sensor JavaSquidSensor
[INFO] [15:52:55.794] Java Main Files AST scan...
[INFO] [15:52:55.796] 6 source files to be analyzed
[INFO] [15:52:57.434] Java Main Files AST scan done: 1640 ms
[INFO] [15:52:57.435] 6/6 source files have been analyzed
[INFO] [15:52:57.437] Java bytecode scan...
[INFO] [15:52:57.551] Java bytecode scan done: 114 ms
[INFO] [15:52:57.551] Java Test Files AST scan...
[INFO] [15:52:57.552] 3 source files to be analyzed
[INFO] [15:52:58.106] Java Test Files AST scan done: 555 ms
[INFO] [15:52:58.107] 3/3 source files have been analyzed
[INFO] [15:52:58.111] Package design analysis...
[INFO] [15:52:58.164] Package design analysis done: 53 ms
[INFO] [15:52:58.193] Sensor JavaSquidSensor (done) | time=4521ms
[INFO] [15:52:58.193] Sensor Lines Sensor
[INFO] [15:52:58.196] Sensor Lines Sensor (done) | time=3ms
[INFO] [15:52:58.196] Sensor QProfileSensor
[INFO] [15:52:58.201] Sensor QProfileSensor (done) | time=5ms
[INFO] [15:52:58.201] Sensor InitialOpenIssuesSensor
[INFO] [15:52:58.270] Sensor InitialOpenIssuesSensor (done) | time=69ms
[INFO] [15:52:58.270] Sensor ProjectLinksSensor
[INFO] [15:52:58.286] Sensor ProjectLinksSensor (done) | time=16ms
[INFO] [15:52:58.286] Sensor VersionEventsSensor
[INFO] [15:52:58.309] Sensor VersionEventsSensor (done) | time=23ms
[INFO] [15:52:58.309] Sensor Maven dependencies
[INFO] [15:53:01.186] Sensor Maven dependencies (done) | time=2877ms
[INFO] [15:53:01.186] Sensor CoberturaSensor
[INFO] [15:53:01.186] parsing W:\DemoService\target\site\cobertura\coverage.xml
[INFO] [15:53:01.283] Sensor CoberturaSensor (done) | time=97ms
[INFO] [15:53:01.283] Sensor SurefireSensor
[INFO] [15:53:01.284] parsing W:\DemoService\target\surefire-reports
[INFO] [15:53:01.302] Sensor SurefireSensor (done) | time=19ms
[INFO] [15:53:01.302] Sensor SCM Sensor
[INFO] [15:53:01.309] SCM provider for this project is: git
[INFO] [15:53:01.313] 1 files to be analyzed
[INFO] [15:53:01.548] 1/1 files analyzed
[INFO] [15:53:01.549] Sensor SCM Sensor (done) | time=247ms
[INFO] [15:53:01.549] Sensor CPD Sensor
[INFO] [15:53:01.549] JavaCpdEngine is used for java
[INFO] [15:53:01.549] Cross-project analysis disabled
[INFO] [15:53:01.595] Sensor CPD Sensor (done) | time=46ms
[INFO] [15:53:01.596] No quality gate is configured.
[INFO] [15:53:01.642] Compare to previous analysis (2015-09-17)
[INFO] [15:53:01.651] Compare over 30 days (2015-08-18, analysis of Wed Sep 16 17:23:06 BST 2015)
[INFO] [15:53:01.944] Execute decorators...
[INFO] [15:53:02.987] Store results in database
[INFO] [15:53:04.851] Analysis reports generated in 75ms, dir size=8 KB
[INFO] [15:53:04.879] Analysis reports compressed in 28ms, zip size=8 KB
[INFO] [15:53:04.914] Analysis reports sent to server in 35ms
[INFO] [15:53:04.915] ANALYSIS SUCCESSFUL, you can browse http://10.1.2.77:9001/dashboard/index/pbs.demoservice:demoservice
[INFO] [15:53:04.915] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.371s
[INFO] Finished at: Thu Sep 17 15:53:05 BST 2015
[INFO] Final Memory: 37M/896M
[INFO] ------------------------------------------------------------------------

我不确定我是否遗漏了某些东西或者某些东西配置不当。有任何想法吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

我发现了这个问题。对于Java项目,复制检测机制的行为略有不同,因为只要有10个连续语句的相同序列(无论是令牌和行的数量),一段代码就被视为重复。因此,我在Test类中添加了更多重复的循环后,设法看到了重复。