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 | |
parent | fdb78927f43c324750c185f105ade4d151fa9193 (diff) | |
download | sonarqube-cf8ab09b8d5fe9e72be77ef610d911b40f177214.tar.gz sonarqube-cf8ab09b8d5fe9e72be77ef610d911b40f177214.zip |
SONAR-16633 splitting plugins into two categories in the scanner context
38 files changed, 113 insertions, 39 deletions
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/DetectPluginChange.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/DetectPluginChange.java index 897bc6217ef..bd17e009809 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/DetectPluginChange.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/DetectPluginChange.java @@ -26,6 +26,7 @@ import org.sonar.api.utils.Preconditions; 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.plugin.PluginType; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.plugin.PluginDto; diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginConsentVerifier.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginConsentVerifier.java index c50fb1209df..992a2415576 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginConsentVerifier.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginConsentVerifier.java @@ -25,6 +25,7 @@ import org.sonar.api.Startable; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.core.extension.PluginRiskConsent; +import org.sonar.core.plugin.PluginType; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.property.PropertyDto; diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java index 19d14265082..0b7b6a7c7d0 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java @@ -45,8 +45,8 @@ import static java.lang.String.format; import static org.apache.commons.io.FileUtils.moveFile; import static org.sonar.core.util.FileUtils.deleteQuietly; import static org.sonar.server.log.ServerProcessLogging.STARTUP_LOGGER_NAME; -import static org.sonar.server.plugins.PluginType.BUNDLED; -import static org.sonar.server.plugins.PluginType.EXTERNAL; +import static org.sonar.core.plugin.PluginType.BUNDLED; +import static org.sonar.core.plugin.PluginType.EXTERNAL; public class PluginJarLoader { private static final Logger LOG = Loggers.get(PluginJarLoader.class); diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginUninstaller.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginUninstaller.java index c33155e39ad..a4359d0f204 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginUninstaller.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginUninstaller.java @@ -36,7 +36,7 @@ import org.sonar.server.platform.ServerFileSystem; import static java.lang.String.format; import static org.apache.commons.io.FileUtils.forceMkdir; import static org.apache.commons.io.FileUtils.moveFileToDirectory; -import static org.sonar.server.plugins.PluginType.EXTERNAL; +import static org.sonar.core.plugin.PluginType.EXTERNAL; public class PluginUninstaller implements Startable { private static final Logger LOG = Loggers.get(PluginUninstaller.class); diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPlugin.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPlugin.java index e1a512c7553..6d348d03094 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPlugin.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPlugin.java @@ -23,6 +23,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.Plugin; import org.sonar.core.platform.PluginInfo; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5; public class ServerPlugin { diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginInfo.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginInfo.java index 35057d91d69..8f452758a3e 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginInfo.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginInfo.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.IOException; import java.util.Objects; import org.sonar.core.platform.PluginInfo; +import org.sonar.core.plugin.PluginType; import org.sonar.updatecenter.common.PluginManifest; public class ServerPluginInfo extends PluginInfo { diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginManager.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginManager.java index 8e5ed0a01f1..3b97129c13d 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginManager.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginManager.java @@ -31,6 +31,7 @@ import org.sonar.api.utils.log.Loggers; import org.sonar.core.platform.ExplodedPlugin; import org.sonar.core.platform.PluginClassLoader; import org.sonar.core.platform.PluginJarExploder; +import org.sonar.core.plugin.PluginType; /** * Entry point to install and load plugins on server startup. It manages diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java index 282d9cd45d0..698b3a69abf 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java @@ -31,6 +31,7 @@ import javax.annotation.CheckForNull; import org.sonar.api.Plugin; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginRepository; +import org.sonar.core.plugin.PluginType; import static com.google.common.base.Preconditions.checkArgument; import static java.lang.String.format; diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/DetectPluginChangeTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/DetectPluginChangeTest.java index d1dc93a74b9..825fea4c355 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/DetectPluginChangeTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/DetectPluginChangeTest.java @@ -23,6 +23,7 @@ import org.junit.Rule; import org.junit.Test; import org.sonar.api.Plugin; import org.sonar.core.platform.PluginInfo; +import org.sonar.core.plugin.PluginType; import org.sonar.db.DbTester; import org.sonar.db.plugin.PluginDto; import org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5; diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginConsentVerifierTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginConsentVerifierTest.java index cf99c57d993..1a06bb19fb1 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginConsentVerifierTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginConsentVerifierTest.java @@ -37,8 +37,8 @@ import static org.sonar.core.config.CorePropertyDefinitions.PLUGINS_RISK_CONSENT import static org.sonar.core.extension.PluginRiskConsent.ACCEPTED; import static org.sonar.core.extension.PluginRiskConsent.NOT_ACCEPTED; import static org.sonar.core.extension.PluginRiskConsent.REQUIRED; -import static org.sonar.server.plugins.PluginType.BUNDLED; -import static org.sonar.server.plugins.PluginType.EXTERNAL; +import static org.sonar.core.plugin.PluginType.BUNDLED; +import static org.sonar.core.plugin.PluginType.EXTERNAL; public class PluginConsentVerifierTest { @Rule diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginUninstallerTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginUninstallerTest.java index e76cba50895..5bf536717e1 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginUninstallerTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginUninstallerTest.java @@ -32,6 +32,7 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.Plugin; import org.sonar.api.utils.log.LogTester; import org.sonar.core.platform.PluginInfo; +import org.sonar.core.plugin.PluginType; import org.sonar.server.platform.ServerFileSystem; import org.sonar.updatecenter.common.Version; @@ -39,8 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.sonar.server.plugins.PluginType.BUNDLED; -import static org.sonar.server.plugins.PluginType.EXTERNAL; +import static org.sonar.core.plugin.PluginType.BUNDLED; +import static org.sonar.core.plugin.PluginType.EXTERNAL; public class PluginUninstallerTest { @Rule diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginInfoTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginInfoTest.java index 9a52570fd5b..cd5ae793ee0 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginInfoTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginInfoTest.java @@ -20,10 +20,11 @@ package org.sonar.server.plugins; import org.junit.Test; +import org.sonar.core.plugin.PluginType; import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.server.plugins.PluginType.BUNDLED; -import static org.sonar.server.plugins.PluginType.EXTERNAL; +import static org.sonar.core.plugin.PluginType.BUNDLED; +import static org.sonar.core.plugin.PluginType.EXTERNAL; public class ServerPluginInfoTest { @Test diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java index a219caadbca..1075795185c 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java @@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.tuple; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.sonar.server.plugins.PluginType.EXTERNAL; +import static org.sonar.core.plugin.PluginType.EXTERNAL; public class ServerPluginManagerTest { diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java index bbc8b8b4413..f5250e05951 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java @@ -27,13 +27,14 @@ import org.junit.Assert; import org.junit.Test; import org.sonar.api.Plugin; import org.sonar.core.platform.PluginInfo; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.sonar.server.plugins.PluginType.BUNDLED; -import static org.sonar.server.plugins.PluginType.EXTERNAL; +import static org.sonar.core.plugin.PluginType.BUNDLED; +import static org.sonar.core.plugin.PluginType.EXTERNAL; public class ServerPluginRepositoryTest { private ServerPluginRepository repository = new ServerPluginRepository(); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/BundledSection.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/BundledSection.java index fc8876cb5a1..1270fc706cd 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/BundledSection.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/BundledSection.java @@ -23,7 +23,7 @@ import org.sonar.api.server.ServerSide; import org.sonar.core.platform.PluginInfo; import org.sonar.process.systeminfo.SystemInfoSection; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; -import org.sonar.server.plugins.PluginType; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.ServerPluginRepository; import org.sonar.updatecenter.common.Version; diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/PluginsSection.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/PluginsSection.java index dfb6bd73e5b..3a9d8c7e39b 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/PluginsSection.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/PluginsSection.java @@ -23,7 +23,7 @@ import org.sonar.api.server.ServerSide; import org.sonar.core.platform.PluginInfo; import org.sonar.process.systeminfo.SystemInfoSection; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; -import org.sonar.server.plugins.PluginType; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.ServerPluginRepository; import org.sonar.updatecenter.common.Version; diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPlugins.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPlugins.java index e7090915508..dc82b842d47 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPlugins.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPlugins.java @@ -32,7 +32,7 @@ import org.sonar.core.util.UuidFactory; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.plugin.PluginDto; -import org.sonar.server.plugins.PluginType; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.ServerPlugin; import org.sonar.server.plugins.ServerPluginRepository; diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BundledSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BundledSectionTest.java index 6c5f09f08bb..1535aeb151b 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BundledSectionTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BundledSectionTest.java @@ -23,7 +23,7 @@ import java.util.Arrays; import org.junit.Test; import org.sonar.core.platform.PluginInfo; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; -import org.sonar.server.plugins.PluginType; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.ServerPluginRepository; import org.sonar.updatecenter.common.Version; diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/PluginsSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/PluginsSectionTest.java index 2ecfbbf7d32..b555bef73ec 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/PluginsSectionTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/PluginsSectionTest.java @@ -23,7 +23,7 @@ import java.util.Arrays; import org.junit.Test; import org.sonar.core.platform.PluginInfo; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; -import org.sonar.server.plugins.PluginType; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.ServerPluginRepository; import org.sonar.updatecenter.common.Version; diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/GeneratePluginIndexTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/GeneratePluginIndexTest.java index 828b2b591ea..3ee07bdac88 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/GeneratePluginIndexTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/GeneratePluginIndexTest.java @@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.sonar.server.plugins.PluginType.BUNDLED; +import static org.sonar.core.plugin.PluginType.BUNDLED; public class GeneratePluginIndexTest { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPluginsTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPluginsTest.java index b402bb89250..138453f914b 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPluginsTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPluginsTest.java @@ -37,7 +37,7 @@ import org.sonar.db.DbTester; import org.sonar.db.plugin.PluginDto; import org.sonar.db.plugin.PluginDto.Type; import org.sonar.server.plugins.PluginFilesAndMd5; -import org.sonar.server.plugins.PluginType; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.ServerPlugin; import org.sonar.server.plugins.ServerPluginRepository; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java index 273c810167c..19306b34ea7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java @@ -37,7 +37,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.plugin.PluginDto; import org.sonar.db.plugin.PluginDto.Type; -import org.sonar.server.plugins.PluginType; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.ServerPlugin; import org.sonar.server.plugins.ServerPluginRepository; import org.sonar.server.plugins.UpdateCenterMatrixFactory; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java index 1a922aa83b8..0eb217dabe3 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java @@ -81,6 +81,7 @@ public class PluginWSCommons { ofNullable(installedPlugin).ifPresent(serverPlugin -> { builder.setFilename(installedPlugin.getJar().getFile().getName()); builder.setHash(installedPlugin.getJar().getMd5()); + builder.setType(installedPlugin.getType().name()); }); ofNullable(pluginInfo.getVersion()).ifPresent(v -> builder.setVersion(isNotBlank(pluginInfo.getDisplayVersion()) ? pluginInfo.getDisplayVersion() : v.getName())); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/DownloadActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/DownloadActionTest.java index 9acb6cae0c1..188f8788016 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/DownloadActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/DownloadActionTest.java @@ -31,7 +31,7 @@ import org.sonar.api.server.ws.WebService; import org.sonar.core.platform.PluginInfo; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5; -import org.sonar.server.plugins.PluginType; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.ServerPlugin; import org.sonar.server.plugins.ServerPluginRepository; import org.sonar.server.ws.TestRequest; diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java index f287b02a097..423fb7658ca 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java @@ -42,7 +42,7 @@ import org.sonar.core.platform.PluginInfo; import org.sonar.db.DbTester; import org.sonar.db.plugin.PluginDto.Type; import org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5; -import org.sonar.server.plugins.PluginType; +import org.sonar.core.plugin.PluginType; import org.sonar.server.plugins.ServerPlugin; import org.sonar.server.plugins.ServerPluginRepository; import org.sonar.server.plugins.UpdateCenterMatrixFactory; diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginType.java b/sonar-core/src/main/java/org/sonar/core/plugin/PluginType.java index c3956cf9fd9..b93042b575e 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginType.java +++ b/sonar-core/src/main/java/org/sonar/core/plugin/PluginType.java @@ -17,7 +17,7 @@ * 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.server.plugins; +package org.sonar.core.plugin; public enum PluginType { EXTERNAL, BUNDLED 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'); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java index bc6222af6a1..29e3046f26e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java @@ -28,6 +28,7 @@ import org.sonar.core.platform.ExplodedPlugin; import org.sonar.core.platform.PluginClassLoader; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginJarExploder; +import org.sonar.core.plugin.PluginType; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -47,7 +48,7 @@ public class ScannerPluginRepositoryTest { @Test public void install_and_load_plugins() { PluginInfo info = new PluginInfo("java"); - ImmutableMap<String, ScannerPlugin> plugins = ImmutableMap.of("java", new ScannerPlugin("java", 1L, info)); + ImmutableMap<String, ScannerPlugin> plugins = ImmutableMap.of("java", new ScannerPlugin("java", 1L, PluginType.EXTERNAL, info)); Plugin instance = mock(Plugin.class); when(loader.load(anyMap())).thenReturn(ImmutableMap.of("java", instance)); when(installer.installRemotes()).thenReturn(plugins); @@ -59,6 +60,8 @@ public class ScannerPluginRepositoryTest { assertThat(underTest.getPluginInfo("java")).isSameAs(info); assertThat(underTest.getPluginInstance("java")).isSameAs(instance); assertThat(underTest.getPluginInstances()).containsOnly(instance); + assertThat(underTest.getBundledPluginsInfos()).isEmpty(); + assertThat(underTest.getExternalPluginsInfos()).isEqualTo(underTest.getPluginInfos()); underTest.stop(); verify(loader).unload(anyCollection()); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java index 54561735cee..a0d39fd35dd 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java @@ -21,6 +21,7 @@ package org.sonar.scanner.report; import com.google.common.collect.ImmutableMap; import java.io.File; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; @@ -53,8 +54,6 @@ import static org.mockito.Mockito.when; public class AnalysisContextReportPublisherTest { - private static final String BIZ = "BIZ"; - private static final String FOO = "FOO"; private static final String SONAR_SKIP = "sonar.skip"; private static final String COM_FOO = "com.foo"; @@ -64,7 +63,7 @@ public class AnalysisContextReportPublisherTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - private ScannerPluginRepository pluginRepo = mock(ScannerPluginRepository.class); + private final ScannerPluginRepository pluginRepo = mock(ScannerPluginRepository.class); private AnalysisContextReportPublisher publisher; private System2 system2; private GlobalServerSettings globalServerSettings; @@ -86,7 +85,7 @@ public class AnalysisContextReportPublisherTest { @Test public void shouldOnlyDumpPluginsByDefault() throws Exception { - when(pluginRepo.getPluginInfos()).thenReturn(singletonList(new PluginInfo("xoo").setName("Xoo").setVersion(Version.create("1.0")))); + when(pluginRepo.getExternalPluginsInfos()).thenReturn(singletonList(new PluginInfo("xoo").setName("Xoo").setVersion(Version.create("1.0")))); ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder()); DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create() @@ -138,7 +137,8 @@ public class AnalysisContextReportPublisherTest { List<String> lines = FileUtils.readLines(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8); assertThat(lines).containsExactly( - "SonarQube plugins:", + "Plugins:", + "Bundled analyzers:", "Global server settings:", "Project server settings:", " - com.foo=bar", @@ -238,7 +238,8 @@ public class AnalysisContextReportPublisherTest { List<String> lines = FileUtils.readLines(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8); assertThat(lines).containsExactly( - "SonarQube plugins:", + "Plugins:", + "Bundled analyzers:", "Global server settings:", "Project server settings:", "Project scanner properties:", @@ -248,4 +249,29 @@ public class AnalysisContextReportPublisherTest { " - sonar.projectKey=foo" ); } + + @Test + public void init_splitsPluginsByTypeInTheFile() throws IOException { + ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder()); + DefaultInputModule parent = new DefaultInputModule(ProjectDefinition.create() + .setBaseDir(temp.newFolder()) + .setWorkDir(temp.newFolder()) + .setProperty("sonar.projectKey", "parent") + .setProperty(SONAR_SKIP, "true")); + when(hierarchy.root()).thenReturn(parent); + + when(pluginRepo.getExternalPluginsInfos()).thenReturn(List.of(new PluginInfo("xoo").setName("Xoo").setVersion(Version.create("1.0")))); + when(pluginRepo.getBundledPluginsInfos()).thenReturn(List.of(new PluginInfo("java").setName("Java").setVersion(Version.create("9.7")))); + + publisher.init(writer); + + List<String> lines = FileUtils.readLines(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8); + + System.out.println(lines); + + assertThat(lines).contains("Plugins:", + " - Xoo 1.0 (xoo)", + "Bundled analyzers:", + " - Java 9.7 (java)"); + } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java index f10faf46a4b..fd677d2aaf9 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java @@ -41,6 +41,7 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.scm.ScmProvider; +import org.sonar.core.plugin.PluginType; import org.sonar.scanner.ProjectInfo; import org.sonar.scanner.bootstrap.ScannerPlugin; import org.sonar.scanner.bootstrap.ScannerPluginRepository; @@ -123,8 +124,8 @@ public class MetadataPublisherTest { Date date = new Date(); when(qProfiles.findAll()).thenReturn(Collections.singletonList(new QProfile("q1", "Q1", "java", date))); when(pluginRepository.getPluginsByKey()).thenReturn(ImmutableMap.of( - "java", new ScannerPlugin("java", 12345L, null), - "php", new ScannerPlugin("php", 45678L, null))); + "java", new ScannerPlugin("java", 12345L, PluginType.BUNDLED, null), + "php", new ScannerPlugin("php", 45678L, PluginType.BUNDLED, null))); File outputDir = temp.newFolder(); ScannerReportWriter writer = new ScannerReportWriter(outputDir); when(referenceBranchSupplier.getFromProperties()).thenReturn("newCodeReference"); diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/blue-installed.json b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/blue-installed.json index c33470d53c5..656149c3d19 100644 --- a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/blue-installed.json +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/blue-installed.json @@ -3,11 +3,13 @@ { "key": "scmgit", "hash": "abc", + "type": "BUNDLED", "updatedAt": 100 }, { "key": "java", "hash": "def", + "type": "EXTERNAL", "updatedAt": 200 } ] diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/green-installed.json b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/green-installed.json index 1379b68eca3..caf8abc663f 100644 --- a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/green-installed.json +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/green-installed.json @@ -3,11 +3,13 @@ { "key": "java", "hash": "def", + "type": "BUNDLED", "updatedAt": 200 }, { "key": "cobol", "hash": "ghi", + "type": "EXTERNAL", "updatedAt": 300 } ] diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/installed-plugins-ws.json b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/installed-plugins-ws.json index c33470d53c5..656149c3d19 100644 --- a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/installed-plugins-ws.json +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/installed-plugins-ws.json @@ -3,11 +3,13 @@ { "key": "scmgit", "hash": "abc", + "type": "BUNDLED", "updatedAt": 100 }, { "key": "java", "hash": "def", + "type": "EXTERNAL", "updatedAt": 200 } ] diff --git a/sonar-ws/src/main/protobuf/ws-plugins.proto b/sonar-ws/src/main/protobuf/ws-plugins.proto index 3748ca5b3f1..41f7c89ddd8 100644 --- a/sonar-ws/src/main/protobuf/ws-plugins.proto +++ b/sonar-ws/src/main/protobuf/ws-plugins.proto @@ -123,6 +123,7 @@ message PluginDetails { optional bool sonarLintSupported = 15; optional string documentationPath = 16; optional int64 updatedAt = 17; + optional string type = 18; } // WS api/plugins/pending |