]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 do not save resource when adding a measure
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 10 Feb 2014 17:14:37 +0000 (18:14 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 10 Feb 2014 17:14:49 +0000 (18:14 +0100)
sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java

index 1fd9d4178c59c52659ce119f14b6991b85308d7d..3858fadfe529bc2fce702ecc13be40a3df68363b 100644 (file)
@@ -44,6 +44,8 @@ import org.sonar.batch.issue.ModuleIssues;
 import org.sonar.core.component.ComponentKeys;
 import org.sonar.core.component.ScanGraph;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import java.util.*;
 
 public class DefaultIndex extends SonarIndex {
@@ -178,7 +180,7 @@ public class DefaultIndex extends SonarIndex {
    */
   @Override
   public Measure addMeasure(Resource resource, Measure measure) {
-    Bucket bucket = checkIndexed(resource);
+    Bucket bucket = getBucket(resource);
     if (bucket != null) {
       Metric metric = metricFinder.findByKey(measure.getMetricKey());
       if (metric == null) {
@@ -430,7 +432,7 @@ public class DefaultIndex extends SonarIndex {
 
   @Override
   public void setSource(Resource reference, String source) {
-    Bucket bucket = checkIndexed(reference);
+    Bucket bucket = getBucket(reference);
     if (bucket != null) {
       persistence.setSource(reference, source);
     }
@@ -451,7 +453,8 @@ public class DefaultIndex extends SonarIndex {
   }
 
   @Override
-  public <R extends Resource> R getResource(R reference) {
+  @CheckForNull
+  public <R extends Resource> R getResource(@Nullable R reference) {
     Bucket bucket = getBucket(reference);
     if (bucket != null) {
       return (R) bucket.getResource();
@@ -559,7 +562,7 @@ public class DefaultIndex extends SonarIndex {
     return getBucket(reference, acceptExcluded) != null;
   }
 
-  private Bucket getBucket(Resource resource, boolean acceptExcluded) {
+  private Bucket getBucket(@Nullable Resource resource, boolean acceptExcluded) {
     Bucket bucket = null;
     if (resource != null) {
       bucket = getBucket(resource);
index dd5da90948d3cb0189075c41bddf53c1804b3e3c..82a317aa6c15a8a24684db1060a0a2dcc2fa6df4 100644 (file)
@@ -146,12 +146,12 @@ public class DefaultIndexTest {
   }
 
   @Test
-  public void shouldIndexResourceWhenAddingMeasure() {
+  public void shouldNotIndexResourceWhenAddingMeasure() {
     Resource dir = Directory.create("src/org/foo", "org/foo");
     index.addMeasure(dir, new Measure("ncloc").setValue(50.0));
 
-    assertThat(index.isIndexed(dir, true)).isTrue();
-    assertThat(index.getMeasures(dir, MeasuresFilters.metric("ncloc")).getIntValue()).isEqualTo(50);
+    assertThat(index.isIndexed(dir, true)).isFalse();
+    assertThat(index.getMeasures(dir, MeasuresFilters.metric("ncloc"))).isNull();
   }
 
   /**