]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16633 splitting plugins into two categories in the scanner context
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Thu, 13 Oct 2022 14:23:01 +0000 (16:23 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 14 Oct 2022 20:03:03 +0000 (20:03 +0000)
39 files changed:
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/DetectPluginChange.java
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginConsentVerifier.java
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginType.java [deleted file]
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginUninstaller.java
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPlugin.java
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginInfo.java
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginManager.java
server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/DetectPluginChangeTest.java
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginConsentVerifierTest.java
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginUninstallerTest.java
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginInfoTest.java
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginManagerTest.java
server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/BundledSection.java
server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/PluginsSection.java
server/sonar-webserver-core/src/main/java/org/sonar/server/startup/RegisterPlugins.java
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BundledSectionTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/PluginsSectionTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/startup/GeneratePluginIndexTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/startup/RegisterPluginsTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/DownloadActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/plugins/ws/InstalledActionTest.java
sonar-core/src/main/java/org/sonar/core/plugin/PluginType.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPlugin.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginInstaller.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerPluginRepository.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/mediumtest/FakePluginInstaller.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/AnalysisContextReportPublisher.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisContextReportPublisherTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/blue-installed.json
sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/green-installed.json
sonar-scanner-engine/src/test/resources/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest/installed-plugins-ws.json
sonar-ws/src/main/protobuf/ws-plugins.proto

index 897bc6217efefdb4161f049bd5d24ed2c8d14fed..bd17e009809d31b784acdb4fdb8195485e848f43 100644 (file)
@@ -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;
index c50fb1209dfab125359a007d371e83684a7e6072..992a2415576963b17acd86bd669ec4d1e41afc26 100644 (file)
@@ -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;
index 19d1426508231daa11917066d1dfc8ec04a9b3cf..0b7b6a7c7d07a2d9fd5f47c5f22c6a9ccfed3670 100644 (file)
@@ -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/PluginType.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginType.java
deleted file mode 100644 (file)
index c3956cf..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 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.server.plugins;
-
-public enum PluginType {
-  EXTERNAL, BUNDLED
-}
index c33155e39adb064e6d915d843d8284a5bbbf0180..a4359d0f204f0877ff801f9ea2081546734c3e49 100644 (file)
@@ -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);
index e1a512c755378543e2c939249d789ba74014bf81..6d348d03094ca17e276800c3774eea50774d7c15 100644 (file)
@@ -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 {
index 35057d91d6942c2def19dc83339e29a6636f2136..8f452758a3e8f33b547892f0ba849d189c826455 100644 (file)
@@ -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 {
index 8e5ed0a01f1136f9201534046cc50417bb09ebb0..3b97129c13d35ec071fd09a556cc5ba3798b1631 100644 (file)
@@ -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
index 282d9cd45d02c52e7ebb74eb484aa3a5579ba1ea..698b3a69abf3d32fa805d5ef6ccd245b7df73906 100644 (file)
@@ -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;
index d1dc93a74b9bf1839563fff391dcc1e3665f58e0..825fea4c355ba633511b639bcfd67b2b00cf1d87 100644 (file)
@@ -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;
index cf99c57d99365aa9f8411db3a3ea5579b5b7a758..1a06bb19fb1883344b2bbee3eeee3bd188d6599a 100644 (file)
@@ -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
index e76cba50895c772c52f3001a2cd0e55f3fbfe605..5bf536717e1ed23dfa99f6da32d23a102dc29e8e 100644 (file)
@@ -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
index 9a52570fd5b07dd104e3fda1d0b6b79eb231dabe..cd5ae793ee0dbdf4eb9b899c4c37cd7287684809 100644 (file)
 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
index a219caadbca1a71d68943f6475cd6084abb1c0ce..1075795185ca5c27022b4111ba40ea88fbd8d2f1 100644 (file)
@@ -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 {
 
index bbc8b8b441332780c85e26435464ffee76a63c4e..f5250e05951ff22f4ad9811d43a6631a1ff632e2 100644 (file)
@@ -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();
index fc8876cb5a1cee76c87a2647ea4836be78410235..1270fc706cdc69d3bbb1ebada9a556d1e2fa10b6 100644 (file)
@@ -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;
 
index dfb6bd73e5b96da0afa6b8e508be7f74e64f4526..3a9d8c7e39babd4aa3877a89906a706f2f1794c2 100644 (file)
@@ -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;
 
index e709091550862c9e2fbff3e4a55362523e4cc3fe..dc82b842d47acc4aa18a700a3a69f7491ca476b3 100644 (file)
@@ -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;
 
index 6c5f09f08bb23f060dc5d72a49e0acbc83a8ef9d..1535aeb151b3e9c2e1355289b17c1d6ca747afde 100644 (file)
@@ -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;
 
index 2ecfbbf7d3253b65fef199b7dfd4ebe45c9ba811..b555bef73ec748f1932d947ffb6ed3d352b22e27 100644 (file)
@@ -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;
 
index 828b2b591ea9a53a387af3f4462ec99bc4af9cfd..3ee07bdac882391e98dfe9d340a4c59bec3db5c8 100644 (file)
@@ -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 {
 
index b402bb89250829e8d1c5d1609dc65bf6cddc16b3..138453f914b99476f7fd859d8e9ef78c06efa954 100644 (file)
@@ -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;
 
index 273c810167c808a72879c8f0806c1f8a1c4bfbcb..19306b34ea71cdce567899312dfc9222f013c13f 100644 (file)
@@ -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;
index 1a922aa83b8481e0d912ee08cdc637e2da6e9aa6..0eb217dabe3fc6cbfb5a6afcacd12af0a38f3804 100644 (file)
@@ -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()));
index 9acb6cae0c1a8e12d9a21deda14c72c3fb6ec8c8..188f8788016a96f9235eaa1f2164761789202abb 100644 (file)
@@ -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;
index f287b02a097828a35bd6c557d6135521872da68f..423fb7658cacab06aee08464d413bd989d91fd87 100644 (file)
@@ -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/sonar-core/src/main/java/org/sonar/core/plugin/PluginType.java b/sonar-core/src/main/java/org/sonar/core/plugin/PluginType.java
new file mode 100644 (file)
index 0000000..b93042b
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.core.plugin;
+
+public enum PluginType {
+  EXTERNAL, BUNDLED
+}
index 9de35691fb69804ec3fec72548f4273be9496848..bc9696365e931c8b5a67f00a53adb240e907ef61 100644 (file)
@@ -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;
+  }
 }
