]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 3 Oct 2014 13:04:28 +0000 (15:04 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Fri, 3 Oct 2014 13:09:16 +0000 (15:09 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan2/AnalysisPublisher.java
sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultIssueValueCoder.java
sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultSensorContext.java
sonar-batch/src/main/java/org/sonar/batch/scm/ScmConfiguration.java
sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
sonar-batch/src/main/java/org/sonar/batch/test/DefaultTestCaseValueCoder.java

index 1dad931f8b577e303d897ea0661b8ae76c5b5d31..f5596acbb52cad3cedd5ace723562aec17124f61 100644 (file)
@@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputPath;
 import org.sonar.api.batch.sensor.issue.Issue;
 import org.sonar.api.batch.sensor.issue.Issue.Severity;
 import org.sonar.api.batch.sensor.measure.Measure;
@@ -104,8 +105,9 @@ public final class AnalysisPublisher {
         jsonWriter.beginObject()
           .prop("repository", issue.ruleKey().repository())
           .prop("rule", issue.ruleKey().rule());
-        if (issue.inputPath() != null) {
-          jsonWriter.prop("path", issue.inputPath().relativePath());
+        InputPath inputPath = issue.inputPath();
+        if (inputPath != null) {
+          jsonWriter.prop("path", inputPath.relativePath());
         }
         jsonWriter.prop("message", issue.message())
           .prop("effortToFix", issue.effortToFix())
index 61ce8f9166fd83476c25b9d8e5f3de4bbcdde898..53b7cb34b056f5ad619e734bab5efc196078b41f 100644 (file)
@@ -73,7 +73,7 @@ class DefaultIssueValueCoder implements ValueCoder {
 
   @Override
   public Object get(Value value, Class clazz, CoderContext context) {
-    DefaultIssue newIssue = new DefaultIssue(null);
+    DefaultIssue newIssue = new DefaultIssue();
     newIssue.withKey(value.getString());
     if (value.isNull(true)) {
       newIssue.onProject();
index 486c241f7a2e1919db6368383a07b97920d1e672..dff662a8f9e08d471dcb4d7f17a47e82826edb47 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.InputFile.Type;
+import org.sonar.api.batch.fs.InputPath;
 import org.sonar.api.batch.measure.Metric;
 import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.rule.internal.DefaultActiveRule;
@@ -123,8 +124,9 @@ public class DefaultSensorContext extends BaseSensorContext {
   @Override
   public void store(Issue issue) {
     String resourceKey;
-    if (issue.inputPath() != null) {
-      resourceKey = ComponentKeys.createEffectiveKey(def.getKey(), issue.inputPath());
+    InputPath inputPath = issue.inputPath();
+    if (inputPath != null) {
+      resourceKey = ComponentKeys.createEffectiveKey(def.getKey(), inputPath);
     } else {
       resourceKey = def.getKey();
     }
index fd96308fa4345df6bc6af2c88463894bab56a593..c9ed4ecb653cf6112c49e3c0ab12111441a054d4 100644 (file)
@@ -70,6 +70,8 @@ public final class ScmConfiguration implements BatchComponent, Startable {
       autodetection();
       if (this.provider == null) {
         considerOldScmUrl();
+      }
+      if (this.provider == null) {
         LOG.warn("SCM provider autodetection failed. No SCM provider claims to support this project. Please use " + CoreProperties.SCM_PROVIDER_KEY
           + " to define SCM of your project.");
       }
@@ -99,12 +101,12 @@ public final class ScmConfiguration implements BatchComponent, Startable {
   }
 
   private void autodetection() {
-    for (ScmProvider provider : providerPerKey.values()) {
-      if (provider.supports(projectReactor.getRoot().getBaseDir())) {
+    for (ScmProvider installedProvider : providerPerKey.values()) {
+      if (installedProvider.supports(projectReactor.getRoot().getBaseDir())) {
         if (this.provider == null) {
-          this.provider = provider;
+          this.provider = installedProvider;
         } else {
-          throw new IllegalStateException("SCM provider autodetection failed. Both " + this.provider.key() + " and " + provider.key()
+          throw new IllegalStateException("SCM provider autodetection failed. Both " + this.provider.key() + " and " + installedProvider.key()
             + " claim to support this project. Please use " + CoreProperties.SCM_PROVIDER_KEY + " to define SCM of your project.");
         }
       }
@@ -121,7 +123,7 @@ public final class ScmConfiguration implements BatchComponent, Startable {
 
   @Override
   public void stop() {
-
+    // Nothing to do
   }
 
 }
index 4485407e9e34e349bd2662ca9ffcb9bdd96c78ff..e3de5aa41d1a52d27c0b6618e69f29d875374caf 100644 (file)
@@ -79,16 +79,7 @@ public final class ScmSensor implements Sensor {
 
     List<InputFile> filesToBlame = new LinkedList<InputFile>();
     for (InputFile f : fs.inputFiles(fs.predicates().all())) {
-      FileData fileData = projectReferentials.fileData(projectDefinition.getKeyWithBranch(), f.relativePath());
-      if (f.status() == Status.SAME
-        && fileData != null
-        && fileData.scmAuthorsByLine() != null
-        && fileData.scmLastCommitDatetimesByLine() != null
-        && fileData.scmRevisionsByLine() != null) {
-        saveMeasures(context, f, fileData.scmAuthorsByLine(), fileData.scmLastCommitDatetimesByLine(), fileData.scmRevisionsByLine());
-      } else {
-        filesToBlame.add(f);
-      }
+      copyPreviousMeasuresForUnmodifiedFiles(context, filesToBlame, f);
     }
     if (!filesToBlame.isEmpty()) {
       LOG.info("SCM provider for this project is: " + configuration.provider().key());
@@ -98,6 +89,25 @@ public final class ScmSensor implements Sensor {
     }
   }
 
+  private void copyPreviousMeasuresForUnmodifiedFiles(final SensorContext context, List<InputFile> filesToBlame, InputFile f) {
+    FileData fileData = projectReferentials.fileData(projectDefinition.getKeyWithBranch(), f.relativePath());
+
+    if (f.status() == Status.SAME && fileData != null) {
+      String scmAuthorsByLine = fileData.scmAuthorsByLine();
+      String scmLastCommitDatetimesByLine = fileData.scmLastCommitDatetimesByLine();
+      String scmRevisionsByLine = fileData.scmRevisionsByLine();
+      if (scmAuthorsByLine != null
+        && scmLastCommitDatetimesByLine != null
+        && scmRevisionsByLine != null) {
+        saveMeasures(context, f, scmAuthorsByLine, scmLastCommitDatetimesByLine, scmRevisionsByLine);
+      } else {
+        filesToBlame.add(f);
+      }
+    } else {
+      filesToBlame.add(f);
+    }
+  }
+
   /**
    * This method is synchronized since it is allowed for plugins to compute blame in parallel.
    */
index 727b14efb8f10486536b8df0d287b8538c5c64c4..88b5de896d9f4ddb08ef1817f9949d384ec1bef3 100644 (file)
@@ -72,7 +72,7 @@ class DefaultTestCaseValueCoder implements ValueCoder {
     long duration = value.getLong();
     TestCase.Type type = TestCase.Type.values()[value.getInt()];
     TestCase.Status status = TestCase.Status.values()[value.getInt()];
-    return new DefaultTestCase(null)
+    return new DefaultTestCase()
       .inTestFile(testFile)
       .ofType(type)
       .name(name)