Search in sources :

Example 11 with GoPluginBundleDescriptor

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

the class PluginsZipTest method setUp.

@BeforeEach
void setUp(@TempDir File rootDir) throws Exception {
    temporaryFolder = new FileHelper(rootDir);
    pluginManager = mock(PluginManager.class);
    temporaryFolder.newFolder();
    systemEnvironment = mock(SystemEnvironment.class);
    bundledPluginsDir = temporaryFolder.newFolder("plugins-bundled");
    expectedZipPath = temporaryFolder.newFile("go-plugins-all.zip").getAbsolutePath();
    externalPluginsDir = temporaryFolder.newFolder("plugins-external");
    when(systemEnvironment.get(PLUGIN_GO_PROVIDED_PATH)).thenReturn(bundledPluginsDir.getAbsolutePath());
    when(systemEnvironment.get(PLUGIN_EXTERNAL_PROVIDED_PATH)).thenReturn(externalPluginsDir.getAbsolutePath());
    when(systemEnvironment.get(ALL_PLUGINS_ZIP_PATH)).thenReturn(expectedZipPath);
    pluginsZip = spy(new PluginsZip(systemEnvironment, pluginManager));
    File bundledTask1Jar = createPluginFile(this.bundledPluginsDir, "bundled-task-1.jar", "Bundled1");
    File bundledAuth2Jar = createPluginFile(this.bundledPluginsDir, "bundled-auth-2.jar", "Bundled2");
    File bundledscm3Jar = createPluginFile(this.bundledPluginsDir, "bundled-scm-3.jar", "Bundled3");
    File bundledPackageMaterialJar = createPluginFile(this.bundledPluginsDir, "bundled-package-material-4.jar", "Bundled4");
    File externalTask1Jar = createPluginFile(externalPluginsDir, "external-task-1.jar", "External1");
    File externalElastic1Jar = createPluginFile(externalPluginsDir, "external-elastic-agent-2.jar", "External2");
    File externalscm3Jar = createPluginFile(externalPluginsDir, "external-scm-3.jar", "External3");
    File externalPackageMaterialJar = createPluginFile(externalPluginsDir, "external-package-material-4.jar", "External3");
    bundledTaskPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("bundled-task-1", bundledTask1Jar, true));
    GoPluginBundleDescriptor bundledAuthPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("bundled-auth-2", bundledAuth2Jar, true));
    GoPluginBundleDescriptor bundledSCMPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("bundled-scm-3", bundledscm3Jar, true));
    GoPluginBundleDescriptor bundledPackageMaterialPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("bundled-package-material-4", bundledPackageMaterialJar, true));
    externalTaskPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("external-task-1", externalTask1Jar, false));
    externalElasticAgentPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("external-elastic-agent-2", externalElastic1Jar, false));
    GoPluginBundleDescriptor externalSCMPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("external-scm-3", externalscm3Jar, false));
    GoPluginBundleDescriptor externalPackageMaterialPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("external-package-material-4", externalPackageMaterialJar, false));
    when(pluginManager.plugins()).thenReturn(List.of(bundledTaskPlugin.descriptors().get(0), bundledAuthPlugin.descriptors().get(0), bundledSCMPlugin.descriptors().get(0), bundledPackageMaterialPlugin.descriptors().get(0), externalTaskPlugin.descriptors().get(0), externalElasticAgentPlugin.descriptors().get(0), externalSCMPlugin.descriptors().get(0), externalPackageMaterialPlugin.descriptors().get(0)));
    when(pluginManager.isPluginOfType("task", "bundled-task-1")).thenReturn(true);
    when(pluginManager.isPluginOfType("task", "external-task-1")).thenReturn(true);
    when(pluginManager.isPluginOfType("package-repository", "bundled-package-material-4")).thenReturn(true);
    when(pluginManager.isPluginOfType("scm", "bundled-scm-3")).thenReturn(true);
    when(pluginManager.isPluginOfType("scm", "external-scm-3")).thenReturn(true);
    when(pluginManager.isPluginOfType("package-repository", "external-package-material-4")).thenReturn(true);
}
Also used : PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) FileHelper(com.thoughtworks.go.plugin.FileHelper) GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) File(java.io.File) ZipFile(java.util.zip.ZipFile) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with GoPluginBundleDescriptor

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

the class PluginInfoMother method getDescriptor.

public static GoPluginDescriptor getDescriptor(String pluginId, String name, String pluginJarLocation, boolean isBundledPlugin, String... targetOperatingSystems) {
    GoPluginDescriptor.About about = GoPluginDescriptor.About.builder().name(name).version("v1").targetGoVersion("goVersion1").description("go plugin").vendor(new GoPluginDescriptor.Vendor("go", "goUrl")).targetOperatingSystems(List.of(targetOperatingSystems)).build();
    GoPluginDescriptor descriptor = GoPluginDescriptor.builder().id(pluginId).version("1").about(about).pluginJarFileLocation(pluginJarLocation).isBundledPlugin(isBundledPlugin).build();
    descriptor.setBundleDescriptor(new GoPluginBundleDescriptor(descriptor));
    return descriptor;
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)

Example 13 with GoPluginBundleDescriptor

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

the class PluginLoaderTest method shouldUnloadPluginIfBundleFailsToLoad.

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

Example 14 with GoPluginBundleDescriptor

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

the class PluginLoaderTest method shouldRunOtherUnloadListenersAndUnloadPluginBundleEvenIfAListenerFails.

@Test
void shouldRunOtherUnloadListenersAndUnloadPluginBundleEvenIfAListenerFails() {
    final GoPluginDescriptor pluginDescriptor = mock(GoPluginDescriptor.class);
    GoPluginBundleDescriptor pluginBundleDescriptor = new GoPluginBundleDescriptor(pluginDescriptor);
    pluginBundleDescriptor.setBundle(mock(Bundle.class));
    PluginChangeListener listenerWhichWorks1 = mock(PluginChangeListener.class, "Listener Which Works: 1");
    PluginChangeListener listenerWhichWorks2 = mock(PluginChangeListener.class, "Listener Which Works: 2");
    PluginChangeListener listenerWhichThrowsWhenUnloading = mock(PluginChangeListener.class, "Listener Which Throws");
    doThrow(new RuntimeException("Fail!")).when(listenerWhichThrowsWhenUnloading).pluginUnLoaded(pluginDescriptor);
    pluginLoader.addPluginChangeListener(listenerWhichWorks1);
    pluginLoader.addPluginChangeListener(listenerWhichThrowsWhenUnloading);
    pluginLoader.addPluginChangeListener(listenerWhichWorks2);
    pluginLoader.unloadPlugin(pluginBundleDescriptor);
    verify(listenerWhichWorks1, times(1)).pluginUnLoaded(pluginDescriptor);
    verify(listenerWhichThrowsWhenUnloading, times(1)).pluginUnLoaded(pluginDescriptor);
    verify(listenerWhichWorks2, times(1)).pluginUnLoaded(pluginDescriptor);
    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 15 with GoPluginBundleDescriptor

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

the class PluginLoaderTest method shouldNotUnloadAPluginIfItsBundleIsNull.

@Test
void shouldNotUnloadAPluginIfItsBundleIsNull() {
    GoPluginBundleDescriptor pluginDescriptor = mock(GoPluginBundleDescriptor.class);
    when(pluginDescriptor.bundle()).thenReturn(null);
    pluginLoader.unloadPlugin(pluginDescriptor);
    verifyNoMoreInteractions(pluginOSGiFramework);
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) 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