@@ -84,6 +84,14 @@ public class ServerPluginRepository implements PluginRepository { | |||
return Optional.ofNullable(pluginByKey.get(key)); | |||
} | |||
public Collection<PluginInfo> getPluginsInfoByType(PluginType type){ | |||
return pluginByKey.values() | |||
.stream() | |||
.filter(p -> p.getType() == type) | |||
.map(ServerPlugin::getPluginInfo) | |||
.collect(Collectors.toList()); | |||
} | |||
@Override | |||
public Plugin getPluginInstance(String key) { | |||
ServerPlugin plugin = pluginByKey.get(key); |
@@ -20,7 +20,10 @@ | |||
package org.sonar.server.plugins; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.stream.Collectors; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import org.sonar.api.Plugin; | |||
@@ -30,6 +33,7 @@ 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; | |||
public class ServerPluginRepositoryTest { | |||
@@ -37,8 +41,8 @@ public class ServerPluginRepositoryTest { | |||
@Test | |||
public void get_plugin_data() { | |||
ServerPlugin plugin1 = newPlugin("plugin1"); | |||
ServerPlugin plugin2 = newPlugin("plugin2"); | |||
ServerPlugin plugin1 = newPlugin("plugin1", EXTERNAL); | |||
ServerPlugin plugin2 = newPlugin("plugin2", EXTERNAL); | |||
repository.addPlugins(Collections.singletonList(plugin1)); | |||
repository.addPlugin(plugin2); | |||
@@ -56,8 +60,8 @@ public class ServerPluginRepositoryTest { | |||
@Test | |||
public void fail_getPluginInstance_if_plugin_doesnt_exist() { | |||
ServerPlugin plugin1 = newPlugin("plugin1"); | |||
ServerPlugin plugin2 = newPlugin("plugin2"); | |||
ServerPlugin plugin1 = newPlugin("plugin1", EXTERNAL); | |||
ServerPlugin plugin2 = newPlugin("plugin2", EXTERNAL); | |||
repository.addPlugins(Arrays.asList(plugin1, plugin2)); | |||
Assert.assertThrows("asd", IllegalArgumentException.class, () -> repository.getPluginInstance("plugin3")); | |||
@@ -65,20 +69,70 @@ public class ServerPluginRepositoryTest { | |||
@Test | |||
public void fail_getPluginInfo_if_plugin_doesnt_exist() { | |||
ServerPlugin plugin1 = newPlugin("plugin1"); | |||
ServerPlugin plugin2 = newPlugin("plugin2"); | |||
ServerPlugin plugin1 = newPlugin("plugin1", EXTERNAL); | |||
ServerPlugin plugin2 = newPlugin("plugin2", EXTERNAL); | |||
repository.addPlugins(Arrays.asList(plugin1, plugin2)); | |||
Assert.assertThrows("asd", IllegalArgumentException.class, () -> repository.getPluginInfo("plugin3")); | |||
} | |||
@Test | |||
public void getPluginsInfoByTypeExternal_given1ExternalPlugin_return1ExternalPlugin(){ | |||
//given | |||
ServerPlugin externalPlugin = newPlugin("plugin1", EXTERNAL); | |||
repository.addPlugin(externalPlugin); | |||
PluginInfo expectedPluginInfo = externalPlugin.getPluginInfo(); | |||
//when | |||
Collection<PluginInfo> pluginInfos = repository.getPluginsInfoByType(EXTERNAL); | |||
//then | |||
assertThat(pluginInfos).containsOnly(expectedPluginInfo); | |||
} | |||
@Test | |||
public void getPluginsInfoByTypeExternal_given1ExternalAnd1BundledPlugin_return1ExternalPlugin(){ | |||
//given | |||
ServerPlugin externalPlugin = newPlugin("plugin1", EXTERNAL); | |||
ServerPlugin bundledPlugin = newPlugin("plugin2", BUNDLED); | |||
repository.addPlugin(externalPlugin); | |||
repository.addPlugin(bundledPlugin); | |||
PluginInfo expectedPluginInfo = externalPlugin.getPluginInfo(); | |||
//when | |||
Collection<PluginInfo> pluginInfos = repository.getPluginsInfoByType(EXTERNAL); | |||
//then | |||
assertThat(pluginInfos).containsOnly(expectedPluginInfo); | |||
} | |||
@Test | |||
public void getPluginsInfoByTypeBundled_given2BundledPlugins_return2BundledPlugins(){ | |||
//given | |||
ServerPlugin bundledPlugin = newPlugin("plugin1", BUNDLED); | |||
ServerPlugin bundledPlugin2 = newPlugin("plugin2", BUNDLED); | |||
repository.addPlugin(bundledPlugin); | |||
repository.addPlugin(bundledPlugin2); | |||
PluginInfo expectedPluginInfo = bundledPlugin.getPluginInfo(); | |||
PluginInfo expectedPluginInfo2 = bundledPlugin2.getPluginInfo(); | |||
//when | |||
Collection<PluginInfo> pluginInfos = repository.getPluginsInfoByType(BUNDLED); | |||
//then | |||
assertThat(pluginInfos).containsOnly(expectedPluginInfo, expectedPluginInfo2); | |||
} | |||
private PluginInfo newPluginInfo(String key) { | |||
PluginInfo pluginInfo = mock(PluginInfo.class); | |||
when(pluginInfo.getKey()).thenReturn(key); | |||
return pluginInfo; | |||
} | |||
private ServerPlugin newPlugin(String key) { | |||
return new ServerPlugin(newPluginInfo(key), EXTERNAL, mock(Plugin.class), mock(FileAndMd5.class), mock(FileAndMd5.class), mock(ClassLoader.class)); | |||
private ServerPlugin newPlugin(String key, PluginType type) { | |||
return new ServerPlugin(newPluginInfo(key), type, mock(Plugin.class), mock(FileAndMd5.class), mock(FileAndMd5.class), mock(ClassLoader.class)); | |||
} | |||
} |
@@ -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", |
@@ -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) { |
@@ -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(); | |||
} | |||
} |
@@ -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(); |
@@ -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); | |||
} | |||
} |
@@ -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]"); | |||
} | |||
} |
@@ -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")), |