diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2023-05-04 13:41:55 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-05-05 20:03:00 +0000 |
commit | fefcbdcece48719cc98753629d58e79ec480e101 (patch) | |
tree | 196ade3c21b1d2768e8bfc1d2b60fa9a3dbba64e /server/sonar-ce-task-projectanalysis | |
parent | e8508f92ee07959736a4900e7f456fc8b099bd0b (diff) | |
download | sonarqube-fefcbdcece48719cc98753629d58e79ec480e101.tar.gz sonarqube-fefcbdcece48719cc98753629d58e79ec480e101.zip |
SONAR-13362 Do not show a deprecation warning if cross-project duplication is overridden and disabled at project level
Diffstat (limited to 'server/sonar-ce-task-projectanalysis')
2 files changed, 13 insertions, 10 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java index 25ad3067ed7..e9b902642ea 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java @@ -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())); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java index 9e0c7ed63e6..172e6a04e7e 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplicationsTest.java @@ -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)); |