]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6993 Add isCpdEnabled in analysis metadata holder
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 10 Nov 2015 15:12:41 +0000 (16:12 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 12 Nov 2015 10:01:29 +0000 (11:01 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/analysis/AnalysisMetadataHolder.java
server/sonar-server/src/main/java/org/sonar/server/computation/analysis/AnalysisMetadataHolderImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/analysis/MutableAnalysisMetadataHolder.java
server/sonar-server/src/test/java/org/sonar/server/computation/analysis/AnalysisMetadataHolderImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/analysis/MutableAnalysisMetadataHolderRule.java

index fc634054bc81904f432064031bfb550c465c3197..4a78f052c86101e331390e1cb2720e9e6d6bcf65 100644 (file)
@@ -45,4 +45,9 @@ public interface AnalysisMetadataHolder {
   @CheckForNull
   Snapshot getBaseProjectSnapshot();
 
+  /**
+   * @throws IllegalStateException if cross project duplication flag has not been set
+   */
+  boolean isCrossProjectDuplicationEnabled();
+
 }
index a73acbd4adb97869c08a3137868361a7702fc67a..429451abb0c5dc733c1ae9bf2c85c711b03d1867 100644 (file)
@@ -35,6 +35,9 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder
   @CheckForNull
   private Snapshot baseProjectSnapshot;
 
+  @CheckForNull
+  private Boolean isCrossProjectDuplicationEnabled;
+
   @Override
   public void setAnalysisDate(Date date) {
     checkState(analysisDate == null, "Analysis date has already been set");
@@ -66,4 +69,15 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder
     return baseProjectSnapshot;
   }
 
+  @Override
+  public void setIsCrossProjectDuplicationEnabled(boolean isCrossProjectDuplicationEnabled) {
+    checkState(this.isCrossProjectDuplicationEnabled == null, "Cross project duplication flag has already been set");
+    this.isCrossProjectDuplicationEnabled = isCrossProjectDuplicationEnabled;
+  }
+
+  @Override
+  public boolean isCrossProjectDuplicationEnabled() {
+    checkState(isCrossProjectDuplicationEnabled != null, "Cross project duplication flag has not been set");
+    return isCrossProjectDuplicationEnabled;
+  }
 }
index 586d152b237140e11a078f95791a4e235a8ccc7c..5d0b20918b472c1e87545b1a5f594f04223d96d5 100644 (file)
@@ -36,4 +36,9 @@ public interface MutableAnalysisMetadataHolder extends AnalysisMetadataHolder {
    */
   void setBaseProjectSnapshot(@Nullable Snapshot baseProjectSnapshot);
 
+  /**
+   * @throws IllegalStateException if cross project duplication flag has already been set
+   */
+  void setIsCrossProjectDuplicationEnabled(boolean isCrossProjectDuplicationEnabled);
+
 }
index 8cee2f78e20815f12b17625884bbade69147df08..a1925060be78dcb16059c7314716f79d7eb0dad1 100644 (file)
@@ -112,4 +112,40 @@ public class AnalysisMetadataHolderImplTest {
     expectedException.expectMessage("Base project snapshot has already been set");
     underTest.setBaseProjectSnapshot(BASE_PROJECT_SNAPSHOT);
   }
+
+  @Test
+  public void isCrossProjectDuplicationEnabled_return_true() {
+    AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
+
+    underTest.setIsCrossProjectDuplicationEnabled(true);
+
+    assertThat(underTest.isCrossProjectDuplicationEnabled()).isEqualTo(true);
+  }
+
+  @Test
+  public void isCrossProjectDuplicationEnabled_return_false() {
+    AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
+
+    underTest.setIsCrossProjectDuplicationEnabled(false);
+
+    assertThat(underTest.isCrossProjectDuplicationEnabled()).isEqualTo(false);
+  }
+
+  @Test
+  public void isCrossProjectDuplicationEnabled_throws_ISE_when_holder_is_not_initialized() {
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("Cross project duplication flag has not been set");
+
+    new AnalysisMetadataHolderImpl().isCrossProjectDuplicationEnabled();
+  }
+
+  @Test
+  public void setIsCrossProjectDuplicationEnabled_throws_ISE_when_called_twice() {
+    AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
+    underTest.setIsCrossProjectDuplicationEnabled(true);
+
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("Cross project duplication flag has already been set");
+    underTest.setIsCrossProjectDuplicationEnabled(false);
+  }
 }
index f97d3e6b6e27bcfe585e71f7a555673b24bf6de5..476be72f60d16cbd0ee9a9df28d7bdd83e79be04 100644 (file)
@@ -49,6 +49,11 @@ public class MutableAnalysisMetadataHolderRule extends ExternalResource implemen
     return delegate.isFirstAnalysis();
   }
 
+  @Override
+  public void setBaseProjectSnapshot(@Nullable Snapshot baseProjectSnapshot) {
+    delegate.setBaseProjectSnapshot(baseProjectSnapshot);
+  }
+
   @Override
   @CheckForNull
   public Snapshot getBaseProjectSnapshot() {
@@ -56,7 +61,12 @@ public class MutableAnalysisMetadataHolderRule extends ExternalResource implemen
   }
 
   @Override
-  public void setBaseProjectSnapshot(@Nullable Snapshot baseProjectSnapshot) {
-    delegate.setBaseProjectSnapshot(baseProjectSnapshot);
+  public boolean isCrossProjectDuplicationEnabled() {
+    return delegate.isCrossProjectDuplicationEnabled();
+  }
+
+  @Override
+  public void setIsCrossProjectDuplicationEnabled(boolean isCrossProjectDuplicationEnabled) {
+    delegate.setIsCrossProjectDuplicationEnabled(isCrossProjectDuplicationEnabled);
   }
 }