]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5473 Added missing "needBlame" field in project referential
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 13 Jan 2015 15:26:54 +0000 (16:26 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 13 Jan 2015 15:32:51 +0000 (16:32 +0100)
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/FileData.java
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java
sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/StatusDetectionTest.java

index fc7e7beca02ebf61ce21ff013f32fbd0fa003c1d..d68bcbd3c61abbaf207c1321e078461436f1a781 100644 (file)
@@ -25,12 +25,14 @@ import javax.annotation.Nullable;
 public class FileData {
 
   private final String hash;
+  private final boolean needBlame;
   private final String scmLastCommitDatetimesByLine;
   private final String scmRevisionsByLine;
   private final String scmAuthorsByLine;
 
-  public FileData(@Nullable String hash, @Nullable String scmLastCommitDatetimesByLine, @Nullable String scmRevisionsByLine, @Nullable String scmAuthorsByLine) {
+  public FileData(@Nullable String hash, boolean needBlame, @Nullable String scmLastCommitDatetimesByLine, @Nullable String scmRevisionsByLine, @Nullable String scmAuthorsByLine) {
     this.hash = hash;
+    this.needBlame = needBlame;
     this.scmLastCommitDatetimesByLine = scmLastCommitDatetimesByLine;
     this.scmRevisionsByLine = scmRevisionsByLine;
     this.scmAuthorsByLine = scmAuthorsByLine;
@@ -41,6 +43,10 @@ public class FileData {
     return hash;
   }
 
+  public boolean needBlame() {
+    return needBlame;
+  }
+
   @CheckForNull
   public String scmLastCommitDatetimesByLine() {
     return scmLastCommitDatetimesByLine;
index 12cdedcb4cec0085a0c5d351260df40ac843c551..348fcd8187fe1cbf66be1706521f8080b665cbda 100644 (file)
@@ -49,8 +49,8 @@ public class ProjectReferentialsTest {
     ref.addActiveRule(activeRule);
     ref.setLastAnalysisDate(new SimpleDateFormat("dd/MM/yyyy").parse("31/10/2014"));
     ref.setTimestamp(10);
-    ref.addFileData("foo", "src/main/java/Foo.java", new FileData("xyz", "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin"));
-    ref.addFileData("foo", "src/main/java/Foo2.java", new FileData("xyz", "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin"));
+    ref.addFileData("foo", "src/main/java/Foo.java", new FileData("xyz", true, "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin"));
+    ref.addFileData("foo", "src/main/java/Foo2.java", new FileData("xyz", false, "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin"));
 
     JSONAssert
       .assertEquals(
@@ -58,8 +58,8 @@ public class ProjectReferentialsTest {
           + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"1984-03-14T00:00:00+0100\"}},"
           + "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule,language:java,params:{param1:value1}}],"
           + "settingsByModule:{foo:{prop1:value1,prop2:value2,prop:value}},"
-          + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"},"
-          + "\"src/main/java/Foo2.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}},"
+          + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,needBlame:true,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"},"
+          + "\"src/main/java/Foo2.java\":{hash:xyz,needBlame:false,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}},"
           + "lastAnalysisDate:\"2014-10-31T00:00:00+0100\"}",
         ref.toJson(), true);
   }
@@ -71,7 +71,7 @@ public class ProjectReferentialsTest {
         + "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"1984-03-14T00:00:00+0100\"}},"
         + "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule1,language:java,params:{param1:value1}}],"
         + "settingsByModule:{foo:{prop:value}},"
-        + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}},"
+        + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,needBlame:true,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}},"
         + "lastAnalysisDate:\"2014-10-31T00:00:00+0100\"}");
 
     assertThat(ref.timestamp()).isEqualTo(1);
@@ -94,6 +94,7 @@ public class ProjectReferentialsTest {
     assertThat(ref.fileData("foo2", "src/main/java/Foo3.java")).isNull();
 
     assertThat(ref.fileData("foo", "src/main/java/Foo.java").hash()).isEqualTo("xyz");
+    assertThat(ref.fileData("foo", "src/main/java/Foo.java").needBlame()).isTrue();
     assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmAuthorsByLine()).isEqualTo("1=henryju,2=gaudin");
     assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmLastCommitDatetimesByLine()).isEqualTo("1=12345,2=3456");
     assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmRevisionsByLine()).isEqualTo("1=345,2=345");
index 78f085c3541574b98db4ae2eeb844dfeb164cdff..cfae1f932764d52654e3c9a6c50c493331a67b29 100644 (file)
@@ -110,7 +110,7 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad
               authors = ((MeasureModel) measureByKey[1]).getData(CoreMetrics.SCM_AUTHORS_BY_LINE);
             }
           }
-          ref.addFileData(module.getKeyWithBranch(), path, new FileData(hash, lastCommits, revisions, authors));
+          ref.addFileData(module.getKeyWithBranch(), path, new FileData(hash, authors == null, lastCommits, revisions, authors));
         }
       }
       ref.setLastAnalysisDate(lastSnapshotCreationDate(projectKey));
index 445fd2bf39e21e2f41d91ee505e6c4171884bc9e..bbfcbdaa6f19aa0b6d691b7fc5bf6824dacfa145 100644 (file)
@@ -95,15 +95,18 @@ public final class ScmSensor implements Sensor {
     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 {
+      if (fileData.needBlame()) {
         filesToBlame.add(f);
+      } else {
+        // Copy previous measures
+        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);
index 4e93f7d5210a5fc1da471b3d9c30f8e2f59e5795..df3a94ce132689f11f6965005441ceccdd00f495 100644 (file)
@@ -30,8 +30,8 @@ public class StatusDetectionTest {
   @Test
   public void detect_status() throws Exception {
     ProjectReferentials ref = new ProjectReferentials();
-    ref.addFileData("foo", "src/Foo.java", new FileData("ABCDE", null, null, null));
-    ref.addFileData("foo", "src/Bar.java", new FileData("FGHIJ", null, null, null));
+    ref.addFileData("foo", "src/Foo.java", new FileData("ABCDE", true, null, null, null));
+    ref.addFileData("foo", "src/Bar.java", new FileData("FGHIJ", true, null, null, null));
     StatusDetection statusDetection = new StatusDetection(ref);
 
     assertThat(statusDetection.status("foo", "src/Foo.java", "ABCDE")).isEqualTo(InputFile.Status.SAME);