Search in sources :

Example 1 with GoPluginBundleDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.

the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldUseOldClassLoaderBehaviourWhenSystemPropertyIsSet.

@Test
void shouldUseOldClassLoaderBehaviourWhenSystemPropertyIsSet() {
    systemEnvironment.setProperty("gocd.plugins.classloader.old", "true");
    final GoPluginDescriptor goPluginDescriptor = getPluginDescriptor("plugin.to.test.classloader", pluginToTestClassloadPluginBundleDir);
    final GoPluginBundleDescriptor descriptor = new GoPluginBundleDescriptor(goPluginDescriptor);
    registry.loadPlugin(descriptor);
    Bundle bundle = pluginOSGiFramework.loadPlugin(descriptor);
    assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
    ActionWithReturn<GoPlugin, Object> action = (plugin, pluginDescriptor) -> {
        assertThat(pluginDescriptor).isEqualTo(goPluginDescriptor);
        assertThat(Thread.currentThread().getContextClassLoader().getClass().getCanonicalName()).isNotEqualTo(BundleClassLoader.class.getCanonicalName());
        return null;
    };
    pluginOSGiFramework.doOn(GoPlugin.class, "plugin.to.test.classloader", "notification", action);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ZipInputStream(java.util.zip.ZipInputStream) Constants(org.osgi.framework.Constants) ZipUtil(com.thoughtworks.go.util.ZipUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) FileHelper(com.thoughtworks.go.plugin.FileHelper) FelixConstants(org.apache.felix.framework.util.FelixConstants) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) BundleClassLoader(org.apache.felix.framework.BundleWiringImpl.BundleClassLoader) ReflectionUtil(com.thoughtworks.go.util.ReflectionUtil) Bundle(org.osgi.framework.Bundle) ServiceReference(org.osgi.framework.ServiceReference) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) BundleContext(org.osgi.framework.BundleContext) File(java.io.File) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) DefaultPluginRegistry(com.thoughtworks.go.plugin.infra.plugininfo.DefaultPluginRegistry) Assertions.fail(org.assertj.core.api.Assertions.fail) TempDir(org.junit.jupiter.api.io.TempDir) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) Bundle(org.osgi.framework.Bundle) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with GoPluginBundleDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.

the class PluginLoaderTest method shouldCallUnloadListenersForEveryPluginInBundle.

@Test
void shouldCallUnloadListenersForEveryPluginInBundle() {
    final GoPluginDescriptor pluginDescriptor1 = GoPluginDescriptor.builder().id("plugin.1").build();
    final GoPluginDescriptor pluginDescriptor2 = GoPluginDescriptor.builder().id("plugin.2").build();
    GoPluginBundleDescriptor pluginBundleDescriptor = new GoPluginBundleDescriptor(pluginDescriptor1, pluginDescriptor2);
    pluginBundleDescriptor.setBundle(mock(Bundle.class));
    PluginChangeListener pluginChangeListener = mock(PluginChangeListener.class, "Listener Which Works: 1");
    pluginLoader.addPluginChangeListener(pluginChangeListener);
    pluginLoader.unloadPlugin(pluginBundleDescriptor);
    verify(pluginChangeListener, times(1)).pluginUnLoaded(pluginDescriptor1);
    verify(pluginChangeListener, times(1)).pluginUnLoaded(pluginDescriptor2);
    verify(pluginOSGiFramework, times(1)).unloadPlugin(pluginBundleDescriptor);
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) Bundle(org.osgi.framework.Bundle) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with GoPluginBundleDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.

the class PluginLoaderTest method shouldNotCallPostLoadHooksAndListenersIfBundleFailsToLoad.

@Test
void shouldNotCallPostLoadHooksAndListenersIfBundleFailsToLoad() {
    PluginChangeListener changeListener = mock(PluginChangeListener.class);
    PluginPostLoadHook postLoadHook = mock(PluginPostLoadHook.class);
    GoPluginDescriptor pluginDescriptor = GoPluginDescriptor.builder().id("plugin1").build();
    GoPluginBundleDescriptor goPluginBundleDescriptor = new GoPluginBundleDescriptor(pluginDescriptor);
    when(pluginOSGiFramework.loadPlugin(goPluginBundleDescriptor)).then(invocation -> {
        goPluginBundleDescriptor.markAsInvalid(singletonList("Ouch!"), null);
        goPluginBundleDescriptor.setBundle(mock(Bundle.class));
        return goPluginBundleDescriptor.bundle();
    });
    pluginLoader.addPluginChangeListener(changeListener);
    pluginLoader.addPluginPostLoadHook(postLoadHook);
    pluginLoader.loadPlugin(goPluginBundleDescriptor);
    verifyNoMoreInteractions(postLoadHook);
    verify(changeListener, times(0)).pluginLoaded(pluginDescriptor);
    verify(changeListener, times(1)).pluginUnLoaded(pluginDescriptor);
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) Bundle(org.osgi.framework.Bundle) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with GoPluginBundleDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.

