From fe3c5105bd62267bf8365101066f6ded7e6a6d33 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 15 Oct 2019 13:31:21 -0500 Subject: [PATCH] Remove deprecated code in scanner --- .../batch/bootstrap/ProjectDefinition.java | 44 ------------------- .../bootstrap/ProjectDefinitionTest.java | 7 +-- .../bootstrapper/LoggingConfiguration.java | 22 +--------- .../GenericCoverageSensor.java | 41 ++--------------- .../scanner/scan/ProjectReactorBuilder.java | 23 +--------- .../GenericCoverageSensorTest.java | 18 ++------ .../coverage/GenericCoverageMediumTest.java | 14 ------ .../scan/ProjectReactorBuilderTest.java | 9 ---- 8 files changed, 13 insertions(+), 165 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java index 40d293da8de..c4b910ef65e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java @@ -52,7 +52,6 @@ public class ProjectDefinition { private File baseDir; private File workDir; - private File buildDir; private Map properties = new LinkedHashMap<>(); private ProjectDefinition parent = null; private List subProjects = new ArrayList<>(); @@ -85,53 +84,10 @@ public class ProjectDefinition { return workDir; } - /** - * @deprecated since 6.1 notion of buildDir is not well defined - */ - @Deprecated - public ProjectDefinition setBuildDir(File d) { - this.buildDir = d; - return this; - } - - /** - * @deprecated since 6.1 notion of buildDir is not well defined - */ - @Deprecated - public File getBuildDir() { - return buildDir; - } - - /** - * @deprecated since 5.0 use {@link #properties()} - */ - @Deprecated - public Properties getProperties() { - Properties result = new Properties(); - for (Map.Entry entry : properties.entrySet()) { - result.setProperty(entry.getKey(), entry.getValue()); - } - return result; - } - public Map properties() { return properties; } - /** - * Copies specified properties into this object. - * - * @since 2.12 - * @deprecated since 5.0 use {@link #setProperties(Map)} - */ - @Deprecated - public ProjectDefinition setProperties(Properties properties) { - for (Entry entry : properties.entrySet()) { - this.properties.put(entry.getKey().toString(), entry.getValue().toString()); - } - return this; - } - public ProjectDefinition setProperties(Map properties) { this.properties.putAll(properties); return this; diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java index a69dad61ada..b62f21f4a11 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java @@ -19,7 +19,8 @@ */ package org.sonar.api.batch.bootstrap; -import java.util.Properties; +import java.util.HashMap; +import java.util.Map; import org.junit.Test; import org.sonar.api.CoreProperties; @@ -67,8 +68,8 @@ public class ProjectDefinitionTest { @Test public void shouldGetKeyFromProperties() { - Properties props = new Properties(); - props.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); + Map props = new HashMap<>(); + props.put(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); ProjectDefinition def = ProjectDefinition.create(); def.setProperties(props); assertThat(def.getKey()).isEqualTo("foo"); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java index bf7b4f63d6c..a211f1e5a24 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java @@ -21,7 +21,6 @@ package org.sonar.batch.bootstrapper; import java.util.HashMap; import java.util.Map; -import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; @@ -31,12 +30,6 @@ import org.apache.commons.lang.StringUtils; public final class LoggingConfiguration { public static final String PROPERTY_ROOT_LOGGER_LEVEL = "ROOT_LOGGER_LEVEL"; - /** - * @deprecated since 5.2 there is no more db access from scanner side - */ - @Deprecated - public static final String PROPERTY_SQL_LOGGER_LEVEL = "SQL_LOGGER_LEVEL"; - public static final String PROPERTY_FORMAT = "FORMAT"; public static final String LEVEL_ROOT_VERBOSE = "DEBUG"; @@ -90,19 +83,6 @@ public final class LoggingConfiguration { return setVerbose(verbose); } - @CheckForNull - private static String getFallback(String key, Map properties, @Nullable Map fallback) { - if (properties.containsKey(key)) { - return properties.get(key); - } - - if (fallback != null) { - return fallback.get(key); - } - - return null; - } - public LoggingConfiguration setRootLevel(String level) { return addSubstitutionVariable(PROPERTY_ROOT_LOGGER_LEVEL, level); } @@ -111,7 +91,7 @@ public final class LoggingConfiguration { return addSubstitutionVariable(PROPERTY_FORMAT, StringUtils.defaultIfBlank(format, FORMAT_DEFAULT)); } - public LoggingConfiguration addSubstitutionVariable(String key, String value) { + private LoggingConfiguration addSubstitutionVariable(String key, String value) { substitutionVariables.put(key, value); return this; } 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 537f8a1857a..ab05eb0640f 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 @@ -26,44 +26,22 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; 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.PropertyDefinition; import org.sonar.api.resources.Qualifiers; +import org.sonar.api.scanner.sensor.ProjectSensor; 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; -public class GenericCoverageSensor implements Sensor { +public class GenericCoverageSensor implements ProjectSensor { private static final Logger LOG = Loggers.get(GenericCoverageSensor.class); static final String REPORT_PATHS_PROPERTY_KEY = "sonar.coverageReportPaths"; - /** - * @deprecated since 6.2 - */ - @Deprecated - static final String OLD_REPORT_PATH_PROPERTY_KEY = "sonar.genericcoverage.reportPath"; - /** - * @deprecated since 6.2 - */ - @Deprecated - static final String OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY = "sonar.genericcoverage.reportPaths"; - /** - * @deprecated since 6.2 - */ - @Deprecated - static final String OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY = "sonar.genericcoverage.itReportPaths"; - /** - * @deprecated since 6.2 - */ - @Deprecated - static final String OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY = "sonar.genericcoverage.overallReportPaths"; - private final DefaultConfiguration config; public GenericCoverageSensor(DefaultConfiguration config) { @@ -78,7 +56,6 @@ public class GenericCoverageSensor implements Sensor { .category(CATEGORY_CODE_COVERAGE) .onQualifiers(Qualifiers.PROJECT) .multiValues(true) - .deprecatedKey(OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY) .build()); } @@ -100,11 +77,7 @@ public class GenericCoverageSensor implements Sensor { @Override public void describe(SensorDescriptor descriptor) { descriptor.name("Generic Coverage Report") - .global() - .onlyWhenConfiguration(c -> asList(REPORT_PATHS_PROPERTY_KEY, OLD_REPORT_PATH_PROPERTY_KEY, OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY, - OLD_IT_COVERAGE_REPORT_PATHS_PROPERTY_KEY, OLD_OVERALL_COVERAGE_REPORT_PATHS_PROPERTY_KEY) - .stream() - .anyMatch(c::hasKey)); + .onlyWhenConfiguration(c -> c.hasKey(REPORT_PATHS_PROPERTY_KEY)); } @Override @@ -126,13 +99,7 @@ public class GenericCoverageSensor implements Sensor { } Set loadReportPaths() { - Set reportPaths = new LinkedHashSet<>(); - reportPaths.addAll(Arrays.asList(config.getStringArray(REPORT_PATHS_PROPERTY_KEY))); - loadDeprecated(reportPaths, OLD_REPORT_PATH_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; + return new LinkedHashSet<>(Arrays.asList(config.getStringArray(REPORT_PATHS_PROPERTY_KEY))); } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java index 75890cf1e96..ae44ad23660 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java @@ -32,7 +32,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.stream.Stream; -import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; @@ -69,11 +68,6 @@ public class ProjectReactorBuilder { private static final String MODULE_KEY_PROPERTY = "sonar.moduleKey"; protected static final String PROPERTY_PROJECT_BASEDIR = "sonar.projectBaseDir"; - /** - * @deprecated since 6.1 notion of buildDir is not well defined - */ - @Deprecated - private static final String PROPERTY_PROJECT_BUILDDIR = "sonar.projectBuildDir"; private static final String PROPERTY_MODULES = "sonar.modules"; /** @@ -187,8 +181,7 @@ public class ProjectReactorBuilder { return ProjectDefinition.create().setProperties(moduleProperties) .setBaseDir(baseDir) - .setWorkDir(workDir) - .setBuildDir(initModuleBuildDir(baseDir, moduleProperties)); + .setWorkDir(workDir); } private void checkUnsupportedIssueExclusions(Map moduleProperties, Map parentProps) { @@ -234,20 +227,6 @@ public class ProjectReactorBuilder { return new File(moduleBaseDir, customWorkDir.getPath()); } - @CheckForNull - private static File initModuleBuildDir(File moduleBaseDir, Map moduleProperties) { - String buildDir = moduleProperties.get(PROPERTY_PROJECT_BUILDDIR); - if (StringUtils.isBlank(buildDir)) { - return null; - } - - File customBuildDir = new File(buildDir); - if (customBuildDir.isAbsolute()) { - return customBuildDir; - } - return new File(moduleBaseDir, customBuildDir.getPath()); - } - private void defineChildren(ProjectDefinition parentProject, Map> propertiesByModuleIdPath, String parentModuleIdPath) { Map parentProps = parentProject.properties(); if (parentProps.containsKey(PROPERTY_MODULES)) { 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 6dc3de2ae2b..245a0578ff3 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 @@ -27,7 +27,6 @@ import org.junit.Test; import org.sonar.api.config.Encryption; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.utils.log.LogTester; -import org.sonar.api.utils.log.LoggerLevel; import org.sonar.scanner.config.DefaultConfiguration; import org.sonar.scanner.scan.ProjectConfiguration; @@ -39,25 +38,14 @@ public class GenericCoverageSensorTest { public LogTester logTester = new LogTester(); @Test - public void migrateOldProperties() { + public void loadAllReportPaths() { Map 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"); - + settings.put(GenericCoverageSensor.REPORT_PATHS_PROPERTY_KEY, "report.xml,report2.xml"); PropertyDefinitions defs = new PropertyDefinitions(GenericCoverageSensor.properties()); DefaultConfiguration config = new ProjectConfiguration(defs, new Encryption(null), settings); Set 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.", - "Property 'sonar.genericcoverage.itReportPaths' is deprecated. Please use 'sonar.coverageReportPaths' instead.", - "Property 'sonar.genericcoverage.overallReportPaths' is deprecated. Please use 'sonar.coverageReportPaths' instead."); - - assertThat(reportPaths).containsOnly( - "old.xml", "old1.xml", "old2.xml", "old3.xml", "old4.xml", "old5.xml", "old6.xml"); + assertThat(reportPaths).containsOnly("report.xml", "report2.xml"); } } 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 1fc4d93676c..0a79212537d 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 @@ -66,20 +66,6 @@ public class GenericCoverageMediumTest { assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'")); } - - @Test - public void warnAboutDeprecatedProperty() { - File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-coverage"); - - tester - .setLogOutput((msg, level) -> logs.add(msg)) - .newAnalysis(new File(projectDir, "sonar-project.properties")) - .property("sonar.genericcoverage.reportPath", "coverage.xml") - .execute(); - - - assertThat(logs).anyMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'")); - } @Test public void twoReports() throws IOException { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java index e27fb8607da..cece58e15aa 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java @@ -550,15 +550,6 @@ public class ProjectReactorBuilderTest { assertThat(ProjectReactorBuilder.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu"); } - @Test - public void shouldDefineProjectWithBuildDir() { - ProjectDefinition rootProject = loadProjectDefinition("simple-project-with-build-dir"); - File buildDir = rootProject.getBuildDir(); - assertThat(buildDir).isDirectory().exists(); - assertThat(new File(buildDir, "report.txt")).isFile().exists(); - assertThat(buildDir.getName()).isEqualTo("build"); - } - @Test public void doNotMixPropertiesWhenModuleKeyIsPrefixOfAnother() throws IOException { ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-same-prefix"); -- 2.39.5