diff options
author | Lukasz Jarocki <lukasz.jarocki@sonarsource.com> | 2022-10-13 16:23:01 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-10-14 20:03:03 +0000 |
commit | cf8ab09b8d5fe9e72be77ef610d911b40f177214 (patch) | |
tree | 63b1383d356d44f13aab3f2fce69d3a51e38be66 /sonar-scanner-engine/src/main/java | |
parent | fdb78927f43c324750c185f105ade4d151fa9193 (diff) | |
download | sonarqube-cf8ab09b8d5fe9e72be77ef610d911b40f177214.tar.gz sonarqube-cf8ab09b8d5fe9e72be77ef610d911b40f177214.zip |
SONAR-16633 splitting plugins into two categories in the scanner context
Diffstat (limited to 'sonar-scanner-engine/src/main/java')
5 files changed, 33 insertions, 7 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPlugin.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPlugin.java index 9de35691fb6..bc9696365e9 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPlugin.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPlugin.java @@ -20,6 +20,7 @@ package org.sonar.scanner.bootstrap; import org.sonar.core.platform.PluginInfo; +import org.sonar.core.plugin.PluginType; import org.sonar.updatecenter.common.Version; public class ScannerPlugin { @@ -27,10 +28,12 @@ public class ScannerPlugin { private final String key; private final long updatedAt; private final PluginInfo info; + private final PluginType type; - public ScannerPlugin(String key, long updatedAt, PluginInfo info) { + public ScannerPlugin(String key, long updatedAt, PluginType type, PluginInfo info) { this.key = key; this.updatedAt = updatedAt; + this.type = type; this.info = info; } @@ -54,4 +57,7 @@ public class ScannerPlugin { return updatedAt; } + public PluginType getType() { + return type; + } } 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 83821718d88..bdad9644779 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 @@ -32,6 +32,7 @@ import org.sonar.api.utils.log.Logger; 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.sonarqube.ws.client.GetRequest; import static java.lang.String.format; @@ -75,12 +76,12 @@ public class ScannerPluginInstaller implements PluginInstaller { private Loaded loadPlugins(Map<String, ScannerPlugin> result) { for (InstalledPlugin plugin : listInstalledPlugins()) { Optional<File> jarFile = pluginFiles.get(plugin); - if (!jarFile.isPresent()) { + if (jarFile.isEmpty()) { return new Loaded(false, plugin.key); } PluginInfo info = PluginInfo.create(jarFile.get()); - result.put(info.getKey(), new ScannerPlugin(plugin.key, plugin.updatedAt, info)); + result.put(info.getKey(), new ScannerPlugin(plugin.key, plugin.updatedAt, PluginType.valueOf(plugin.type), info)); } return new Loaded(true, null); } @@ -122,6 +123,7 @@ public class ScannerPluginInstaller implements PluginInstaller { String key; String hash; long updatedAt; + String type; public InstalledPlugin() { // http://stackoverflow.com/a/18645370/229031 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 fcf68cc3a04..a123741bbb0 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 @@ -33,6 +33,7 @@ import org.sonar.core.platform.PluginClassLoader; 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 static java.util.stream.Collectors.toList; import static org.sonar.api.utils.Preconditions.checkState; @@ -68,7 +69,7 @@ public class ScannerPluginRepository implements PluginRepository, Startable { 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], pluginInfo)); + pluginsByKeys.put(pluginKey, new ScannerPlugin(pluginInfo.getKey(), (long) localPlugin[2], PluginType.BUNDLED, pluginInfo)); pluginInstancesByKeys.put(pluginKey, (Plugin) localPlugin[1]); } @@ -115,6 +116,14 @@ public class ScannerPluginRepository implements PluginRepository, Startable { return pluginsByKeys.values().stream().map(ScannerPlugin::getInfo).collect(toList()); } + public Collection<PluginInfo> getExternalPluginsInfos() { + return pluginsByKeys.values().stream().filter(p -> p.getType() == PluginType.EXTERNAL).map(ScannerPlugin::getInfo).collect(toList()); + } + + public Collection<PluginInfo> getBundledPluginsInfos() { + return pluginsByKeys.values().stream().filter(p -> p.getType() == PluginType.BUNDLED).map(ScannerPlugin::getInfo).collect(toList()); + } + @Override public PluginInfo getPluginInfo(String key) { ScannerPlugin info = pluginsByKeys.get(key); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakePluginInstaller.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakePluginInstaller.java index 5800b912a7b..fcdd2af7be6 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakePluginInstaller.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakePluginInstaller.java @@ -27,6 +27,7 @@ import java.util.Map; import javax.annotation.Priority; import org.sonar.api.Plugin; import org.sonar.core.platform.PluginInfo; +import org.sonar.core.plugin.PluginType; import org.sonar.scanner.bootstrap.PluginInstaller; import org.sonar.scanner.bootstrap.ScannerPlugin; @@ -37,7 +38,7 @@ public class FakePluginInstaller implements PluginInstaller { private final List<Object[]> mediumTestPlugins = new ArrayList<>(); public FakePluginInstaller add(String pluginKey, File jarFile, long lastUpdatedAt) { - pluginsByKeys.put(pluginKey, new ScannerPlugin(pluginKey, lastUpdatedAt, PluginInfo.create(jarFile))); + pluginsByKeys.put(pluginKey, new ScannerPlugin(pluginKey, lastUpdatedAt, PluginType.BUNDLED, PluginInfo.create(jarFile))); return this; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java index ce0c1b5a166..31eabd7a9fb 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java @@ -71,6 +71,7 @@ public class AnalysisContextReportPublisher { File analysisLog = writer.getFileStructure().analysisLog(); try (BufferedWriter fileWriter = Files.newBufferedWriter(analysisLog.toPath(), StandardCharsets.UTF_8)) { writePlugins(fileWriter); + writeBundledAnalyzers(fileWriter); writeGlobalSettings(fileWriter); writeProjectSettings(fileWriter); writeModulesSettings(fileWriter); @@ -80,8 +81,15 @@ public class AnalysisContextReportPublisher { } private void writePlugins(BufferedWriter fileWriter) throws IOException { - fileWriter.write("SonarQube plugins:\n"); - for (PluginInfo p : pluginRepo.getPluginInfos()) { + fileWriter.write("Plugins:\n"); + for (PluginInfo p : pluginRepo.getExternalPluginsInfos()) { + fileWriter.append(String.format(" - %s %s (%s)", p.getName(), p.getVersion(), p.getKey())).append('\n'); + } + } + + private void writeBundledAnalyzers(BufferedWriter fileWriter) throws IOException { + fileWriter.write("Bundled analyzers:\n"); + for (PluginInfo p : pluginRepo.getBundledPluginsInfos()) { fileWriter.append(String.format(" - %s %s (%s)", p.getName(), p.getVersion(), p.getKey())).append('\n'); } } |