private Configuration settings;
private List<IssuePattern> multicriteriaPatterns;
- protected AbstractPatternInitializer(Configuration settings) {
- this.settings = settings;
+ protected AbstractPatternInitializer(Configuration config) {
+ this.settings = config;
initPatterns();
}
@Override
protected String getMulticriteriaConfigurationKey() {
- return "sonar.issue.ignore" + ".multicriteria";
+ return IssueExclusionProperties.EXCLUSION_KEY_PREFIX + ".multicriteria";
}
@Override
package org.sonar.scanner.issue.ignore.pattern;
import org.sonar.api.config.Configuration;
+import org.sonar.core.config.IssueExclusionProperties;
public class IssueInclusionPatternInitializer extends AbstractPatternInitializer {
@Override
protected String getMulticriteriaConfigurationKey() {
- return "sonar.issue.enforce" + ".multicriteria";
+ return IssueExclusionProperties.INCLUSION_KEY_PREFIX + ".multicriteria";
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.scan;
+
+import java.util.Map;
+import org.sonar.api.config.Encryption;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.config.DefaultConfiguration;
+
+public class ModuleConfiguration extends DefaultConfiguration {
+
+ public ModuleConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode, Map<String, String> props) {
+ super(propertyDefinitions, encryption, mode, props);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.scan;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.fs.internal.DefaultInputModule;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.report.AnalysisContextReportPublisher;
+import org.sonar.scanner.repository.ProjectRepositories;
+
+public class ModuleConfigurationProvider extends ProviderAdapter {
+
+ private ModuleConfiguration moduleConfiguration;
+
+ public ModuleConfiguration provide(GlobalConfiguration globalConfig, DefaultInputModule module, ProjectRepositories projectRepos,
+ GlobalAnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) {
+ if (moduleConfiguration == null) {
+
+ Map<String, String> settings = new LinkedHashMap<>();
+ settings.putAll(globalConfig.getProperties());
+ settings.putAll(addServerSidePropertiesIfModuleExists(projectRepos, module.definition()));
+ addScannerSideProperties(settings, module.definition());
+ contextReportPublisher.dumpModuleSettings(module);
+
+ moduleConfiguration = new ModuleConfiguration(globalConfig.getDefinitions(), globalConfig.getEncryption(), analysisMode, settings);
+ }
+ return moduleConfiguration;
+ }
+
+ private static Map<String, String> addServerSidePropertiesIfModuleExists(ProjectRepositories projectRepos, ProjectDefinition def) {
+ if (projectRepos.moduleExists(def.getKeyWithBranch())) {
+ return projectRepos.settings(def.getKeyWithBranch());
+ } else {
+ // Module doesn't exist on server. Try to add parent server settings as inheritance.
+ ProjectDefinition parentDef = def.getParent();
+ if (parentDef != null) {
+ return addServerSidePropertiesIfModuleExists(projectRepos, parentDef);
+ }
+ return Collections.emptyMap();
+ }
+ }
+
+ private static void addScannerSideProperties(Map<String, String> settings, ProjectDefinition project) {
+ List<ProjectDefinition> orderedProjects = getTopDownParentProjects(project);
+ for (ProjectDefinition p : orderedProjects) {
+ settings.putAll(p.properties());
+ }
+ }
+
+ /**
+ * From root to given project
+ */
+ static List<ProjectDefinition> getTopDownParentProjects(ProjectDefinition project) {
+ List<ProjectDefinition> result = new ArrayList<>();
+ ProjectDefinition p = project;
+ while (p != null) {
+ result.add(0, p);
+ p = p.getParent();
+ }
+ return result;
+ }
+}
module.definition(),
module,
MutableModuleSettings.class,
- new ModuleSettingsProvider());
+ new ModuleConfigurationProvider());
if (analysisMode.isIssues()) {
add(
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.scanner.scan;
-
-import java.util.Map;
-import org.sonar.api.config.Encryption;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
-import org.sonar.scanner.config.DefaultConfiguration;
-
-public class ModuleSettings extends DefaultConfiguration {
-
- public ModuleSettings(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode, Map<String, String> props) {
- super(propertyDefinitions, encryption, mode, props);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.scanner.scan;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.fs.internal.DefaultInputModule;
-import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
-import org.sonar.scanner.bootstrap.GlobalConfiguration;
-import org.sonar.scanner.report.AnalysisContextReportPublisher;
-import org.sonar.scanner.repository.ProjectRepositories;
-
-public class ModuleSettingsProvider extends ProviderAdapter {
-
- private ModuleSettings projectSettings;
-
- public ModuleSettings provide(GlobalConfiguration globalSettings, DefaultInputModule module, ProjectRepositories projectRepos,
- GlobalAnalysisMode analysisMode, AnalysisContextReportPublisher contextReportPublisher) {
- if (projectSettings == null) {
-
- Map<String, String> settings = new LinkedHashMap<>();
- settings.putAll(globalSettings.getProperties());
- settings.putAll(addServerSidePropertiesIfModuleExists(projectRepos, module.definition()));
- addScannerSideProperties(settings, module.definition());
- contextReportPublisher.dumpModuleSettings(module);
-
- projectSettings = new ModuleSettings(globalSettings.getDefinitions(), globalSettings.getEncryption(), analysisMode, settings);
- }
- return projectSettings;
- }
-
- private static Map<String, String> addServerSidePropertiesIfModuleExists(ProjectRepositories projectRepos, ProjectDefinition def) {
- if (projectRepos.moduleExists(def.getKeyWithBranch())) {
- return projectRepos.settings(def.getKeyWithBranch());
- } else {
- // Module doesn't exist on server. Try to add parent server settings as inheritance.
- ProjectDefinition parentDef = def.getParent();
- if (parentDef != null) {
- return addServerSidePropertiesIfModuleExists(projectRepos, parentDef);
- }
- return Collections.emptyMap();
- }
- }
-
- private static void addScannerSideProperties(Map<String, String> settings, ProjectDefinition project) {
- List<ProjectDefinition> orderedProjects = getTopDownParentProjects(project);
- for (ProjectDefinition p : orderedProjects) {
- settings.putAll(p.properties());
- }
- }
-
- /**
- * From root to given project
- */
- static List<ProjectDefinition> getTopDownParentProjects(ProjectDefinition project) {
- List<ProjectDefinition> result = new ArrayList<>();
- ProjectDefinition p = project;
- while (p != null) {
- result.add(0, p);
- p = p.getParent();
- }
- return result;
- }
-}
import static java.util.Objects.requireNonNull;
/**
- * @deprecated since 6.5 {@link ModuleSettings} used to be mutable, so keep a mutable copy for backward compatibility.
+ * @deprecated since 6.5 {@link ModuleConfiguration} used to be mutable, so keep a mutable copy for backward compatibility.
*/
@Deprecated
public class MutableModuleSettings extends Settings {
}
private void addBuildProperties(ProjectDefinition project) {
- List<ProjectDefinition> orderedProjects = ModuleSettingsProvider.getTopDownParentProjects(project);
+ List<ProjectDefinition> orderedProjects = ModuleConfigurationProvider.getTopDownParentProjects(project);
for (ProjectDefinition p : orderedProjects) {
addProperties(p.properties());
}
import static java.util.Objects.requireNonNull;
/**
- * @deprecated since 6.5 {@link ProjectSettings} used to be mutable, so keep a mutable copy for backward compatibility.
+ * @deprecated since 6.5 {@link ProjectConfiguration} used to be mutable, so keep a mutable copy for backward compatibility.
*/
@Deprecated
public class MutableProjectSettings extends Settings {
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.scan;
+
+import java.util.Map;
+import org.sonar.api.config.Encryption;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.config.DefaultConfiguration;
+
+public class ProjectConfiguration extends DefaultConfiguration {
+
+ public ProjectConfiguration(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode, Map<String, String> props) {
+ super(propertyDefinitions, encryption, mode, props);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.scan;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
+import org.sonar.scanner.repository.ProjectRepositories;
+
+public class ProjectConfigurationProvider extends ProviderAdapter {
+
+ private ProjectConfiguration projectConfig;
+
+ public ProjectConfiguration provide(ProjectReactor reactor, GlobalConfiguration globalSettings, ProjectRepositories projectRepositories, GlobalAnalysisMode mode) {
+ if (projectConfig == null) {
+
+ Map<String, String> settings = new LinkedHashMap<>();
+ settings.putAll(globalSettings.getProperties());
+ settings.putAll(projectRepositories.settings(reactor.getRoot().getKeyWithBranch()));
+ settings.putAll(reactor.getRoot().properties());
+
+ projectConfig = new ProjectConfiguration(globalSettings.getDefinitions(), globalSettings.getEncryption(), mode, settings);
+ }
+ return projectConfig;
+ }
+}
@Override
protected void doBeforeStart() {
- addBatchComponents();
- addBatchExtensions();
+ addScannerComponents();
+ addScannerExtensions();
ProjectLock lock = getComponentByType(ProjectLock.class);
lock.tryLock();
getComponentByType(WorkDirectoriesInitializer.class).execute();
}
- private void addBatchComponents() {
+ private void addScannerComponents() {
add(
props,
ProjectReactorBuilder.class,
MutableProjectSettings.class,
ScannerProperties.class,
- new ProjectSettingsProvider(),
+ new ProjectConfigurationProvider(),
// Report
ScannerMetrics.class,
return getComponentByType(GlobalAnalysisMode.class).isIssues();
}
- private void addBatchExtensions() {
+ private void addScannerExtensions() {
getComponentByType(CoreExtensionsInstaller.class)
- .install(this, noExtensionFilter(), extension -> isInstantiationStrategy(extension, PER_BATCH));
+ .install(this, noExtensionFilter(), extension -> getScannerProjectExtensionsFilter().accept(extension));
getComponentByType(ExtensionInstaller.class)
- .install(this, getBatchPluginExtensionsFilter());
+ .install(this, getScannerProjectExtensionsFilter());
}
@VisibleForTesting
- static ExtensionMatcher getBatchPluginExtensionsFilter() {
+ static ExtensionMatcher getScannerProjectExtensionsFilter() {
return extension -> isScannerSide(extension) || (isDeprecatedScannerSide(extension) && isInstantiationStrategy(extension, PER_BATCH));
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.scanner.scan;
-
-import java.util.Map;
-import org.sonar.api.config.Encryption;
-import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
-import org.sonar.scanner.config.DefaultConfiguration;
-
-public class ProjectSettings extends DefaultConfiguration {
-
- public ProjectSettings(PropertyDefinitions propertyDefinitions, Encryption encryption, GlobalAnalysisMode mode, Map<String, String> props) {
- super(propertyDefinitions, encryption, mode, props);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.scanner.scan;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
-import org.sonar.scanner.bootstrap.GlobalConfiguration;
-import org.sonar.scanner.repository.ProjectRepositories;
-
-public class ProjectSettingsProvider extends ProviderAdapter {
-
- private ProjectSettings projectSettings;
-
- public ProjectSettings provide(ProjectReactor reactor, GlobalConfiguration globalSettings, ProjectRepositories projectRepositories, GlobalAnalysisMode mode) {
- if (projectSettings == null) {
-
- Map<String, String> settings = new LinkedHashMap<>();
- settings.putAll(globalSettings.getProperties());
- settings.putAll(projectRepositories.settings(reactor.getRoot().getKeyWithBranch()));
- settings.putAll(reactor.getRoot().properties());
-
- projectSettings = new ProjectSettings(globalSettings.getDefinitions(), globalSettings.getEncryption(), mode, settings);
- }
- return projectSettings;
- }
-}
}
private static Supplier<Map<String, String>> createSettingsSupplier(GlobalConfiguration globalConfiguration, ProjectDefinition root, SettingsLoader settingsLoader) {
- // we can't get ProjectSettings because it creates a circular dependency.
+ // we can't get ProjectConfiguration because it creates a circular dependency.
// We create our own settings which will only be loaded if needed.
return () -> {
Map<String, String> settings = new HashMap<>();
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 org.sonar.scanner.scan.ProjectConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
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);
+ DefaultConfiguration config = new ProjectConfiguration(defs, new Encryption(null), mock(GlobalAnalysisMode.class), settings);
Set<String> reportPaths = new GenericCoverageSensor(config).loadReportPaths();
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 org.sonar.scanner.scan.ProjectConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
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);
+ DefaultConfiguration config = new ProjectConfiguration(defs, new Encryption(null), mock(GlobalAnalysisMode.class), settings);
new GenericTestExecutionSensor(mock(TestPlanBuilder.class), config).execute(context);
assertThat(logTester.logs(LoggerLevel.WARN)).contains(
grandParent.addSubProject(parent);
parent.addSubProject(child);
- List<ProjectDefinition> hierarchy = ModuleSettingsProvider.getTopDownParentProjects(child);
+ List<ProjectDefinition> hierarchy = ModuleConfigurationProvider.getTopDownParentProjects(child);
assertThat(hierarchy.get(0)).isEqualTo(grandParent);
assertThat(hierarchy.get(1)).isEqualTo(parent);
assertThat(hierarchy.get(2)).isEqualTo(child);
@Test
public void should_add_only_batch_extensions() {
- ExtensionMatcher filter = ProjectScanContainer.getBatchPluginExtensionsFilter();
+ ExtensionMatcher filter = ProjectScanContainer.getScannerProjectExtensionsFilter();
assertThat(filter.accept(new MyBatchExtension())).isTrue();
assertThat(filter.accept(MyBatchExtension.class)).isTrue();