Browse Source

SONAR-5813 Fully drop support of "sonar.cpd.xxx.skip" properties

tags/6.1-RC1
Julien HENRY 7 years ago
parent
commit
0fa7bac665

+ 2
- 2
it/it-tests/src/test/java/it/analysisExclusion/IssueExclusionsTest.java View 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);
}


+ 1
- 1
it/it-tests/src/test/java/it/projectAdministration/ProjectAdministrationTest.java View 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);
}

+ 1
- 1
it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java View 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);
}

+ 0
- 7
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java View 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
*/

+ 4
- 17
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokens.java View 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;
}

+ 0
- 32
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/cpd/internal/DefaultCpdTokensTest.java View 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);

+ 1
- 27
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensor.java View 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);

+ 1
- 26
sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/deprecated/DeprecatedCpdBlockIndexerSensorTest.java View 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

Loading…
Cancel
Save