]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5813 Fully drop support of "sonar.cpd.xxx.skip" properties 1184/head
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 29 Aug 2016 13:34:48 +0000 (15:34 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 29 Aug 2016 13:34:48 +0000 (15:34 +0200)
it/it-tests/src/test/java/it/analysisExclusion/IssueExclusionsTest.java
it/it-tests/src/test/java/it/projectAdministration/ProjectAdministrationTest.java
it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensor.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensorTest.java

index 408ad2a2d1820187eac333d248df8c88087b731d..2103ed3f7a441b6b98f02dc3919633d30b37928e 100644 (file)
@@ -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);
   }
 
index f9863aa85b4b6849dd400889afcd81d7b6376ff5..50a3f12b3b4beb03d8afca39daa40b3d861fe6dd 100644 (file)
@@ -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);
     }
index facf950e78ef37632ac175f8a2d729f3d3bc1683..399399a49f5112314aeabec043f18b55723628f6 100644 (file)
@@ -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);
     }
index 76d5ae24ca55013b7807a5edad547604e22a8f66..3960bb7054b250dc74021534fd542bf577ac658b 100644 (file)
@@ -225,13 +225,6 @@ public interface CoreProperties {
   /* CPD */
   String CPD_PLUGIN = "cpd";
 
-  /**
-   * @deprecated in 5.0
-   * @see <a href="https://jira.sonarsource.com/browse/SONAR-5339">SONAR-5339</a>
-   */
-  @Deprecated
-  String CPD_SKIP_PROPERTY = "sonar.cpd.skip";
-
   /**
    * @since 2.11
    */
index 20db6a92e5e319e79f47ab82ad549b243ed2dd3f..16d8be19e08e811c76c64cb0befa5b0b2086c766 100644 (file)
@@ -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;
   }
index 94494b959237c4a796fdf2dab19fb9c8289dbcf0..96310b7097743f7b4d95fe8bff7d83b97795b2eb 100644 (file)
@@ -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);
index 1d66024c21cbaf22649c54457b1c18ed75ed5d55..c2af38c58755828c8c1a5477746077339b131c15 100644 (file)
@@ -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);
index 092a3499c10ab61e3177a6b0d092a37e16f0acdf..a8c734eeba304349c1b26a5d383a719da27f4246 100644 (file)
@@ -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