From cf0653f726df89776688bb25ca8a3b34dec685ec Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 5 Jul 2017 09:33:58 +0200 Subject: [PATCH] Fix quality flaws --- .../api/batch/debt/DebtRemediationFunction.java | 1 + .../sonar/api/batch/postjob/PostJobContext.java | 1 + .../sonar/api/batch/sensor/SensorContext.java | 3 ++- .../deprecated/DeprecatedSensorContext.java | 3 ++- .../scanner/scan/ModuleSettingsProvider.java | 4 ++-- .../scanner/scan/MutableModuleSettings.java | 16 +--------------- .../scanner/scan/MutableModuleSettingsTest.java | 2 +- 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java index 96ff255364c..a0b2e24404d 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java @@ -27,6 +27,7 @@ import org.sonar.api.utils.Duration; * @since 4.3 * @deprecated since 6.5 debt model will soon be unavailable on batch side */ +@Deprecated public class DebtRemediationFunction { public enum Type { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/PostJobContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/PostJobContext.java index cfe881f2866..d6255c82fc4 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/PostJobContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/PostJobContext.java @@ -33,6 +33,7 @@ public interface PostJobContext { /** * @deprecated since 6.5 use {@link PostJobContext#config()} */ + @Deprecated Settings settings(); /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java index 8da60fb974e..cdf3aa304ac 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java @@ -36,8 +36,8 @@ import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.batch.sensor.measure.Measure; import org.sonar.api.batch.sensor.measure.NewMeasure; import org.sonar.api.batch.sensor.symbol.NewSymbolTable; -import org.sonar.api.config.Settings; import org.sonar.api.config.Configuration; +import org.sonar.api.config.Settings; import org.sonar.api.utils.Version; /** @@ -50,6 +50,7 @@ public interface SensorContext { /** * @deprecated since 6.5 use {@link PostJobContext#config()} */ + @Deprecated Settings settings(); /** diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java index 3679fa3fd1a..25439a3f923 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/deprecated/DeprecatedSensorContext.java @@ -46,7 +46,8 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen private final DefaultIndex index; private final InputModule module; - public DeprecatedSensorContext(InputModule module, DefaultIndex index, Configuration config, org.sonar.api.config.Settings mutableSettings, FileSystem fs, ActiveRules activeRules, + public DeprecatedSensorContext(InputModule module, DefaultIndex index, Configuration config, org.sonar.api.config.Settings mutableSettings, + FileSystem fs, ActiveRules activeRules, AnalysisMode analysisMode, SensorStorage sensorStorage, SonarRuntime sonarRuntime) { super(module, config, mutableSettings, fs, activeRules, analysisMode, sensorStorage, sonarRuntime); this.index = index; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettingsProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettingsProvider.java index 7fd4d6a24d6..d17a9c0916f 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettingsProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ModuleSettingsProvider.java @@ -50,7 +50,7 @@ public class ModuleSettingsProvider extends ProviderAdapter { return projectSettings; } - private Map addServerSidePropertiesIfModuleExists(ProjectRepositories projectRepos, ProjectDefinition def) { + private static Map addServerSidePropertiesIfModuleExists(ProjectRepositories projectRepos, ProjectDefinition def) { if (projectRepos.moduleExists(def.getKeyWithBranch())) { return projectRepos.settings(def.getKeyWithBranch()); } else { @@ -63,7 +63,7 @@ public class ModuleSettingsProvider extends ProviderAdapter { } } - private void addScannerSideProperties(Map settings, ProjectDefinition project) { + private static void addScannerSideProperties(Map settings, ProjectDefinition project) { List orderedProjects = getTopDownParentProjects(project); for (ProjectDefinition p : orderedProjects) { settings.putAll(p.properties()); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java index 8ae1bfb6ca4..da9caf1a825 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/MutableModuleSettings.java @@ -19,7 +19,6 @@ */ package org.sonar.scanner.scan; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -68,25 +67,12 @@ public class MutableModuleSettings extends Settings { } private void addBuildProperties(ProjectDefinition project) { - List orderedProjects = getTopDownParentProjects(project); + List orderedProjects = ModuleSettingsProvider.getTopDownParentProjects(project); for (ProjectDefinition p : orderedProjects) { addProperties(p.properties()); } } - /** - * From root to given project - */ - static List getTopDownParentProjects(ProjectDefinition project) { - List result = new ArrayList<>(); - ProjectDefinition p = project; - while (p != null) { - result.add(0, p); - p = p.getParent(); - } - return result; - } - @Override protected Optional get(String key) { if (analysisMode.isIssues() && key.endsWith(".secured") && !key.contains(".license")) { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java index f1a150d800f..c0e4d487632 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/MutableModuleSettingsTest.java @@ -76,7 +76,7 @@ public class MutableModuleSettingsTest { grandParent.addSubProject(parent); parent.addSubProject(child); - List hierarchy = MutableModuleSettings.getTopDownParentProjects(child); + List hierarchy = ModuleSettingsProvider.getTopDownParentProjects(child); assertThat(hierarchy.get(0)).isEqualTo(grandParent); assertThat(hierarchy.get(1)).isEqualTo(parent); assertThat(hierarchy.get(2)).isEqualTo(child); -- 2.39.5