]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13362 Do not show a deprecation warning if cross-project duplication is overrid...
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 4 May 2023 18:41:55 +0000 (13:41 -0500)
committersonartech <sonartech@sonarsource.com>
Fri, 5 May 2023 20:03:00 +0000 (20:03 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java

index 25ad3067ed799579ded7c1969251e6d0dca9bcf4..e9b902642ea426c95caf87953f56435964eac75f 100644 (file)
@@ -26,7 +26,6 @@ import java.util.Map;
 import java.util.function.Function;
 import java.util.function.Predicate;
 import javax.annotation.Nonnull;
-import org.sonar.api.CoreProperties;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.log.Logger;
@@ -56,12 +55,13 @@ public class IntegrateCrossProjectDuplications {
   private final Configuration config;
   private final DuplicationRepository duplicationRepository;
 
-  private Map<String, NumberOfUnitsNotLessThan> numberOfUnitsByLanguage = new HashMap<>();
+  private final Map<String, NumberOfUnitsNotLessThan> numberOfUnitsByLanguage = new HashMap<>();
 
-  public IntegrateCrossProjectDuplications(Configuration config, DuplicationRepository duplicationRepository, CeTaskMessages ceTaskMessages, System2 system) {
+  public IntegrateCrossProjectDuplications(CrossProjectDuplicationStatusHolder crossProjectDuplicationStatusHolder, Configuration config,
+    DuplicationRepository duplicationRepository, CeTaskMessages ceTaskMessages, System2 system) {
     this.config = config;
     this.duplicationRepository = duplicationRepository;
-    if (config.getBoolean(CoreProperties.CPD_CROSS_PROJECT).orElse(false)) {
+    if (crossProjectDuplicationStatusHolder.isEnabled()) {
       LOGGER.warn(DEPRECATED_WARNING);
       ceTaskMessages.add(new CeTaskMessages.Message(DEPRECATED_WARNING_DASHBOARD, system.now()));
     }
index 9e0c7ed63e6e978cd621483842db751800add1fa..172e6a04e7e3037924abfdd875a90494e42ce0b2 100644 (file)
@@ -42,6 +42,7 @@ import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
 import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
 
@@ -59,10 +60,12 @@ public class IntegrateCrossProjectDuplicationsTest {
   @Rule
   public DuplicationRepositoryRule duplicationRepository = DuplicationRepositoryRule.create();
 
-  private TestSystem2 system = new TestSystem2();
-  private MapSettings settings = new MapSettings();
-  private CeTaskMessages ceTaskMessages = mock(CeTaskMessages.class);
-  private IntegrateCrossProjectDuplications underTest = new IntegrateCrossProjectDuplications(settings.asConfig(), duplicationRepository, ceTaskMessages, system);
+  private final TestSystem2 system = new TestSystem2();
+  private final MapSettings settings = new MapSettings();
+  private final CeTaskMessages ceTaskMessages = mock(CeTaskMessages.class);
+  private final CrossProjectDuplicationStatusHolder crossProjectDuplicationStatusHolder = mock(CrossProjectDuplicationStatusHolder.class);
+  private final IntegrateCrossProjectDuplications underTest = new IntegrateCrossProjectDuplications(crossProjectDuplicationStatusHolder, settings.asConfig(),
+    duplicationRepository, ceTaskMessages, system);
 
   @Test
   public void add_duplications_from_two_blocks() {
@@ -336,10 +339,10 @@ public class IntegrateCrossProjectDuplicationsTest {
 
   @Test
   public void log_warning_if_this_deprecated_feature_is_enabled() {
-    settings.setProperty("sonar.cpd.cross_project", "true");
+    when(crossProjectDuplicationStatusHolder.isEnabled()).thenReturn(true);
     system.setNow(1000L);
 
-    new IntegrateCrossProjectDuplications(settings.asConfig(), duplicationRepository, ceTaskMessages, system);
+    new IntegrateCrossProjectDuplications(crossProjectDuplicationStatusHolder, settings.asConfig(), duplicationRepository, ceTaskMessages, system);
 
     assertThat(logTester.logs()).containsExactly("This analysis uses the deprecated cross-project duplication feature.");
     verify(ceTaskMessages).add(new CeTaskMessages.Message("This project uses the deprecated cross-project duplication feature.", 1000L));