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;
*/
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";
@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);
}
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;
@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);
}
@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"));
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