From fc7a31fb361cafdaaf1d2a1b98047bd7fafaec7e Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 24 Jan 2018 13:37:04 +0100 Subject: [PATCH] SONAR-10315 log the plugins loaded by compute engine --- .../java/org/sonar/ce/container/CePluginRepository.java | 5 ++++- .../org/sonar/ce/container/CePluginRepositoryTest.java | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/CePluginRepository.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/CePluginRepository.java index 968b030dc16..b537c7721ce 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/CePluginRepository.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/CePluginRepository.java @@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.io.FileUtils; import org.picocontainer.Startable; import org.sonar.api.Plugin; +import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginLoader; @@ -45,6 +46,7 @@ import static java.lang.String.format; */ public class CePluginRepository implements PluginRepository, Startable { + private static final Logger LOGGER = Loggers.get(CePluginRepository.class); private static final String[] JAR_FILE_EXTENSIONS = new String[] {"jar"}; private static final String NOT_STARTED_YET = "not started yet"; @@ -63,12 +65,13 @@ public class CePluginRepository implements PluginRepository, Startable { @Override public void start() { - Loggers.get(getClass()).info("Load plugins"); + LOGGER.info("Load plugins"); for (File file : listJarFiles(fs.getInstalledPluginsDir())) { PluginInfo info = PluginInfo.create(file); pluginInfosByKeys.put(info.getKey(), info); } pluginInstancesByKeys.putAll(loader.load(pluginInfosByKeys)); + pluginInfosByKeys.values().forEach(p -> LOGGER.info("Loaded plugin {} [{}]", p.getName(), p.getKey())); started.set(true); } diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/CePluginRepositoryTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/CePluginRepositoryTest.java index 9db4d275db8..5d53e9f8af7 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/CePluginRepositoryTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/CePluginRepositoryTest.java @@ -30,6 +30,8 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.mockito.Mockito; import org.sonar.api.Plugin; +import org.sonar.api.utils.log.LogTester; +import org.sonar.api.utils.log.LoggerLevel; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginLoader; import org.sonar.server.platform.ServerFileSystem; @@ -46,6 +48,9 @@ public class CePluginRepositoryTest { @Rule public ExpectedException expectedException = ExpectedException.none(); + @Rule + public LogTester logTester = new LogTester(); + private ServerFileSystem fs = mock(ServerFileSystem.class, Mockito.RETURNS_DEEP_STUBS); private PluginLoader pluginLoader = new DumbPluginLoader(); private CePluginRepository underTest = new CePluginRepository(fs, pluginLoader); @@ -67,7 +72,7 @@ public class CePluginRepositoryTest { } @Test - public void load_plugins() throws Exception { + public void load_plugins() { String pluginKey = "test"; when(fs.getInstalledPluginsDir()).thenReturn(new File("src/test/plugins/sonar-test-plugin/target")); @@ -77,6 +82,7 @@ public class CePluginRepositoryTest { assertThat(underTest.getPluginInfo(pluginKey).getKey()).isEqualTo(pluginKey); assertThat(underTest.getPluginInstance(pluginKey)).isNotNull(); assertThat(underTest.hasPlugin(pluginKey)).isTrue(); + assertThat(logTester.logs(LoggerLevel.INFO)).contains("Loaded plugin Test Plugin [test]"); } @Test -- 2.39.5