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;
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()));
}
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;
@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() {
@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));