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-15 14:31:39 +0100
committersonartech <sonartech@sonarsource.com>2023-12-21 20:02:33 +0000
commit4d04d1b26abaf409d0c68b97f0cac05e251ff16d (patch)
treef833caff22fb99819fe5900decdfb8b0666b9799 /sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap
parent32e97e99a805f50e099b16ac55a65703d284979b (diff)
downloadsonarqube-4d04d1b26abaf409d0c68b97f0cac05e251ff16d.tar.gz
sonarqube-4d04d1b26abaf409d0c68b97f0cac05e251ff16d.zip
SONAR-21195 Refactor file indexing into two distinct steps
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/PluginInstaller.java11
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java11
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java20
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringScannerContainer.java12
4 files changed, 41 insertions, 13 deletions
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..de69726669c 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
@@ -22,6 +22,7 @@ package org.sonar.scanner.bootstrap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.sonar.scanner.mediumtest.LocalPlugin;
public interface PluginInstaller {
@@ -45,8 +46,14 @@ public interface PluginInstaller {
Map<String, ScannerPlugin> installPluginsForLanguages(Set<String> languageKeys);
/**
- * Used only by medium tests.
+ * Used only by medium tests. Installs required plugins (phase 1)
* @see org.sonar.scanner.mediumtest.ScannerMediumTester
*/
- List<Object[]> installLocals();
+ List<LocalPlugin> installLocals();
+
+ /**
+ * Used only by medium tests. Installs optional plugins (phase 2)
+ * @see org.sonar.scanner.mediumtest.ScannerMediumTester
+ */
+ List<LocalPlugin> installOptionalLocals(Set<String> languageKeys);
}
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..e05b7d08471 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
@@ -36,6 +36,7 @@ import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.plugin.PluginType;
+import org.sonar.scanner.mediumtest.LocalPlugin;
import org.sonarqube.ws.client.GetRequest;
import static java.lang.String.format;
@@ -137,7 +138,15 @@ public class ScannerPluginInstaller implements PluginInstaller {
* Returns empty on purpose. This method is used only by medium tests.
*/
@Override
- public List<Object[]> installLocals() {
+ public List<LocalPlugin> installLocals() {
+ return Collections.emptyList();
+ }
+
+ /**
+ * Returns empty on purpose. This method is used only by medium tests.
+ */
+ @Override
+ public List<LocalPlugin> installOptionalLocals(Set<String> languageKeys) {
return Collections.emptyList();
}
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..074079f974e 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
@@ -36,6 +36,7 @@ import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginJarExploder;
import org.sonar.core.platform.PluginRepository;
import org.sonar.core.plugin.PluginType;
+import org.sonar.scanner.mediumtest.LocalPlugin;
import static java.util.stream.Collectors.toMap;
import static org.sonar.api.utils.Preconditions.checkState;
@@ -79,11 +80,11 @@ public class ScannerPluginRepository implements PluginRepository, Startable {
pluginInstancesByKeys = new HashMap<>(loader.load(explodedPluginsByKey));
// this part is only used by medium tests
- for (Object[] localPlugin : installer.installLocals()) {
- String pluginKey = (String) localPlugin[0];
- PluginInfo pluginInfo = new PluginInfo(pluginKey);
- pluginsByKeys.put(pluginKey, new ScannerPlugin(pluginInfo.getKey(), (long) localPlugin[2], PluginType.BUNDLED, pluginInfo));
- pluginInstancesByKeys.put(pluginKey, (Plugin) localPlugin[1]);
+ for (LocalPlugin localPlugin : installer.installLocals()) {
+ ScannerPlugin scannerPlugin = localPlugin.toScannerPlugin();
+ String pluginKey = localPlugin.pluginKey();
+ pluginsByKeys.put(pluginKey, scannerPlugin);
+ pluginInstancesByKeys.put(pluginKey, localPlugin.pluginInstance());
}
keysByClassLoader = new HashMap<>();
@@ -107,6 +108,15 @@ public class ScannerPluginRepository implements PluginRepository, Startable {
.collect(toMap(Map.Entry::getKey, e -> pluginJarExploder.explode(e.getValue().getInfo())));
pluginInstancesByKeys.putAll(new HashMap<>(loader.load(explodedPluginsByKey)));
+ // this part is only used by medium tests
+ for (LocalPlugin localPlugin : installer.installOptionalLocals(languageKeys)) {
+ ScannerPlugin scannerPlugin = localPlugin.toScannerPlugin();
+ String pluginKey = localPlugin.pluginKey();
+ languagePluginsByKeys.put(pluginKey, scannerPlugin);
+ pluginsByKeys.put(pluginKey, scannerPlugin);
+ pluginInstancesByKeys.put(pluginKey, localPlugin.pluginInstance());
+ }
+
keysByClassLoader = new HashMap<>();
for (Map.Entry<String, Plugin> e : pluginInstancesByKeys.entrySet()) {
keysByClassLoader.put(e.getValue().getClass().getClassLoader(), e.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
index eedc07f9924..38972c95071 100644
--- 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
@@ -112,13 +112,14 @@ 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.FilePreprocessor;
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.ModuleRelativePathWarner;
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.ProjectFilePreprocessor;
import org.sonar.scanner.scan.filesystem.ScannerComponentIdGenerator;
import org.sonar.scanner.scan.filesystem.StatusDetection;
import org.sonar.scanner.scan.measure.DefaultMetricFinder;
@@ -193,8 +194,9 @@ public class SpringScannerContainer extends SpringComponentContainer {
LanguageDetection.class,
MetadataGenerator.class,
FileMetadata.class,
- FileIndexer.class,
- ProjectFileIndexer.class,
+ ModuleRelativePathWarner.class,
+ FilePreprocessor.class,
+ ProjectFilePreprocessor.class,
ProjectExclusionFilters.class,
// rules
@@ -335,7 +337,7 @@ public class SpringScannerContainer extends SpringComponentContainer {
getComponentByType(DeprecatedPropertiesWarningGenerator.class).execute();
- getComponentByType(ProjectFileIndexer.class).index();
+ getComponentByType(ProjectFilePreprocessor.class).execute();
new SpringProjectScanContainer(this).execute();
}