]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 3 Nov 2014 14:59:10 +0000 (15:59 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 3 Nov 2014 14:59:10 +0000 (15:59 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingResult.java
plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooScmProvider.java
sonar-batch/src/main/java/org/sonar/batch/util/ProgressReport.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/scm/ScmMediumTest.java

index dd69da8e23c08e693a97adc023a957fb05d50ea3..68e24d97baebef4c9d67ccdd5188af2e23be1534 100644 (file)
@@ -87,8 +87,7 @@ class IssueTrackingResult {
     }
     unmatchedByRuleAndKey.get(ruleKey).put(i.getKee(), i);
     Map<Integer, Multimap<String, IssueDto>> unmatchedForRule = unmatchedByRuleAndLineAndChecksum.get(ruleKey);
-    Integer line = i.getLine();
-    Integer lineNotNull = line != null ? line : 0;
+    Integer lineNotNull = lineNotNull(i);
     if (!unmatchedForRule.containsKey(lineNotNull)) {
       unmatchedForRule.put(lineNotNull, HashMultimap.<String, IssueDto>create());
     }
@@ -97,12 +96,18 @@ class IssueTrackingResult {
     unmatchedForRuleAndLine.put(checksumNotNull, i);
   }
 
+  private Integer lineNotNull(IssueDto i) {
+    Integer line = i.getLine();
+    Integer lineNotNull = line != null ? line : 0;
+    return lineNotNull;
+  }
+
   void setMatch(DefaultIssue issue, IssueDto matching) {
     matched.put(issue, matching);
     RuleKey ruleKey = RuleKey.of(matching.getRuleRepo(), matching.getRule());
     unmatchedByRuleAndKey.get(ruleKey).remove(matching.getKee());
     unmatchedByKey.remove(matching.getKee());
-    Integer lineNotNull = matching.getLine() != null ? matching.getLine() : 0;
+    Integer lineNotNull = lineNotNull(matching);
     String checksumNotNull = StringUtils.defaultString(matching.getChecksum(), "");
     unmatchedByRuleAndLineAndChecksum.get(ruleKey).get(lineNotNull).get(checksumNotNull).remove(matching);
   }
index 5807d8200431cf9596f7b80a80e3b1ca21d4b9e3..1dbcb2c04fdca006c37e643efd37f126c2ba3829 100644 (file)
@@ -22,6 +22,8 @@ package org.sonar.xoo.scm;
 import org.sonar.api.batch.scm.BlameCommand;
 import org.sonar.api.batch.scm.ScmProvider;
 
+import java.io.File;
+
 public class XooScmProvider extends ScmProvider {
 
   private final XooBlameCommand blame;
@@ -30,6 +32,11 @@ public class XooScmProvider extends ScmProvider {
     this.blame = blame;
   }
 
+  @Override
+  public boolean supports(File baseDir) {
+    return new File(baseDir, ".xoo").exists();
+  }
+
   @Override
   public String key() {
     return "xoo";
index 80be1cead2eb73e55b0ccd53aca62dc0f8a2ad54..0409a99e119c88e62eb3d556de02e17b75f21ab3 100644 (file)
@@ -24,23 +24,18 @@ import org.slf4j.LoggerFactory;
 
 public class ProgressReport implements Runnable {
 
+  private static final Logger LOG = LoggerFactory.getLogger(ProgressReport.class);
   private final long period;
-  private final Logger logger;
   private String message = "";
   private final Thread thread;
   private String stopMessage = "";
 
-  public ProgressReport(String threadName, long period, Logger logger) {
+  public ProgressReport(String threadName, long period) {
     this.period = period;
-    this.logger = logger;
     thread = new Thread(this);
     thread.setName(threadName);
   }
 
-  public ProgressReport(String threadName, long period) {
-    this(threadName, period, LoggerFactory.getLogger(ProgressReport.class));
-  }
-
   @Override
   public void run() {
     while (!Thread.interrupted()) {
@@ -73,9 +68,9 @@ public class ProgressReport implements Runnable {
   }
 
   private void log(String message) {
-    synchronized (logger) {
-      logger.info(message);
-      logger.notifyAll();
+    synchronized (LOG) {
+      LOG.info(message);
+      LOG.notifyAll();
     }
   }
 
index 1c3b4209e515a97d5700d7293f1ccb78a5778142..775c52004ceb37a1f467111d5578a716c6f3f993 100644 (file)
@@ -150,6 +150,37 @@ public class ScmMediumTest {
       .withValue("1=;2=julien;3=julien;4=julien;5=simon"));
   }
 
+  @Test
+  public void testAutoDetection() throws IOException {
+
+    File baseDir = prepareProject();
+    new File(baseDir, ".xoo").createNewFile();
+
+    TaskResult result = tester.newTask()
+      .properties(ImmutableMap.<String, String>builder()
+        .put("sonar.task", "scan")
+        .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+        .put("sonar.projectKey", "com.foo.project")
+        .put("sonar.projectName", "Foo Project")
+        .put("sonar.projectVersion", "1.0-SNAPSHOT")
+        .put("sonar.projectDescription", "Description of Foo Project")
+        .put("sonar.sources", "src")
+        .build())
+      .start();
+
+    assertThat(result.measures()).hasSize(4);
+
+    assertThat(result.measures()).contains(new DefaultMeasure<Integer>()
+      .forMetric(CoreMetrics.LINES)
+      .onFile(new DefaultInputFile("com.foo.project", "src/sample.xoo"))
+      .withValue(5));
+
+    assertThat(result.measures()).contains(new DefaultMeasure<String>()
+      .forMetric(CoreMetrics.SCM_AUTHORS_BY_LINE)
+      .onFile(new DefaultInputFile("com.foo.project", "src/sample.xoo"))
+      .withValue("1=;2=julien;3=julien;4=julien;5=simon"));
+  }
+
   private File prepareProject() throws IOException {
     File baseDir = temp.newFolder();
     File srcDir = new File(baseDir, "src");