From: Julien HENRY Date: Mon, 29 Aug 2016 13:34:48 +0000 (+0200) Subject: SONAR-5813 Fully drop support of "sonar.cpd.xxx.skip" properties X-Git-Tag: 6.1-RC1~274 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1184%2Fhead;p=sonarqube.git SONAR-5813 Fully drop support of "sonar.cpd.xxx.skip" properties --- diff --git a/it/it-tests/src/test/java/it/analysisExclusion/IssueExclusionsTest.java b/it/it-tests/src/test/java/it/analysisExclusion/IssueExclusionsTest.java index 408ad2a2d18..2103ed3f7a4 100644 --- a/it/it-tests/src/test/java/it/analysisExclusion/IssueExclusionsTest.java +++ b/it/it-tests/src/test/java/it/analysisExclusion/IssueExclusionsTest.java @@ -239,9 +239,9 @@ public class IssueExclusionsTest { orchestrator.getServer().associateProjectToQualityProfile("com.sonarsource.it.samples:multi-modules-exclusions", "xoo", "with-many-rules"); SonarScanner scan = SonarScanner.create(ItUtils.projectDir(PROJECT_DIR)) - .setProperties("sonar.cpd.skip", "true") + .setProperty("sonar.cpd.exclusions", "**/*") .setProperties(properties) - .setProperties("sonar.verbose", "true"); + .setProperty("sonar.verbose", "true"); return orchestrator.executeBuildQuietly(scan); } diff --git a/it/it-tests/src/test/java/it/projectAdministration/ProjectAdministrationTest.java b/it/it-tests/src/test/java/it/projectAdministration/ProjectAdministrationTest.java index f9863aa85b4..50a3f12b3b4 100644 --- a/it/it-tests/src/test/java/it/projectAdministration/ProjectAdministrationTest.java +++ b/it/it-tests/src/test/java/it/projectAdministration/ProjectAdministrationTest.java @@ -198,7 +198,7 @@ public class ProjectAdministrationTest { private void scanSample(@Nullable String date, @Nullable String profile) { SonarScanner scan = SonarScanner.create(projectDir("shared/xoo-sample")) - .setProperties("sonar.cpd.skip", "true"); + .setProperty("sonar.cpd.exclusions", "**/*"); if (date != null) { scan.setProperty("sonar.projectDate", date); } diff --git a/it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java b/it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java index facf950e78e..399399a49f5 100644 --- a/it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java +++ b/it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java @@ -135,7 +135,7 @@ public class QualityGateUiTest { private void scanSample(@Nullable String date, @Nullable String profile) { SonarScanner scan = SonarScanner.create(projectDir("shared/xoo-sample")) - .setProperties("sonar.cpd.skip", "true"); + .setProperty("sonar.cpd.exclusions", "**/*"); if (date != null) { scan.setProperty("sonar.projectDate", date); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 76d5ae24ca5..3960bb7054b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -225,13 +225,6 @@ public interface CoreProperties { /* CPD */ String CPD_PLUGIN = "cpd"; - /** - * @deprecated in 5.0 - * @see SONAR-5339 - */ - @Deprecated - String CPD_SKIP_PROPERTY = "sonar.cpd.skip"; - /** * @since 2.11 */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java index 20db6a92e5e..16d8be19e08 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java @@ -54,28 +54,15 @@ public class DefaultCpdTokens extends DefaultStorable implements NewCpdTokens { public DefaultCpdTokens onFile(InputFile inputFile) { Preconditions.checkNotNull(inputFile, "file can't be null"); this.inputFile = (DefaultInputFile) inputFile; - String language = inputFile.language(); - if (language != null && isSkipped(language)) { - this.excluded = true; - } else { - String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS); - for (PathPattern cpdExclusion : PathPattern.create(cpdExclusions)) { - if (cpdExclusion.match(inputFile)) { - this.excluded = true; - } + String[] cpdExclusions = settings.getStringArray(CoreProperties.CPD_EXCLUSIONS); + for (PathPattern cpdExclusion : PathPattern.create(cpdExclusions)) { + if (cpdExclusion.match(inputFile)) { + this.excluded = true; } } return this; } - boolean isSkipped(String language) { - String key = "sonar.cpd." + language + ".skip"; - if (settings.hasKey(key)) { - return settings.getBoolean(key); - } - return settings.getBoolean(CoreProperties.CPD_SKIP_PROPERTY); - } - public InputFile inputFile() { return inputFile; } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java index 94494b95923..96310b70977 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java @@ -82,38 +82,6 @@ public class DefaultCpdTokensTest { assertThat(tokens.getTokenLines()).isEmpty(); } - @Test - public void handle_exclusions_by_language() { - SensorStorage sensorStorage = mock(SensorStorage.class); - Settings settings = new Settings(); - settings.setProperty("sonar.cpd.java.skip", "true"); - DefaultCpdTokens tokens = new DefaultCpdTokens(settings, sensorStorage) - .onFile(INPUT_FILE) - .addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo"); - - tokens.save(); - - verifyZeroInteractions(sensorStorage); - - assertThat(tokens.getTokenLines()).isEmpty(); - } - - @Test - public void handle_exclusions() { - SensorStorage sensorStorage = mock(SensorStorage.class); - Settings settings = new Settings(); - settings.setProperty("sonar.cpd.skip", "true"); - DefaultCpdTokens tokens = new DefaultCpdTokens(settings, sensorStorage) - .onFile(INPUT_FILE) - .addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo"); - - tokens.save(); - - verifyZeroInteractions(sensorStorage); - - assertThat(tokens.getTokenLines()).isEmpty(); - } - @Test public void save_many_tokens() { SensorStorage sensorStorage = mock(SensorStorage.class); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensor.java index 1d66024c21c..c2af38c5875 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensor.java @@ -22,14 +22,12 @@ package org.sonar.scanner.cpd.deprecated; import com.google.common.annotations.VisibleForTesting; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; import org.sonar.api.batch.CpdMapping; import org.sonar.api.batch.Phase; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.api.config.Settings; /** * Feed block index using deprecated {@link CpdMapping} extension point if not already @@ -44,13 +42,11 @@ public class DeprecatedCpdBlockIndexerSensor implements Sensor { private CpdBlockIndexer javaCpdBlockIndexer; private CpdBlockIndexer defaultCpdBlockIndexer; - private Settings settings; private FileSystem fs; - public DeprecatedCpdBlockIndexerSensor(JavaCpdBlockIndexer javaCpdBlockIndexer, DefaultCpdBlockIndexer defaultCpdBlockIndexer, Settings settings, FileSystem fs) { + public DeprecatedCpdBlockIndexerSensor(JavaCpdBlockIndexer javaCpdBlockIndexer, DefaultCpdBlockIndexer defaultCpdBlockIndexer, FileSystem fs) { this.javaCpdBlockIndexer = javaCpdBlockIndexer; this.defaultCpdBlockIndexer = defaultCpdBlockIndexer; - this.settings = settings; this.fs = fs; } @@ -67,32 +63,10 @@ public class DeprecatedCpdBlockIndexerSensor implements Sensor { return defaultCpdBlockIndexer; } - @VisibleForTesting - boolean isSkipped(String language) { - String key = "sonar.cpd." + language + ".skip"; - if (settings.hasKey(key)) { - return settings.getBoolean(key); - } - return settings.getBoolean(CoreProperties.CPD_SKIP_PROPERTY); - } - @Override public void execute(SensorContext context) { - if (settings.hasKey(CoreProperties.CPD_SKIP_PROPERTY)) { - LOG.warn("\"sonar.cpd.skip\" property is deprecated and will be removed. Please set \"sonar.cpd.exclusions=**\" instead to disable duplication mechanism."); - } for (String language : fs.languages()) { - if (settings.hasKey("sonar.cpd." + language + ".skip")) { - LOG - .warn("\"sonar.cpd." + language + ".skip\" property is deprecated and will be removed. Please set \"sonar.cpd.exclusions=**\" instead to disable duplication mechanism."); - } - - if (isSkipped(language)) { - LOG.info("Detection of duplicated code is skipped for {}", language); - continue; - } - CpdBlockIndexer blockIndexer = getBlockIndexer(language); if (!blockIndexer.isLanguageSupported(language)) { LOG.debug("Detection of duplicated code is not supported for {}", language); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensorTest.java index 092a3499c10..a8c734eeba3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensorTest.java @@ -25,10 +25,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.fs.internal.DefaultFileSystem; -import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.Settings; import org.sonar.scanner.FakeJava; -import org.sonar.scanner.cpd.CpdComponents; import static org.assertj.core.api.Assertions.assertThat; @@ -40,36 +37,14 @@ public class DeprecatedCpdBlockIndexerSensorTest { JavaCpdBlockIndexer sonarEngine; DefaultCpdBlockIndexer sonarBridgeEngine; DeprecatedCpdBlockIndexerSensor sensor; - Settings settings; @Before public void setUp() throws IOException { sonarEngine = new JavaCpdBlockIndexer(null, null, null); sonarBridgeEngine = new DefaultCpdBlockIndexer(new CpdMappings(), null, null, null); - settings = new Settings(new PropertyDefinitions(CpdComponents.class)); DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder().toPath()); - sensor = new DeprecatedCpdBlockIndexerSensor(sonarEngine, sonarBridgeEngine, settings, fs); - } - - @Test - public void test_global_skip() { - settings.setProperty("sonar.cpd.skip", true); - assertThat(sensor.isSkipped(FakeJava.KEY)).isTrue(); - } - - @Test - public void should_not_skip_by_default() { - assertThat(sensor.isSkipped(FakeJava.KEY)).isFalse(); - } - - @Test - public void should_skip_by_language() { - settings.setProperty("sonar.cpd.skip", false); - settings.setProperty("sonar.cpd.php.skip", true); - - assertThat(sensor.isSkipped("php")).isTrue(); - assertThat(sensor.isSkipped(FakeJava.KEY)).isFalse(); + sensor = new DeprecatedCpdBlockIndexerSensor(sonarEngine, sonarBridgeEngine, fs); } @Test