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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations