use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.
the class DefaultPluginJarChangeListener method removePlugin.
private void removePlugin(GoPluginDescriptor descriptor) {
GoPluginDescriptor descriptorOfRemovedPlugin = registry.unloadPlugin(descriptor);
goPluginOSGiFramework.unloadPlugin(descriptorOfRemovedPlugin);
boolean bundleLocationHasBeenDeleted = FileUtils.deleteQuietly(descriptorOfRemovedPlugin.bundleLocation());
if (!bundleLocationHasBeenDeleted) {
throw new RuntimeException(String.format("Failed to remove bundle jar %s from bundle location %s", descriptorOfRemovedPlugin.fileName(), descriptorOfRemovedPlugin.bundleLocation()));
}
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.
the class DefaultPluginJarChangeListener method pluginJarUpdated.
@Override
public void pluginJarUpdated(PluginFileDetails pluginFileDetails) {
GoPluginDescriptor descriptor = goPluginDescriptorBuilder.build(pluginFileDetails.file(), pluginFileDetails.isBundledPlugin());
GoPluginDescriptor existingDescriptor = registry.getPluginByIdOrFileName(descriptor.id(), descriptor.fileName());
validateIfExternalPluginRemovingBundledPlugin(descriptor, existingDescriptor);
validateIfSamePluginUpdated(descriptor, existingDescriptor);
validatePluginCompatibilityWithCurrentOS(descriptor);
removePlugin(descriptor);
addPlugin(pluginFileDetails, descriptor);
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.
the class DefaultPluginManagerIntegrationTest method shouldRegisterTheExtensionClassesOfAPluginAndExposeItInItsDescriptorAfterItIsLoaded.
@Test
public void shouldRegisterTheExtensionClassesOfAPluginAndExposeItInItsDescriptorAfterItIsLoaded() throws Exception {
GoPluginDescriptor plugin = pluginManager.getPluginDescriptorFor(PLUGIN_ID_1);
assertThat(plugin.id(), is(PLUGIN_ID_1));
assertThat(plugin.bundleSymbolicName(), is(PLUGIN_ID_1));
assertThat(plugin.bundleClassPath(), is("lib/go-plugin-activator.jar,.,lib/dependency.jar"));
assertThat(plugin.bundleActivator(), is(DefaultGoPluginActivator.class.getCanonicalName()));
assertThat(plugin.isInvalid(), is(false));
//property set by the plugin in the setPluginDescriptor method.
assertThat(System.getProperty(PLUGIN_DESC_PROPERTY_SET_BY_TEST_PLUGIN_1), is(plugin.toString()));
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.
the class DefaultPluginManagerTest method shouldNotFindPluginIsOfGivenExtensionWhenReferenceNotFoundAndExtensionDoNotMatch.
@Test
public void shouldNotFindPluginIsOfGivenExtensionWhenReferenceNotFoundAndExtensionDoNotMatch() throws Exception {
final String pluginThatDoesNotImplement = "plugin-that-does-not-implement";
GoPluginIdentifier pluginIdentifier = new GoPluginIdentifier("another-extension-type", asList("1.0"));
final GoPlugin goPlugin = mock(GoPlugin.class);
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
when(goPluginOSGiFramework.hasReferenceFor(GoPlugin.class, pluginThatDoesNotImplement)).thenReturn(true);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
ActionWithReturn<GoPlugin, GoPluginApiResponse> action = (ActionWithReturn<GoPlugin, GoPluginApiResponse>) invocationOnMock.getArguments()[2];
return action.execute(goPlugin, descriptor);
}
}).when(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq(pluginThatDoesNotImplement), any(ActionWithReturn.class));
when(goPlugin.pluginIdentifier()).thenReturn(pluginIdentifier);
DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, goPluginOSGiFramework, jarChangeListener, pluginRequestProcessorRegistry, pluginWriter, pluginValidator, systemEnvironment, pluginsZipUpdater, pluginsListListener);
assertFalse(pluginManager.isPluginOfType("extension-type", pluginThatDoesNotImplement));
verify(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq(pluginThatDoesNotImplement), any(ActionWithReturn.class));
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.
the class DefaultPluginJarChangeListenerTest method pluginDescriptorAwareCallbackErrorShouldNotBeFatal.
@Test
public void pluginDescriptorAwareCallbackErrorShouldNotBeFatal() throws Exception {
String pluginJarFileName = "descriptor-aware-test-plugin.jar";
File pluginJarFile = new File(PLUGIN_DIR, pluginJarFileName);
copyPluginToTheDirectory(PLUGIN_DIR, pluginJarFileName);
GoPluginDescriptor descriptor = new GoPluginDescriptor("some.old.id", "1.0", new GoPluginDescriptor.About(null, null, null, null, null, null), null, new File(pluginJarFileName), false);
when(systemEnvironment.getOperatingSystemFamilyName()).thenReturn("Windows");
when(goPluginDescriptorBuilder.build(pluginJarFile, true)).thenReturn(descriptor);
when(osgiFramework.hasReferenceFor(PluginDescriptorAware.class, descriptor.id())).thenReturn(true);
doThrow(new RuntimeException("Exception in plugin descriptor")).when(osgiFramework).doOnAllForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject());
listener = new DefaultPluginJarChangeListener(registry, osgiManifestGenerator, osgiFramework, goPluginDescriptorBuilder, systemEnvironment);
listener.pluginJarAdded(new PluginFileDetails(pluginJarFile, true));
verify(registry, times(1)).loadPlugin(descriptor);
verify(osgiFramework, times(1)).loadPlugin(descriptor);
verify(osgiFramework, times(1)).hasReferenceFor(PluginDescriptorAware.class, descriptor.id());
verify(osgiFramework, times(1)).doOnAllWithExceptionHandlingForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject(), Matchers.<ExceptionHandler<PluginDescriptorAware>>anyObject());
}
Aggregations