index 83821718d8835cf7a4d59f22458124c15defc47d..bdad964477933f3d7beec7fcaba5483c86f69022 100644 (file)
@@ -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
index fcf68cc3a04434b48e071b7804d79584be0b5112..a123741bbb0cdc34836574891c5fa408be6f91da 100644 (file)
@@ -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);
index 5800b912a7b4234f91ebde9b9b59ba0316e63bcb..fcdd2af7be6f7dd93d08067ca7bf31521f87d698 100644 (file)
@@ -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;
   }
 
index ce0c1b5a166e51481493319309fdb5f7cb10b4bd..31eabd7a9fbfe60827587bd82801029b057c2651 100644 (file)
@@ -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');
     }
   }
index bc6222af6a187c725b3cb3a1f6d356bd8ca5096f..29e3046f26e60b084b24d22d836df9cee44eba25 100644 (file)
@@ -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());
index 54561735cee99f27d00c39578296bf8806ec4ea5..a0d39fd35ddf0f7c6c5dd4c5ae1348ff4e881d69 100644 (file)
@@ -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)");
+  }
 }
index f10faf46a4bf46c6bd17e5a67577583461b0313a..fd677d2aaf9ca6393d33f0b2165d13739177ecb5 100644 (file)
@@ -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");
index c33470d53c5f349c818b1ad1f7c3d5e1dd7071e9..656149c3d19f1d21936e31f5a4b1e328e7b47210 100644 (file)
@@ -3,11 +3,13 @@
     {
       "key": "scmgit",
       "hash": "abc",
+      "type": "BUNDLED",
       "updatedAt": 100
     },
     {
       "key": "java",
       "hash": "def",
+      "type": "EXTERNAL",
       "updatedAt": 200
     }
   ]
index 1379b68eca32b16e4d8eeaec01af70328a1c0c24..caf8abc663f75752e4cf0d93de02d9ea1e439f03 100644 (file)
@@ -3,11 +3,13 @@
     {
       "key": "java",
       "hash": "def",
+      "type": "BUNDLED",
       "updatedAt": 200
     },
     {
       "key": "cobol",
       "hash": "ghi",
+      "type": "EXTERNAL",
       "updatedAt": 300
     }
   ]
index c33470d53c5f349c818b1ad1f7c3d5e1dd7071e9..656149c3d19f1d21936e31f5a4b1e328e7b47210 100644 (file)
@@ -3,11 +3,13 @@
     {
       "key": "scmgit",
       "hash": "abc",
+      "type": "BUNDLED",
       "updatedAt": 100
     },
     {
       "key": "java",
       "hash": "def",
+      "type": "EXTERNAL",
       "updatedAt": 200
     }
   ]
index 3748ca5b3f145e2d95e00251ea4c1a3e78d0e1d7..41f7c89ddd82725f7d94c78b5745aaaa5ba545d0 100644 (file)
@@ -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