diff options
author | Lukasz Jarocki <lukasz.jarocki@sonarsource.com> | 2021-03-03 16:55:59 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-03-08 20:07:54 +0000 |
commit | 45b11acbe0116d6781f0d4d5a4e035837e2ba54a (patch) | |
tree | bed8bb785e90f9caad0f0ccfb37773dd214291bb /server/sonar-webserver-core | |
parent | 129ca5f3534a69799f5ea95975c3f0a49fbb2804 (diff) | |
download | sonarqube-45b11acbe0116d6781f0d4d5a4e035837e2ba54a.tar.gz sonarqube-45b11acbe0116d6781f0d4d5a4e035837e2ba54a.zip |
SONAR-14523 implemented splitting plugins into two
Diffstat (limited to 'server/sonar-webserver-core')
7 files changed, 142 insertions, 12 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java index 7708b7c858e..95f556a3c34 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/AbstractSystemInfoWriter.java @@ -30,7 +30,7 @@ import org.sonar.server.telemetry.TelemetryDataLoader; public abstract class AbstractSystemInfoWriter implements SystemInfoWriter { private static final String[] ORDERED_SECTION_NAMES = { // standalone - "System", "Database", "Plugins", + "System", "Database", "Bundled", "Plugins", // cluster "Web JVM State", "Web Database Connection", "Web Logging", "Web JVM Properties", diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java index ee41ff6c490..d41750a8fa2 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java @@ -23,6 +23,7 @@ import org.sonar.core.platform.Module; import org.sonar.process.systeminfo.JvmPropertiesSection; import org.sonar.process.systeminfo.JvmStateSection; import org.sonar.server.platform.monitoring.AlmConfigurationSection; +import org.sonar.server.platform.monitoring.BundledSection; import org.sonar.server.platform.monitoring.DbConnectionSection; import org.sonar.server.platform.monitoring.DbSection; import org.sonar.server.platform.monitoring.EsIndexesSection; @@ -60,7 +61,8 @@ public class SystemInfoWriterModule extends Module { LoggingSection.class, PluginsSection.class, SettingsSection.class, - AlmConfigurationSection.class + AlmConfigurationSection.class, + BundledSection.class ); if (standalone) { 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 new file mode 100644 index 00000000000..d0404cfcec0 --- /dev/null +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/BundledSection.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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.platform.monitoring; + +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.server.plugins.ServerPluginRepository; +import org.sonar.updatecenter.common.Version; + +import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute; + +@ServerSide +public class BundledSection implements SystemInfoSection { + private final ServerPluginRepository repository; + + public BundledSection(ServerPluginRepository repository) { + this.repository = repository; + } + + @Override + public ProtobufSystemInfo.Section toProtobuf() { + ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); + protobuf.setName("Bundled"); + + for (PluginInfo plugin : repository.getPluginsInfoByType(PluginType.BUNDLED)) { + String label = ""; + Version version = plugin.getVersion(); + if (version != null) { + label = version.getName() + " "; + } + label += String.format("[%s]", plugin.getName()); + + setAttribute(protobuf, plugin.getKey(), label); + } + return protobuf.build(); + } +} 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 45b1ee14f96..95efad64ed4 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 @@ -21,18 +21,19 @@ package org.sonar.server.platform.monitoring; import org.sonar.api.server.ServerSide; import org.sonar.core.platform.PluginInfo; -import org.sonar.core.platform.PluginRepository; import org.sonar.process.systeminfo.SystemInfoSection; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; +import org.sonar.server.plugins.PluginType; +import org.sonar.server.plugins.ServerPluginRepository; import org.sonar.updatecenter.common.Version; import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute; @ServerSide public class PluginsSection implements SystemInfoSection { - private final PluginRepository repository; + private final ServerPluginRepository repository; - public PluginsSection(PluginRepository repository) { + public PluginsSection(ServerPluginRepository repository) { this.repository = repository; } @@ -40,12 +41,15 @@ public class PluginsSection implements SystemInfoSection { public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Plugins"); - for (PluginInfo plugin : repository.getPluginInfos()) { - String label = "[" + plugin.getName() + "]"; + + for (PluginInfo plugin : repository.getPluginsInfoByType(PluginType.EXTERNAL)) { + String label = ""; Version version = plugin.getVersion(); if (version != null) { - label = version.getName() + " " + label; + label = version.getName() + " "; } + label += String.format("[%s]", plugin.getName()); + setAttribute(protobuf, plugin.getKey(), label); } return protobuf.build(); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java index 4c190bebb06..77f359e78ba 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java @@ -42,7 +42,7 @@ public class SystemInfoWriterModuleTest { Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters(); assertThat(adapters) - .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 18); + .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 19); } @Test @@ -54,7 +54,7 @@ public class SystemInfoWriterModuleTest { Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters(); assertThat(adapters) - .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 12); + .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 13); } } 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 new file mode 100644 index 00000000000..3d7926a9695 --- /dev/null +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BundledSectionTest.java @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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.platform.monitoring; + +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.server.plugins.ServerPluginRepository; +import org.sonar.updatecenter.common.Version; + +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.platform.monitoring.SystemInfoTesting.assertThatAttributeIs; +import java.util.Arrays; + +public class BundledSectionTest { + + private ServerPluginRepository repo = mock(ServerPluginRepository.class); + private BundledSection underTest = new BundledSection(repo); + + @Test + public void name() { + assertThat(underTest.toProtobuf().getName()).isEqualTo("Bundled"); + } + + @Test + public void toProtobuf_given3BundledPlugins_returnThree() { + when(repo.getPluginsInfoByType(PluginType.BUNDLED)).thenReturn(Arrays.asList( + new PluginInfo("java") + .setName("Java") + .setVersion(Version.create("20.0")), + new PluginInfo("c++") + .setName("C++") + .setVersion(Version.create("1.0.2")), + new PluginInfo("no-version") + .setName("No Version"))); + + ProtobufSystemInfo.Section section = underTest.toProtobuf(); + + assertThatAttributeIs(section, "java", "20.0 [Java]"); + assertThatAttributeIs(section, "c++", "1.0.2 [C++]"); + assertThatAttributeIs(section, "no-version", "[No 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 e53cd71e9f3..8fbf32462d8 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 @@ -24,16 +24,19 @@ import org.junit.Test; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginRepository; import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo; +import org.sonar.server.plugins.PluginType; +import org.sonar.server.plugins.ServerPluginRepository; import org.sonar.updatecenter.common.Version; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs; public class PluginsSectionTest { - private PluginRepository repo = mock(PluginRepository.class); + private ServerPluginRepository repo = mock(ServerPluginRepository.class); private PluginsSection underTest = new PluginsSection(repo); @Test @@ -43,7 +46,7 @@ public class PluginsSectionTest { @Test public void plugin_name_and_version() { - when(repo.getPluginInfos()).thenReturn(Arrays.asList( + when(repo.getPluginsInfoByType(PluginType.EXTERNAL)).thenReturn(Arrays.asList( new PluginInfo("key-1") .setName("Plugin 1") .setVersion(Version.create("1.1")), |