import org.sonar.api.config.PropertyDefinitions;
import javax.annotation.Nullable;
+
import java.util.Collection;
import java.util.List;
try {
pico.stop();
-
} catch (RuntimeException e) {
if (!swallowException) {
throw PicoUtils.propagate(e);
public ComponentContainer addExtension(@Nullable PluginMetadata plugin, Object extension) {
Object key = componentKeys.of(extension);
- pico.as(Characteristics.CACHE).addComponent(key, extension);
+ try {
+ pico.as(Characteristics.CACHE).addComponent(key, extension);
+ } catch (Throwable t) {
+ throw new IllegalStateException("Unable to register extension " + getName(extension), t);
+ }
declareExtension(plugin, extension);
return this;
}
+ private String getName(Object extension) {
+ if (extension instanceof Class) {
+ return ((Class) extension).getName();
+ }
+ return getName(extension.getClass());
+ }
+
public void declareExtension(@Nullable PluginMetadata plugin, Object extension) {
propertyDefinitions.addComponent(extension, plugin != null ? plugin.getName() : "");
}
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
public class ComponentContainerTest {
container.startComponents();
}
+ @Test
+ public void display_plugin_name_when_failing_to_add_extension() {
+ ComponentContainer container = new ComponentContainer();
+ PluginMetadata plugin = mock(PluginMetadata.class);
+
+ container.startComponents();
+
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("Unable to register extension org.sonar.api.platform.ComponentContainerTest$UnstartableComponent");
+
+ container.addExtension(plugin, UnstartableComponent.class);
+
+ }
+
@Test
public void test_start_failure() {
ComponentContainer container = new ComponentContainer();