]> source.dussan.org Git - sonarqube.git/commitdiff
Remove deprecated code in scanner
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 15 Oct 2019 18:31:21 +0000 (13:31 -0500)
committerSonarTech <sonartech@sonarsource.com>
Mon, 21 Oct 2019 18:21:11 +0000 (20:21 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java
sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LoggingConfiguration.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageSensor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/genericcoverage/GenericCoverageSensorTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/coverage/GenericCoverageMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java

index 40d293da8de330fdc249d82c4abd3600ae46031a..c4b910ef65e73633db8600bb52919b9739a5fb37 100644 (file)
@@ -52,7 +52,6 @@ public class ProjectDefinition {
 
   private File baseDir;
   private File workDir;
-  private File buildDir;
   private Map<String, String> properties = new LinkedHashMap<>();
   private ProjectDefinition parent = null;
   private List<ProjectDefinition> 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<String, String> entry : properties.entrySet()) {
-      result.setProperty(entry.getKey(), entry.getValue());
-    }
-    return result;
-  }
-
   public Map<String, String> 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<Object, Object> entry : properties.entrySet()) {
-      this.properties.put(entry.getKey().toString(), entry.getValue().toString());
-    }
-    return this;
-  }
-
   public ProjectDefinition setProperties(Map<String, String> properties) {
     this.properties.putAll(properties);
     return this;
index a69dad61adafc8ccb52430112622c8360c77651c..b62f21f4a11a13e7991a2b3109ea9c132516fa24 100644 (file)
@@ -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<String, String> props = new HashMap<>();
+    props.put(CoreProperties.PROJECT_KEY_PROPERTY, "foo");
     ProjectDefinition def = ProjectDefinition.create();
     def.setProperties(props);
     assertThat(def.getKey()).isEqualTo("foo");
index bf7b4f63d6c9457d2efffdec428890de60fc16a5..a211f1e5a249d13d4cc8d9c6b72acbe2111c8234 100644 (file)
@@ -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<String, String> properties, @Nullable Map<String, String> 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;
   }
index 537f8a1857ac0555686e2314046104b7e5b4955e..ab05eb0640f0c43dd8da6fc4dc3322371a120277 100644 (file)
@@ -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<String> loadReportPaths() {
-    Set<String> 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)));
   }
 
 }
index 75890cf1e963cc4fd9dd551eb56a82c11e0ba0e5..ae44ad236606193d6e6eaa40989c87b8da098f25 100644 (file)
@@ -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<String, String> moduleProperties, Map<String, String> parentProps) {
@@ -234,20 +227,6 @@ public class ProjectReactorBuilder {
     return new File(moduleBaseDir, customWorkDir.getPath());
   }
 
-  @CheckForNull
-  private static File initModuleBuildDir(File moduleBaseDir, Map<String, String> 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<String, Map<String, String>> propertiesByModuleIdPath, String parentModuleIdPath) {
     Map<String, String> parentProps = parentProject.properties();
     if (parentProps.containsKey(PROPERTY_MODULES)) {
index 6dc3de2ae2b398109b5ab02e4b96bc6397619d3d..245a0578ff34abb472d1055ce9c385f2f040fc0e 100644 (file)
@@ -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<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");
-
+    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<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.",
-      "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");
   }
 }
index 1fc4d93676ca2a93c09fd3c01ba044bcdf4e708a..0a79212537dbd8bba3c014e35abd86cd35eb5a03 100644 (file)
@@ -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 {
index e27fb8607da8e326fd78e551b1b0d5f16553dc63..cece58e15aa9046e684451acd9b833bb9a860df2 100644 (file)
@@ -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");