the class PluginLoaderTest method shouldUnloadPluginIfBundleThrowsExceptionDuringLoad.

@Test
void shouldUnloadPluginIfBundleThrowsExceptionDuringLoad() {
    GoPluginDescriptor pluginDescriptor = GoPluginDescriptor.builder().id("plugin1").build();
    GoPluginBundleDescriptor pluginBundleDescriptor = new GoPluginBundleDescriptor(pluginDescriptor);
    when(pluginOSGiFramework.loadPlugin(pluginBundleDescriptor)).then(invocation -> {
        pluginBundleDescriptor.setBundle(mock(Bundle.class));
        throw new UnsupportedOperationException("Ouch!");
    });
    assertThatCode(() -> pluginLoader.loadPlugin(pluginBundleDescriptor)).isInstanceOf(RuntimeException.class).hasMessageContaining("Failed to load plugin");
    assertThat(pluginDescriptor.isInvalid()).isTrue();
    assertThat(pluginDescriptor.getStatus().getMessages()).isEqualTo(singletonList("Ouch!"));
    verify(pluginOSGiFramework, times(1)).unloadPlugin(pluginBundleDescriptor);
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) Bundle(org.osgi.framework.Bundle) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.jupiter.api.Test)

Example 5 with GoPluginBundleDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.

the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldPassInCorrectDescriptorToAction.

@Test
void shouldPassInCorrectDescriptorToAction() {
    final GoPluginDescriptor goPluginDescriptor = getPluginDescriptor(PLUGIN_ID, descriptorBundleDir);
    final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(goPluginDescriptor);
    registry.loadPlugin(bundleDescriptor);
    Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
    assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
    ActionWithReturn<GoPlugin, Object> action = (plugin, pluginDescriptor) -> {
        assertThat(pluginDescriptor).isEqualTo(goPluginDescriptor);
        plugin.pluginIdentifier();
        return null;
    };
    pluginOSGiFramework.doOn(GoPlugin.class, PLUGIN_ID, "notification", action);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ZipInputStream(java.util.zip.ZipInputStream) Constants(org.osgi.framework.Constants) ZipUtil(com.thoughtworks.go.util.ZipUtil) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) FileHelper(com.thoughtworks.go.plugin.FileHelper) FelixConstants(org.apache.felix.framework.util.FelixConstants) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) BundleClassLoader(org.apache.felix.framework.BundleWiringImpl.BundleClassLoader) ReflectionUtil(com.thoughtworks.go.util.ReflectionUtil) Bundle(org.osgi.framework.Bundle) ServiceReference(org.osgi.framework.ServiceReference) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) BundleContext(org.osgi.framework.BundleContext) File(java.io.File) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) DefaultPluginRegistry(com.thoughtworks.go.plugin.infra.plugininfo.DefaultPluginRegistry) Assertions.fail(org.assertj.core.api.Assertions.fail) TempDir(org.junit.jupiter.api.io.TempDir) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) Bundle(org.osgi.framework.Bundle) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

GoPluginBundleDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor)26 Test (org.junit.jupiter.api.Test)20 Bundle (org.osgi.framework.Bundle)13 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)11 GoPlugin (com.thoughtworks.go.plugin.api.GoPlugin)8 BundleContext (org.osgi.framework.BundleContext)8 ServiceReference (org.osgi.framework.ServiceReference)8 File (java.io.File)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 IOException (java.io.IOException)6 FileHelper (com.thoughtworks.go.plugin.FileHelper)5 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)5 DefaultPluginRegistry (com.thoughtworks.go.plugin.infra.plugininfo.DefaultPluginRegistry)4 ReflectionUtil (com.thoughtworks.go.util.ReflectionUtil)4 ZipUtil (com.thoughtworks.go.util.ZipUtil)4 HashMap (java.util.HashMap)4 ZipInputStream (java.util.zip.ZipInputStream)4 FileUtils (org.apache.commons.io.FileUtils)4 BundleClassLoader (org.apache.felix.framework.BundleWiringImpl.BundleClassLoader)4 FelixConstants (org.apache.felix.framework.util.FelixConstants)4