aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2023-12-22 10:28:22 +0100
committersonartech <sonartech@sonarsource.com>2023-12-22 20:03:01 +0000
commit6c6de5ad4fac7a44abcc6a0ae7d9cb5c7a53da51 (patch)
tree43710bdc5975d01b9336c229d0aa68a0fa66f4e2 /sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap
parent83fe248f66dcc3a909eb411f917795c054445723 (diff)
downloadsonarqube-6c6de5ad4fac7a44abcc6a0ae7d9cb5c7a53da51.tar.gz
sonarqube-6c6de5ad4fac7a44abcc6a0ae7d9cb5c7a53da51.zip
Revert "SONAR-21195 Enhance scanner engine to download only required plugins"
This reverts commit 981e6b85954f413666e8608a4e2f46fa2e4089cc.
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java11
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PluginInstaller.java17
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java83
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java58
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java9
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringScannerContainer.java346
6 files changed, 31 insertions, 493 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java
index c9ed8839af6..d99b1da967b 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ExtensionInstaller.java
@@ -19,7 +19,6 @@
*/
package org.sonar.scanner.bootstrap;
-import java.util.Collection;
import javax.annotation.Nullable;
import org.sonar.api.Plugin;
import org.sonar.api.SonarRuntime;
@@ -48,13 +47,7 @@ public class ExtensionInstaller {
}
// plugin extensions
- installExtensionsForPlugins(container, matcher, pluginRepository.getPluginInfos());
-
- return this;
- }
-
- public void installExtensionsForPlugins(ExtensionContainer container, ExtensionMatcher matcher, Collection<PluginInfo> pluginInfos) {
- for (PluginInfo pluginInfo : pluginInfos) {
+ for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
Plugin plugin = pluginRepository.getPluginInstance(pluginInfo.getKey());
Plugin.Context context = new PluginContextImpl.Builder()
.setSonarRuntime(sonarRuntime)
@@ -66,6 +59,8 @@ public class ExtensionInstaller {
doInstall(container, matcher, pluginInfo, extension);
}
}
+
+ return this;
}
private static void doInstall(ExtensionContainer container, ExtensionMatcher matcher, @Nullable PluginInfo pluginInfo, Object extension) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PluginInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PluginInstaller.java
index eeb35462dab..3a0b93461f2 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PluginInstaller.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/PluginInstaller.java
@@ -21,28 +21,15 @@ package org.sonar.scanner.bootstrap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
public interface PluginInstaller {
/**
- * Loads/downloads all plugins that are installed on the server.
- * @return information about all installed plugins, grouped by key
- */
- Map<String, ScannerPlugin> installAllPlugins();
-
- /**
- * Gets the list of plugins that are not required for any specific languages and downloads them if not
+ * Gets the list of plugins installed on server and downloads them if not
* already in local cache.
* @return information about all installed plugins, grouped by key
*/
- Map<String, ScannerPlugin> installRequiredPlugins();
-
- /**
- * Loads/downloads plugins that are required for the given languageKeys.
- * @return information about any plugins installed by this call, grouped by key
- */
- Map<String, ScannerPlugin> installPluginsForLanguages(Set<String> languageKeys);
+ Map<String, ScannerPlugin> installRemotes();
/**
* Used only by medium tests.
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java
index efed3403147..a38452c5e16 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java
@@ -22,14 +22,11 @@ package org.sonar.scanner.bootstrap;
import com.google.gson.Gson;
import java.io.File;
import java.io.Reader;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.Set;
-import java.util.function.Predicate;
import javax.annotation.Nullable;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -51,58 +48,21 @@ public class ScannerPluginInstaller implements PluginInstaller {
private final PluginFiles pluginFiles;
private final DefaultScannerWsClient wsClient;
- private List<InstalledPlugin> availablePlugins;
-
public ScannerPluginInstaller(PluginFiles pluginFiles, DefaultScannerWsClient wsClient) {
this.pluginFiles = pluginFiles;
this.wsClient = wsClient;
}
@Override
- public Map<String, ScannerPlugin> installAllPlugins() {
- LOG.info("Loading all plugins");
- return installPlugins(p -> true).installedPluginsByKey;
- }
-
- @Override
- public Map<String, ScannerPlugin> installRequiredPlugins() {
- LOG.info("Loading required plugins");
- InstallResult result = installPlugins(p -> p.getRequiredForLanguages() == null || p.getRequiredForLanguages().isEmpty());
-
- LOG.debug("Plugins not loaded because they are optional: {}", result.skippedPlugins);
-
- return result.installedPluginsByKey;
- }
-
- @Override
- public Map<String, ScannerPlugin> installPluginsForLanguages(Set<String> languageKeys) {
- LOG.info("Loading plugins for detected languages");
- LOG.debug("Detected languages: {}", languageKeys);
- InstallResult result = installPlugins(
- p -> p.getRequiredForLanguages() != null && !Collections.disjoint(p.getRequiredForLanguages(), languageKeys)
- );
-
- List<InstalledPlugin> skippedLanguagePlugins = result.skippedPlugins.stream()
- .filter(p -> p.getRequiredForLanguages() != null && !p.getRequiredForLanguages().isEmpty()).toList();
- LOG.debug("Optional language-specific plugins not loaded: {}", skippedLanguagePlugins);
-
- return result.installedPluginsByKey;
- }
-
- private InstallResult installPlugins(Predicate<InstalledPlugin> pluginFilter) {
- if (this.availablePlugins == null) {
- this.availablePlugins = listInstalledPlugins();
- }
-
+ public Map<String, ScannerPlugin> installRemotes() {
Profiler profiler = Profiler.create(LOG).startInfo("Load/download plugins");
try {
- InstallResult result = new InstallResult();
- Loaded loaded = loadPlugins(result, pluginFilter);
+ Map<String, ScannerPlugin> result = new HashMap<>();
+ Loaded loaded = loadPlugins(result);
if (!loaded.ok) {
// retry once, a plugin may have been uninstalled during downloads
- this.availablePlugins = listInstalledPlugins();
- result.installedPluginsByKey.clear();
- loaded = loadPlugins(result, pluginFilter);
+ result.clear();
+ loaded = loadPlugins(result);
if (!loaded.ok) {
throw new IllegalStateException(format("Fail to download plugin [%s]. Not found.", loaded.notFoundPlugin));
}
@@ -113,23 +73,16 @@ public class ScannerPluginInstaller implements PluginInstaller {
}
}
- private Loaded loadPlugins(InstallResult result, Predicate<InstalledPlugin> pluginFilter) {
- List<InstalledPlugin> pluginsToInstall = availablePlugins.stream()
- .filter(pluginFilter).toList();
-
- for (InstalledPlugin plugin : pluginsToInstall) {
+ private Loaded loadPlugins(Map<String, ScannerPlugin> result) {
+ for (InstalledPlugin plugin : listInstalledPlugins()) {
Optional<File> jarFile = pluginFiles.get(plugin);
if (jarFile.isEmpty()) {
return new Loaded(false, plugin.key);
}
PluginInfo info = PluginInfo.create(jarFile.get());
- result.installedPluginsByKey.put(info.getKey(), new ScannerPlugin(plugin.key, plugin.updatedAt, PluginType.valueOf(plugin.type), info));
+ result.put(info.getKey(), new ScannerPlugin(plugin.key, plugin.updatedAt, PluginType.valueOf(plugin.type), info));
}
-
- result.skippedPlugins = availablePlugins.stream()
- .filter(Predicate.not(pluginFilter)).toList();
-
return new Loaded(true, null);
}
@@ -144,7 +97,7 @@ public class ScannerPluginInstaller implements PluginInstaller {
/**
* Gets information about the plugins installed on server (filename, checksum)
*/
- private List<InstalledPlugin> listInstalledPlugins() {
+ private InstalledPlugin[] listInstalledPlugins() {
Profiler profiler = Profiler.create(LOG).startInfo("Load plugins index");
GetRequest getRequest = new GetRequest(PLUGINS_WS_URL);
InstalledPlugins installedPlugins;
@@ -158,13 +111,8 @@ public class ScannerPluginInstaller implements PluginInstaller {
return installedPlugins.plugins;
}
- private static class InstallResult {
- Map<String, ScannerPlugin> installedPluginsByKey = new HashMap<>();
- List<InstalledPlugin> skippedPlugins = new ArrayList<>();
- }
-
private static class InstalledPlugins {
- List<InstalledPlugin> plugins;
+ InstalledPlugin[] plugins;
public InstalledPlugins() {
// http://stackoverflow.com/a/18645370/229031
@@ -176,21 +124,10 @@ public class ScannerPluginInstaller implements PluginInstaller {
String hash;
long updatedAt;
String type;
- private Set<String> requiredForLanguages;
public InstalledPlugin() {
// http://stackoverflow.com/a/18645370/229031
}
-
- public Set<String> getRequiredForLanguages() {
- return requiredForLanguages;
- }
-
- @Override
- public String toString() {
- return key;
- }
-
}
private static class Loaded {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java
index 3ce0202292b..af61c721555 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java
@@ -20,16 +20,14 @@
package org.sonar.scanner.bootstrap;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.Plugin;
import org.sonar.api.Startable;
-import org.sonar.api.config.Configuration;
import org.sonar.core.platform.ExplodedPlugin;
import org.sonar.core.platform.PluginClassLoader;
import org.sonar.core.platform.PluginInfo;
@@ -37,7 +35,6 @@ import org.sonar.core.platform.PluginJarExploder;
import org.sonar.core.platform.PluginRepository;
import org.sonar.core.plugin.PluginType;
-import static java.util.stream.Collectors.toMap;
import static org.sonar.api.utils.Preconditions.checkState;
/**
@@ -50,33 +47,22 @@ public class ScannerPluginRepository implements PluginRepository, Startable {
private final PluginJarExploder pluginJarExploder;
private final PluginClassLoader loader;
- private final Configuration properties;
-
private Map<String, Plugin> pluginInstancesByKeys;
private Map<String, ScannerPlugin> pluginsByKeys;
private Map<ClassLoader, String> keysByClassLoader;
- private boolean shouldLoadAllPluginsOnStart;
- public ScannerPluginRepository(PluginInstaller installer, PluginJarExploder pluginJarExploder, PluginClassLoader loader, Configuration properties) {
+ public ScannerPluginRepository(PluginInstaller installer, PluginJarExploder pluginJarExploder, PluginClassLoader loader) {
this.installer = installer;
this.pluginJarExploder = pluginJarExploder;
this.loader = loader;
- this.properties = properties;
}
@Override
public void start() {
- shouldLoadAllPluginsOnStart = properties.getBoolean("sonar.plugins.loadAll").orElse(false);
- if (shouldLoadAllPluginsOnStart) {
- LOG.warn("sonar.plugins.loadAll is true, so ALL available plugins will be downloaded");
- pluginsByKeys = new HashMap<>(installer.installAllPlugins());
- } else {
- pluginsByKeys = new HashMap<>(installer.installRequiredPlugins());
- }
-
- Map<String, ExplodedPlugin> explodedPluginsByKey = pluginsByKeys.entrySet().stream()
- .collect(toMap(Map.Entry::getKey, e -> pluginJarExploder.explode(e.getValue().getInfo())));
- pluginInstancesByKeys = new HashMap<>(loader.load(explodedPluginsByKey));
+ pluginsByKeys = new HashMap<>(installer.installRemotes());
+ Map<String, ExplodedPlugin> explodedPLuginsByKey = pluginsByKeys.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, e -> pluginJarExploder.explode(e.getValue().getInfo())));
+ pluginInstancesByKeys = new HashMap<>(loader.load(explodedPLuginsByKey));
// this part is only used by medium tests
for (Object[] localPlugin : installer.installLocals()) {
@@ -91,29 +77,7 @@ public class ScannerPluginRepository implements PluginRepository, Startable {
keysByClassLoader.put(e.getValue().getClass().getClassLoader(), e.getKey());
}
- logPlugins(pluginsByKeys.values());
- }
-
- public Collection<PluginInfo> installPluginsForLanguages(Set<String> languageKeys) {
- if (shouldLoadAllPluginsOnStart) {
- return Collections.emptySet();
- }
-
- var languagePluginsByKeys = new HashMap<>(installer.installPluginsForLanguages(languageKeys));
-
- pluginsByKeys.putAll(languagePluginsByKeys);
-
- Map<String, ExplodedPlugin> explodedPluginsByKey = languagePluginsByKeys.entrySet().stream()
- .collect(toMap(Map.Entry::getKey, e -> pluginJarExploder.explode(e.getValue().getInfo())));
- pluginInstancesByKeys.putAll(new HashMap<>(loader.load(explodedPluginsByKey)));
-
- keysByClassLoader = new HashMap<>();
- for (Map.Entry<String, Plugin> e : pluginInstancesByKeys.entrySet()) {
- keysByClassLoader.put(e.getValue().getClass().getClassLoader(), e.getKey());
- }
-
- logPlugins(languagePluginsByKeys.values());
- return languagePluginsByKeys.values().stream().map(ScannerPlugin::getInfo).toList();
+ logPlugins();
}
@CheckForNull
@@ -121,12 +85,12 @@ public class ScannerPluginRepository implements PluginRepository, Startable {
return keysByClassLoader.get(cl);
}
- private static void logPlugins(Collection<ScannerPlugin> plugins) {
- if (plugins.isEmpty()) {
+ private void logPlugins() {
+ if (pluginsByKeys.isEmpty()) {
LOG.debug("No plugins loaded");
} else {
- LOG.debug("Plugins loaded:");
- for (ScannerPlugin p : plugins) {
+ LOG.debug("Plugins:");
+ for (ScannerPlugin p : pluginsByKeys.values()) {
LOG.debug(" * {} {} ({})", p.getName(), p.getVersion(), p.getKey());
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java
index 41c81d2fea6..9b7bd6c4eab 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java
@@ -54,8 +54,9 @@ import org.sonar.scanner.repository.DefaultMetricsRepositoryLoader;
import org.sonar.scanner.repository.DefaultNewCodePeriodLoader;
import org.sonar.scanner.repository.MetricsRepositoryProvider;
import org.sonar.scanner.repository.settings.DefaultGlobalSettingsLoader;
+import org.sonar.scanner.scan.SpringProjectScanContainer;
-@Priority(4)
+@Priority(3)
public class SpringGlobalContainer extends SpringComponentContainer {
private static final Logger LOG = LoggerFactory.getLogger(SpringGlobalContainer.class);
private final Map<String, String> scannerProperties;
@@ -119,7 +120,7 @@ public class SpringGlobalContainer extends SpringComponentContainer {
@Override
protected void doAfterStart() {
- installRequiredPlugins();
+ installPlugins();
loadCoreExtensions();
long startTime = System.currentTimeMillis();
@@ -135,12 +136,12 @@ public class SpringGlobalContainer extends SpringComponentContainer {
throw MessageException.of("The preview mode, along with the 'sonar.analysis.mode' parameter, is no more supported. You should stop using this parameter.");
}
getComponentByType(RuntimeJavaVersion.class).checkJavaVersion();
- new SpringScannerContainer(this).execute();
+ new SpringProjectScanContainer(this).execute();
LOG.info("Analysis total time: {}", formatTime(System.currentTimeMillis() - startTime));
}
- private void installRequiredPlugins() {
+ private void installPlugins() {
PluginRepository pluginRepository = getComponentByType(PluginRepository.class);
for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
Plugin instance = pluginRepository.getPluginInstance(pluginInfo.getKey());
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringScannerContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringScannerContainer.java
deleted file mode 100644
index eedc07f9924..00000000000
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringScannerContainer.java
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 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.bootstrap;
-
-import javax.annotation.Nullable;
-import javax.annotation.Priority;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.fs.internal.FileMetadata;
-import org.sonar.api.batch.fs.internal.SensorStrategy;
-import org.sonar.api.batch.rule.CheckFactory;
-import org.sonar.api.batch.sensor.issue.internal.DefaultNoSonarFilter;
-import org.sonar.api.scan.filesystem.PathResolver;
-import org.sonar.api.utils.MessageException;
-import org.sonar.core.extension.CoreExtensionsInstaller;
-import org.sonar.core.metric.ScannerMetrics;
-import org.sonar.core.platform.SpringComponentContainer;
-import org.sonar.scanner.DefaultFileLinesContextFactory;
-import org.sonar.scanner.ProjectInfo;
-import org.sonar.scanner.analysis.AnalysisTempFolderProvider;
-import org.sonar.scanner.cache.AnalysisCacheEnabled;
-import org.sonar.scanner.cache.AnalysisCacheMemoryStorage;
-import org.sonar.scanner.cache.AnalysisCacheProvider;
-import org.sonar.scanner.cache.DefaultAnalysisCacheLoader;
-import org.sonar.scanner.ci.CiConfigurationProvider;
-import org.sonar.scanner.ci.vendors.AppVeyor;
-import org.sonar.scanner.ci.vendors.AwsCodeBuild;
-import org.sonar.scanner.ci.vendors.AzureDevops;
-import org.sonar.scanner.ci.vendors.Bamboo;
-import org.sonar.scanner.ci.vendors.BitbucketPipelines;
-import org.sonar.scanner.ci.vendors.Bitrise;
-import org.sonar.scanner.ci.vendors.Buildkite;
-import org.sonar.scanner.ci.vendors.CircleCi;
-import org.sonar.scanner.ci.vendors.CirrusCi;
-import org.sonar.scanner.ci.vendors.CodeMagic;
-import org.sonar.scanner.ci.vendors.DroneCi;
-import org.sonar.scanner.ci.vendors.GithubActions;
-import org.sonar.scanner.ci.vendors.GitlabCi;
-import org.sonar.scanner.ci.vendors.Jenkins;
-import org.sonar.scanner.ci.vendors.SemaphoreCi;
-import org.sonar.scanner.ci.vendors.TravisCi;
-import org.sonar.scanner.cpd.CpdExecutor;
-import org.sonar.scanner.cpd.CpdSettings;
-import org.sonar.scanner.cpd.index.SonarCpdBlockIndex;
-import org.sonar.scanner.issue.IssueFilters;
-import org.sonar.scanner.issue.IssuePublisher;
-import org.sonar.scanner.issue.ignore.EnforceIssuesFilter;
-import org.sonar.scanner.issue.ignore.IgnoreIssuesFilter;
-import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer;
-import org.sonar.scanner.issue.ignore.pattern.IssueInclusionPatternInitializer;
-import org.sonar.scanner.issue.ignore.scanner.IssueExclusionsLoader;
-import org.sonar.scanner.report.ActiveRulesPublisher;
-import org.sonar.scanner.report.AnalysisCachePublisher;
-import org.sonar.scanner.report.AnalysisContextReportPublisher;
-import org.sonar.scanner.report.AnalysisWarningsPublisher;
-import org.sonar.scanner.report.CeTaskReportDataHolder;
-import org.sonar.scanner.report.ChangedLinesPublisher;
-import org.sonar.scanner.report.ComponentsPublisher;
-import org.sonar.scanner.report.JavaArchitectureInformationProvider;
-import org.sonar.scanner.report.MetadataPublisher;
-import org.sonar.scanner.report.ReportPublisher;
-import org.sonar.scanner.report.ScannerFileStructureProvider;
-import org.sonar.scanner.report.SourcePublisher;
-import org.sonar.scanner.report.TestExecutionPublisher;
-import org.sonar.scanner.repository.ContextPropertiesCache;
-import org.sonar.scanner.repository.DefaultProjectRepositoriesLoader;
-import org.sonar.scanner.repository.DefaultQualityProfileLoader;
-import org.sonar.scanner.repository.ProjectRepositoriesProvider;
-import org.sonar.scanner.repository.QualityProfilesProvider;
-import org.sonar.scanner.repository.ReferenceBranchSupplier;
-import org.sonar.scanner.repository.language.DefaultLanguagesRepository;
-import org.sonar.scanner.repository.language.LanguagesRepository;
-import org.sonar.scanner.repository.settings.DefaultProjectSettingsLoader;
-import org.sonar.scanner.rule.ActiveRulesProvider;
-import org.sonar.scanner.rule.DefaultActiveRulesLoader;
-import org.sonar.scanner.rule.QProfileVerifier;
-import org.sonar.scanner.scan.DeprecatedPropertiesWarningGenerator;
-import org.sonar.scanner.scan.InputModuleHierarchyProvider;
-import org.sonar.scanner.scan.InputProjectProvider;
-import org.sonar.scanner.scan.ModuleIndexer;
-import org.sonar.scanner.scan.MutableProjectReactorProvider;
-import org.sonar.scanner.scan.MutableProjectSettings;
-import org.sonar.scanner.scan.ProjectBuildersExecutor;
-import org.sonar.scanner.scan.ProjectConfigurationProvider;
-import org.sonar.scanner.scan.ProjectLock;
-import org.sonar.scanner.scan.ProjectReactorBuilder;
-import org.sonar.scanner.scan.ProjectReactorValidator;
-import org.sonar.scanner.scan.ProjectServerSettingsProvider;
-import org.sonar.scanner.scan.ScanProperties;
-import org.sonar.scanner.scan.SonarGlobalPropertiesFilter;
-import org.sonar.scanner.scan.SpringProjectScanContainer;
-import org.sonar.scanner.scan.WorkDirectoriesInitializer;
-import org.sonar.scanner.scan.branch.BranchConfiguration;
-import org.sonar.scanner.scan.branch.BranchConfigurationProvider;
-import org.sonar.scanner.scan.branch.BranchType;
-import org.sonar.scanner.scan.branch.ProjectBranchesProvider;
-import org.sonar.scanner.scan.filesystem.DefaultProjectFileSystem;
-import org.sonar.scanner.scan.filesystem.FileIndexer;
-import org.sonar.scanner.scan.filesystem.InputComponentStore;
-import org.sonar.scanner.scan.filesystem.LanguageDetection;
-import org.sonar.scanner.scan.filesystem.MetadataGenerator;
-import org.sonar.scanner.scan.filesystem.ProjectCoverageAndDuplicationExclusions;
-import org.sonar.scanner.scan.filesystem.ProjectExclusionFilters;
-import org.sonar.scanner.scan.filesystem.ProjectFileIndexer;
-import org.sonar.scanner.scan.filesystem.ScannerComponentIdGenerator;
-import org.sonar.scanner.scan.filesystem.StatusDetection;
-import org.sonar.scanner.scan.measure.DefaultMetricFinder;
-import org.sonar.scanner.scm.ScmChangedFilesProvider;
-import org.sonar.scanner.scm.ScmConfiguration;
-import org.sonar.scanner.scm.ScmPublisher;
-import org.sonar.scanner.scm.ScmRevisionImpl;
-import org.sonar.scanner.sensor.DefaultSensorStorage;
-import org.sonar.scanner.sensor.ExecutingSensorContext;
-import org.sonar.scanner.sensor.ProjectSensorContext;
-import org.sonar.scanner.sensor.ProjectSensorOptimizer;
-import org.sonar.scanner.sensor.UnchangedFilesHandler;
-import org.sonar.scm.git.GitScmSupport;
-import org.sonar.scm.svn.SvnScmSupport;
-
-import static org.sonar.api.batch.InstantiationStrategy.PER_BATCH;
-import static org.sonar.core.extension.CoreExtensionsInstaller.noExtensionFilter;
-import static org.sonar.scanner.bootstrap.ExtensionUtils.isDeprecatedScannerSide;
-import static org.sonar.scanner.bootstrap.ExtensionUtils.isInstantiationStrategy;
-import static org.sonar.scanner.bootstrap.ExtensionUtils.isScannerSide;
-
-@Priority(3)
-public class SpringScannerContainer extends SpringComponentContainer {
- private static final Logger LOG = LoggerFactory.getLogger(SpringScannerContainer.class);
-
- public SpringScannerContainer(SpringComponentContainer globalContainer) {
- super(globalContainer);
- }
-
- @Override
- protected void doBeforeStart() {
- addScannerExtensions();
- addComponents();
- }
-
- private void addScannerExtensions() {
- getParentComponentByType(CoreExtensionsInstaller.class)
- .install(this, noExtensionFilter(), extension -> getScannerProjectExtensionsFilter().accept(extension));
- getParentComponentByType(ExtensionInstaller.class)
- .install(this, getScannerProjectExtensionsFilter());
- }
-
- private void addComponents() {
- add(
- ScanProperties.class,
- ProjectReactorBuilder.class,
- WorkDirectoriesInitializer.class,
- new MutableProjectReactorProvider(),
- ProjectBuildersExecutor.class,
- ProjectLock.class,
- ProjectReactorValidator.class,
- ProjectInfo.class,
- new BranchConfigurationProvider(),
- new ProjectBranchesProvider(),
- ProjectRepositoriesProvider.class,
- new ProjectServerSettingsProvider(),
- AnalysisCacheEnabled.class,
- DeprecatedPropertiesWarningGenerator.class,
-
- // temp
- new AnalysisTempFolderProvider(),
-
- // file system
- ModuleIndexer.class,
- InputComponentStore.class,
- PathResolver.class,
- new InputProjectProvider(),
- new InputModuleHierarchyProvider(),
- ScannerComponentIdGenerator.class,
- new ScmChangedFilesProvider(),
- StatusDetection.class,
- LanguageDetection.class,
- MetadataGenerator.class,
- FileMetadata.class,
- FileIndexer.class,
- ProjectFileIndexer.class,
- ProjectExclusionFilters.class,
-
- // rules
- new ActiveRulesProvider(),
- new QualityProfilesProvider(),
- CheckFactory.class,
- QProfileVerifier.class,
-
- // issues
- DefaultNoSonarFilter.class,
- IssueFilters.class,
- IssuePublisher.class,
-
- // metrics
- DefaultMetricFinder.class,
-
- // issue exclusions
- IssueInclusionPatternInitializer.class,
- IssueExclusionPatternInitializer.class,
- IssueExclusionsLoader.class,
- EnforceIssuesFilter.class,
- IgnoreIssuesFilter.class,
-
- // context
- ContextPropertiesCache.class,
-
- SensorStrategy.class,
-
- MutableProjectSettings.class,
- SonarGlobalPropertiesFilter.class,
- ProjectConfigurationProvider.class,
-
- ProjectCoverageAndDuplicationExclusions.class,
-
- // Plugin cache
- AnalysisCacheProvider.class,
- AnalysisCacheMemoryStorage.class,
- DefaultAnalysisCacheLoader.class,
-
- // Report
- ReferenceBranchSupplier.class,
- ScannerMetrics.class,
- JavaArchitectureInformationProvider.class,
- ReportPublisher.class,
- ScannerFileStructureProvider.class,
- AnalysisContextReportPublisher.class,
- MetadataPublisher.class,
- ActiveRulesPublisher.class,
- ComponentsPublisher.class,
- AnalysisCachePublisher.class,
- TestExecutionPublisher.class,
- SourcePublisher.class,
- ChangedLinesPublisher.class,
- AnalysisWarningsPublisher.class,
-
- CeTaskReportDataHolder.class,
-
- // Cpd
- CpdExecutor.class,
- CpdSettings.class,
- SonarCpdBlockIndex.class,
-
- // SCM
- ScmConfiguration.class,
- ScmPublisher.class,
- ScmRevisionImpl.class,
-
- // Sensors
- DefaultSensorStorage.class,
- DefaultFileLinesContextFactory.class,
- ProjectSensorContext.class,
- ProjectSensorOptimizer.class,
- ExecutingSensorContext.class,
-
- UnchangedFilesHandler.class,
-
- // Filesystem
- DefaultProjectFileSystem.class,
-
- // CI
- new CiConfigurationProvider(),
- AppVeyor.class,
- AwsCodeBuild.class,
- AzureDevops.class,
- Bamboo.class,
- BitbucketPipelines.class,
- Bitrise.class,
- Buildkite.class,
- CircleCi.class,
- CirrusCi.class,
- DroneCi.class,
- GithubActions.class,
- CodeMagic.class,
- GitlabCi.class,
- Jenkins.class,
- SemaphoreCi.class,
- TravisCi.class
- );
-
- add(GitScmSupport.getObjects());
- add(SvnScmSupport.getObjects());
-
- add(DefaultProjectSettingsLoader.class,
- DefaultActiveRulesLoader.class,
- DefaultQualityProfileLoader.class,
- DefaultProjectRepositoriesLoader.class);
-
- addIfMissing(DefaultLanguagesRepository.class, LanguagesRepository.class);
-
- }
-
- static ExtensionMatcher getScannerProjectExtensionsFilter() {
- return extension -> {
- if (isDeprecatedScannerSide(extension)) {
- return isInstantiationStrategy(extension, PER_BATCH);
- }
- return isScannerSide(extension);
- };
- }
-
- @Override
- protected void doAfterStart() {
- ScanProperties properties = getComponentByType(ScanProperties.class);
- properties.validate();
-
- properties.get("sonar.branch").ifPresent(deprecatedBranch -> {
- throw MessageException.of("The 'sonar.branch' parameter is no longer supported. You should stop using it. " +
- "Branch analysis is available in Developer Edition and above. See https://www.sonarsource.com/plans-and-pricing/developer/ for more information.");
- });
-
- BranchConfiguration branchConfig = getComponentByType(BranchConfiguration.class);
- if (branchConfig.branchType() == BranchType.PULL_REQUEST) {
- LOG.info("Pull request {} for merge into {} from {}", branchConfig.pullRequestKey(), pullRequestBaseToDisplayName(branchConfig.targetBranchName()),
- branchConfig.branchName());
- } else if (branchConfig.branchName() != null) {
- LOG.info("Branch name: {}", branchConfig.branchName());
- }
-
- getComponentByType(DeprecatedPropertiesWarningGenerator.class).execute();
-
- getComponentByType(ProjectFileIndexer.class).index();
- new SpringProjectScanContainer(this).execute();
- }
-
- private static String pullRequestBaseToDisplayName(@Nullable String pullRequestBase) {
- return pullRequestBase != null ? pullRequestBase : "default branch";
- }
-
-}