diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2023-12-15 14:31:39 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-01-04 20:02:48 +0000 |
commit | f8465c0d33ceb835c92f0b24e7842ba96c7604e0 (patch) | |
tree | e6b4bf5fec92c471e7510ee92b003fbc49dc24fa /sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap | |
parent | aec0c95e903db2ab7fdc3dfc6e90421e6342a277 (diff) | |
download | sonarqube-f8465c0d33ceb835c92f0b24e7842ba96c7604e0.tar.gz sonarqube-f8465c0d33ceb835c92f0b24e7842ba96c7604e0.zip |
SONAR-21195 Refactor file indexing into two distinct steps
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap')
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 0e117e75136..e4ae17968be 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 d2453c3b6ec..9bf367f630d 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 4d1894b59f8..6b875da7620 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 0cba8e33dfc..d7cecd16ed3 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 @@ -113,13 +113,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; @@ -194,8 +195,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 @@ -337,7 +339,7 @@ public class SpringScannerContainer extends SpringComponentContainer { getComponentByType(DeprecatedPropertiesWarningGenerator.class).execute(); - getComponentByType(ProjectFileIndexer.class).index(); + getComponentByType(ProjectFilePreprocessor.class).execute(); new SpringProjectScanContainer(this).execute(); } |