diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2018-06-06 14:12:25 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-06-11 20:20:48 +0200 |
commit | 17968cf78d5f505c1ce3fb3ae5c8be6bf22684cd (patch) | |
tree | a661038fd5506008a54c8a020372d5b66723f9c5 | |
parent | b7afbcb9ba7bf3f9321949ecdd9de65d48fc9fce (diff) | |
download | sonarqube-17968cf78d5f505c1ce3fb3ae5c8be6bf22684cd.tar.gz sonarqube-17968cf78d5f505c1ce3fb3ae5c8be6bf22684cd.zip |
SONAR-10542 Deprecation warning always logged when using generic test execution/coverage
9 files changed, 117 insertions, 47 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java index dfdfa2f9f1d..27f11deacfd 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/config/DefaultConfiguration.java @@ -47,12 +47,14 @@ public abstract class DefaultConfiguration implements Configuration { private final Encryption encryption; private final GlobalAnalysisMode mode; private final Map<String, String> properties; + private final Map<String, String> originalProperties; public DefaultConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode, Map<String, String> props) { this.definitions = requireNonNull(propertyDefinitions); this.encryption = encryption; this.mode = mode; this.properties = unmodifiableMapWithTrimmedValues(definitions, props); + this.originalProperties = Collections.unmodifiableMap(props); } protected static Map<String, String> unmodifiableMapWithTrimmedValues(PropertyDefinitions definitions, Map<String, String> props) { @@ -80,6 +82,10 @@ public abstract class DefaultConfiguration implements Configuration { return properties; } + public Map<String, String> getOriginalProperties() { + return originalProperties; + } + @Override public boolean hasKey(String key) { return properties.containsKey(key); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java index b9a1579f027..5fbfff5d25b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java @@ -28,11 +28,11 @@ import java.util.stream.Collectors; 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.Configuration; import org.sonar.api.config.PropertyDefinition; import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; +import org.sonar.scanner.config.DefaultConfiguration; import static java.util.Arrays.asList; import static org.sonar.api.CoreProperties.CATEGORY_CODE_COVERAGE; @@ -63,9 +63,9 @@ public class GenericCoverageSensor implements Sensor { @Deprecated static final String OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY = "sonar.genericcoverage.overallReportPaths"; - private final Configuration config; + private final DefaultConfiguration config; - public GenericCoverageSensor(Configuration config) { + public GenericCoverageSensor(DefaultConfiguration config) { this.config = config; } @@ -77,18 +77,26 @@ public class GenericCoverageSensor implements Sensor { .description("List of comma-separated paths (absolute or relative) containing coverage report.") .category(CATEGORY_CODE_COVERAGE) .onQualifiers(Qualifiers.PROJECT) + .multiValues(true) .deprecatedKey(OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY) .build()); } - private void loadDeprecated(Set<String> reportPaths, String propertyKey) { - if (config.hasKey(propertyKey)) { + private void loadArrayDeprecated(Set<String> reportPaths, String propertyKey) { + if (config.getOriginalProperties().containsKey(propertyKey)) { LOG.warn("Property '{}' is deprecated. Please use '{}' instead.", propertyKey, REPORT_PATHS_PROPERTY_KEY); reportPaths.addAll(Arrays.asList(config.getStringArray(propertyKey))); } } + private void loadDeprecated(Set<String> reportPaths, String propertyKey) { + if (config.getOriginalProperties().containsKey(propertyKey)) { + LOG.warn("Property '{}' is deprecated. Please use '{}' instead.", propertyKey, REPORT_PATHS_PROPERTY_KEY); + config.get(propertyKey).ifPresent(reportPaths::add); + } + } + @Override public void describe(SensorDescriptor descriptor) { descriptor.name("Generic Coverage Report") @@ -120,9 +128,9 @@ public class GenericCoverageSensor implements Sensor { Set<String> reportPaths = new LinkedHashSet<>(); reportPaths.addAll(Arrays.asList(config.getStringArray(REPORT_PATHS_PROPERTY_KEY))); loadDeprecated(reportPaths, OLD_REPORT_PATH_PROPERTY_KEY); - loadDeprecated(reportPaths, OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY); - loadDeprecated(reportPaths, OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY); - loadDeprecated(reportPaths, OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY); + loadArrayDeprecated(reportPaths, OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY); + loadArrayDeprecated(reportPaths, OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY); + loadArrayDeprecated(reportPaths, OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY); return reportPaths; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensor.java index b44fdb3591e..3b9fe583ce1 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensor.java @@ -29,6 +29,7 @@ import org.sonar.api.config.PropertyDefinition; import org.sonar.api.resources.Qualifiers; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; +import org.sonar.scanner.config.DefaultConfiguration; import org.sonar.scanner.deprecated.test.TestPlanBuilder; import static org.sonar.api.CoreProperties.CATEGORY_CODE_COVERAGE; @@ -45,9 +46,11 @@ public class GenericTestExecutionSensor implements Sensor { static final String OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY = "sonar.genericcoverage.unitTestReportPaths"; private final TestPlanBuilder testPlanBuilder; + private final DefaultConfiguration configuration; - public GenericTestExecutionSensor(TestPlanBuilder testPlanBuilder) { + public GenericTestExecutionSensor(TestPlanBuilder testPlanBuilder, DefaultConfiguration configuration) { this.testPlanBuilder = testPlanBuilder; + this.configuration = configuration; } public static ImmutableList<PropertyDefinition> properties() { @@ -58,9 +61,9 @@ public class GenericTestExecutionSensor implements Sensor { .description("List of comma-separated paths (absolute or relative) containing unit tests results report.") .category(CATEGORY_CODE_COVERAGE) .onQualifiers(Qualifiers.PROJECT) + .multiValues(true) .deprecatedKey(OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY) .build()); - } @Override @@ -71,10 +74,11 @@ public class GenericTestExecutionSensor implements Sensor { @Override public void execute(SensorContext context) { - if (context.settings().hasKey(OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY)) { + if (configuration.getOriginalProperties().containsKey(OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY)) { LOG.warn("Property '{}' is deprecated. Please use '{}' instead.", OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY, REPORT_PATHS_PROPERTY_KEY); } - for (String reportPath : context.settings().getStringArray(REPORT_PATHS_PROPERTY_KEY)) { + + for (String reportPath : configuration.getStringArray(REPORT_PATHS_PROPERTY_KEY)) { File reportFile = context.fileSystem().resolvePath(reportPath); LOG.info("Parsing {}", reportFile); GenericTestExecutionReportParser parser = new GenericTestExecutionReportParser(testPlanBuilder); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java index a44ac36b0ec..af9ea941f51 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectScanContainer.java @@ -21,7 +21,6 @@ package org.sonar.scanner.scan; import com.google.common.annotations.VisibleForTesting; import javax.annotation.Nullable; -import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.fs.internal.DefaultInputModule; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageSensorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageSensorTest.java index 2212f377950..6ebb470dfbb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageSensorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageSensorTest.java @@ -19,15 +19,21 @@ */ package org.sonar.scanner.genericcoverage; +import java.util.HashMap; +import java.util.Map; import java.util.Set; import org.junit.Rule; import org.junit.Test; +import org.sonar.api.config.Encryption; import org.sonar.api.config.PropertyDefinitions; -import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; +import org.sonar.scanner.bootstrap.GlobalAnalysisMode; +import org.sonar.scanner.config.DefaultConfiguration; +import org.sonar.scanner.scan.ProjectSettings; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; public class GenericCoverageSensorTest { @@ -36,12 +42,17 @@ public class GenericCoverageSensorTest { @Test public void migrateOldProperties() { - MapSettings settings = new MapSettings(new PropertyDefinitions(GenericCoverageSensor.properties())); - settings.setProperty(GenericCoverageSensor.OLD_REPORT_PATH_PROPERTY_KEY, "old.xml"); - settings.setProperty(GenericCoverageSensor.OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old1.xml,old2.xml"); - settings.setProperty(GenericCoverageSensor.OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old3.xml,old4.xml,old.xml"); - settings.setProperty(GenericCoverageSensor.OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old5.xml,old6.xml"); - Set<String> reportPaths = new GenericCoverageSensor(settings.asConfig()).loadReportPaths(); + Map<String, String> settings = new HashMap<>(); + settings.put(GenericCoverageSensor.OLD_REPORT_PATH_PROPERTY_KEY, "old.xml"); + settings.put(GenericCoverageSensor.OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old1.xml,old2.xml"); + settings.put(GenericCoverageSensor.OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old3.xml,old4.xml,old.xml"); + settings.put(GenericCoverageSensor.OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY, "old5.xml,old6.xml"); + + PropertyDefinitions defs = new PropertyDefinitions(GenericCoverageSensor.properties()); + DefaultConfiguration config = new ProjectSettings(defs, new Encryption(null), mock(GlobalAnalysisMode.class), settings); + + Set<String> reportPaths = new GenericCoverageSensor(config).loadReportPaths(); + assertThat(logTester.logs(LoggerLevel.WARN)).contains( "Property 'sonar.genericcoverage.reportPath' is deprecated. Please use 'sonar.coverageReportPaths' instead.", "Property 'sonar.genericcoverage.reportPaths' is deprecated. Please use 'sonar.coverageReportPaths' instead.", @@ -51,5 +62,4 @@ public class GenericCoverageSensorTest { assertThat(reportPaths).containsOnly( "old.xml", "old1.xml", "old2.xml", "old3.xml", "old4.xml", "old5.xml", "old6.xml"); } - } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensorTest.java index e388c77a231..ad996aef87b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericTestExecutionSensorTest.java @@ -21,17 +21,24 @@ package org.sonar.scanner.genericcoverage; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.api.batch.sensor.internal.SensorContextTester; +import org.sonar.api.config.Encryption; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.Settings; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; +import org.sonar.scanner.bootstrap.GlobalAnalysisMode; +import org.sonar.scanner.config.DefaultConfiguration; import org.sonar.scanner.deprecated.test.TestPlanBuilder; +import org.sonar.scanner.scan.ProjectSettings; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -48,12 +55,15 @@ public class GenericTestExecutionSensorTest { public void logWhenDeprecatedPropsAreUsed() throws IOException { File basedir = temp.newFolder(); File report = new File(basedir, "report.xml"); - FileUtils.write(report, "<unitTest version=\"1\"><file path=\"A.java\"><testCase name=\"test1\" duration=\"500\"/></file></unitTest>"); + FileUtils.write(report, "<unitTest version=\"1\"><file path=\"A.java\"><testCase name=\"test1\" duration=\"500\"/></file></unitTest>", StandardCharsets.UTF_8); SensorContextTester context = SensorContextTester.create(basedir); - Settings settings = new MapSettings(new PropertyDefinitions(GenericTestExecutionSensor.properties())); - settings.setProperty(GenericTestExecutionSensor.OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY, "report.xml"); - context.setSettings(settings); - new GenericTestExecutionSensor(mock(TestPlanBuilder.class)).execute(context); + + Map<String, String> settings = new HashMap<>(); + settings.put(GenericTestExecutionSensor.OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY, "report.xml"); + PropertyDefinitions defs = new PropertyDefinitions(GenericTestExecutionSensor.properties()); + DefaultConfiguration config = new ProjectSettings(defs, new Encryption(null), mock(GlobalAnalysisMode.class), settings); + + new GenericTestExecutionSensor(mock(TestPlanBuilder.class), config).execute(context); assertThat(logTester.logs(LoggerLevel.WARN)).contains( "Using 'unitTest' as root element of the report is deprecated. Please change to 'testExecutions'.", "Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead."); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java index de42f5b39b0..3099de627a8 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumTest.java @@ -22,6 +22,7 @@ package org.sonar.scanner.mediumtest.coverage; import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; @@ -56,8 +57,8 @@ public class CoverageMediumTest { File xooFile = new File(srcDir, "sample.xoo"); File xooUtCoverageFile = new File(srcDir, "sample.xoo.coverage"); - FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}"); - FileUtils.write(xooUtCoverageFile, "2:2:2:1\n3:1"); + FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8); + FileUtils.write(xooUtCoverageFile, "2:2:2:1\n3:1", StandardCharsets.UTF_8); TaskResult result = tester.newTask() .properties(ImmutableMap.<String, String>builder() @@ -92,11 +93,11 @@ public class CoverageMediumTest { srcDir.mkdir(); File xooFile = new File(srcDir, "sample.xoo"); - FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}"); + FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8); File xooUtCoverageFile = new File(srcDir, "sample.xoo.coverage"); - FileUtils.write(xooUtCoverageFile, "2:2:2:2\n4:0"); + FileUtils.write(xooUtCoverageFile, "2:2:2:2\n4:0", StandardCharsets.UTF_8); File xooItCoverageFile = new File(srcDir, "sample.xoo.itcoverage"); - FileUtils.write(xooItCoverageFile, "2:2:2:1\n3:1\n5:0"); + FileUtils.write(xooItCoverageFile, "2:2:2:1\n3:1\n5:0", StandardCharsets.UTF_8); TaskResult result = tester.newTask() .properties(ImmutableMap.<String, String>builder() @@ -136,8 +137,8 @@ public class CoverageMediumTest { File xooFile = new File(srcDir, "sample.xoo"); File xooUtCoverageFile = new File(srcDir, "sample.xoo.coverage"); - FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}"); - FileUtils.write(xooUtCoverageFile, "2:2:2:1\n3:1"); + FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8); + FileUtils.write(xooUtCoverageFile, "2:2:2:1\n3:1", StandardCharsets.UTF_8); TaskResult result = tester.newTask() .properties(ImmutableMap.<String, String>builder() @@ -170,8 +171,8 @@ public class CoverageMediumTest { File xooFile = new File(srcDir, "sample.xoo"); File measuresFile = new File(srcDir, "sample.xoo.measures"); - FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}"); - FileUtils.write(measuresFile, "executable_lines_data:2=1;3=1;4=0"); + FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8); + FileUtils.write(measuresFile, "executable_lines_data:2=1;3=1;4=0", StandardCharsets.UTF_8); TaskResult result = tester.newTask() .properties(ImmutableMap.<String, String>builder() @@ -213,13 +214,13 @@ public class CoverageMediumTest { File xooFile1 = new File(srcDir, "sample1.xoo"); File measuresFile1 = new File(srcDir, "sample1.xoo.measures"); - FileUtils.write(xooFile1, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}"); - FileUtils.write(measuresFile1, "executable_lines_data:2=1;3=1;4=0"); + FileUtils.write(xooFile1, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8); + FileUtils.write(measuresFile1, "executable_lines_data:2=1;3=1;4=0", StandardCharsets.UTF_8); File xooFile2 = new File(srcDir, "sample2.xoo"); File measuresFile2 = new File(srcDir, "sample2.xoo.measures"); - FileUtils.write(xooFile2, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}"); - FileUtils.write(measuresFile2, "executable_lines_data:2=1;3=1;4=0"); + FileUtils.write(xooFile2, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8); + FileUtils.write(measuresFile2, "executable_lines_data:2=1;3=1;4=0", StandardCharsets.UTF_8); TaskResult result = tester.newTask() .properties(ImmutableMap.<String, String>builder() diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java index 4e07941de56..2afc3545f3d 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java @@ -21,6 +21,8 @@ package org.sonar.scanner.mediumtest.coverage; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.junit.Rule; import org.junit.Test; import org.sonar.api.batch.fs.InputFile; @@ -33,7 +35,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; public class GenericCoverageMediumTest { - + private final List<String> logs = new ArrayList<>(); + @Rule public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) @@ -45,6 +48,7 @@ public class GenericCoverageMediumTest { File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-coverage"); TaskResult result = tester + .setLogOutput((msg, level) -> logs.add(msg)) .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.coverageReportPaths", "coverage.xml") .execute(); @@ -76,8 +80,23 @@ public class GenericCoverageMediumTest { tuple(CoreMetrics.UNCOVERED_CONDITIONS_KEY, 1, ""), tuple(CoreMetrics.CONDITIONS_BY_LINE_KEY, 0, "3=2"), tuple(CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, 0, "3=1") - ); + assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'")); + + } + + @Test + public void warnAboutDeprecatedProperty() { + File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-coverage"); + + tester + .setLogOutput((msg, level) -> logs.add(msg)) + .newScanTask(new File(projectDir, "sonar-project.properties")) + .property("sonar.genericcoverage.reportPath", "coverage.xml") + .execute(); + + + assertThat(logs).anyMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'")); } @Test @@ -86,6 +105,7 @@ public class GenericCoverageMediumTest { File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-coverage"); TaskResult result = tester + .setLogOutput((msg, level) -> logs.add(msg)) .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.coverageReportPaths", "coverage.xml,coverage2.xml") .execute(); @@ -117,8 +137,9 @@ public class GenericCoverageMediumTest { tuple(CoreMetrics.UNCOVERED_CONDITIONS_KEY, 0, ""), tuple(CoreMetrics.CONDITIONS_BY_LINE_KEY, 0, "3=2"), tuple(CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, 0, "3=2") - ); + + assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'")); } - + } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java index 72ff026489e..19ac322b2a7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tests/GenericTestExecutionMediumTest.java @@ -22,6 +22,9 @@ package org.sonar.scanner.mediumtest.tests; import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; @@ -38,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; public class GenericTestExecutionMediumTest { + private final List<String> logs = new ArrayList<>(); @Rule public TemporaryFolder temp = new TemporaryFolder(); @@ -57,18 +61,19 @@ public class GenericTestExecutionMediumTest { testDir.mkdir(); File xooFile = new File(srcDir, "sample.xoo"); - FileUtils.write(xooFile, "foo"); + FileUtils.write(xooFile, "foo", StandardCharsets.UTF_8); File xooTestFile = new File(testDir, "sampleTest.xoo"); - FileUtils.write(xooTestFile, "failure\nerror\nok\nskipped"); + FileUtils.write(xooTestFile, "failure\nerror\nok\nskipped", StandardCharsets.UTF_8); File xooTestExecutionFile = new File(testDir, "sampleTest.xoo.test"); FileUtils.write(xooTestExecutionFile, "skipped::::SKIPPED:UNIT\n" + "failure:2:Failure::FAILURE:UNIT\n" + "error:2:Error:The stack:ERROR:UNIT\n" + - "success:4:::OK:INTEGRATION"); + "success:4:::OK:INTEGRATION", StandardCharsets.UTF_8); - TaskResult result = tester.newTask() + TaskResult result = tester + .newTask() .properties(ImmutableMap.<String, String>builder() .put("sonar.task", "scan") .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) @@ -99,6 +104,7 @@ public class GenericTestExecutionMediumTest { File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-test-exec"); TaskResult result = tester + .setLogOutput((msg, level) -> logs.add(msg)) .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.testExecutionReportPaths", "unittest.xml") .execute(); @@ -133,6 +139,8 @@ public class GenericTestExecutionMediumTest { tuple(CoreMetrics.TEST_ERRORS_KEY, 1, 0L), tuple(CoreMetrics.TEST_EXECUTION_TIME_KEY, 0, 1105L), tuple(CoreMetrics.TEST_FAILURES_KEY, 1, 0L)); + + assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.testExecutionReportPaths'")); } @Test @@ -141,6 +149,7 @@ public class GenericTestExecutionMediumTest { File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-test-exec"); TaskResult result = tester + .setLogOutput((msg, level) -> logs.add(msg)) .newScanTask(new File(projectDir, "sonar-project.properties")) .property("sonar.testExecutionReportPaths", "unittest.xml,unittest2.xml") .execute(); @@ -179,6 +188,8 @@ public class GenericTestExecutionMediumTest { tuple(CoreMetrics.TEST_ERRORS_KEY, 1, 0L), tuple(CoreMetrics.TEST_EXECUTION_TIME_KEY, 0, 1610L), tuple(CoreMetrics.TEST_FAILURES_KEY, 1, 0L)); + + assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.testExecutionReportPaths'")); } } |