use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldSetCurrentThreadContextClassLoaderToBundleClassLoaderToAvoidDependenciesFromApplicationClassloaderMessingAroundWithThePluginBehavior.
@Test
void shouldSetCurrentThreadContextClassLoaderToBundleClassLoaderToAvoidDependenciesFromApplicationClassloaderMessingAroundWithThePluginBehavior() {
systemEnvironment.setProperty("gocd.plugins.classloader.old", "false");
final GoPluginDescriptor goPluginDescriptor = getPluginDescriptor("plugin.to.test.classloader", pluginToTestClassloadPluginBundleDir);
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);
assertThat(Thread.currentThread().getContextClassLoader().getClass().getCanonicalName()).isEqualTo(BundleClassLoader.class.getCanonicalName());
plugin.pluginIdentifier();
return null;
};
pluginOSGiFramework.doOn(GoPlugin.class, "plugin.to.test.classloader", "notification", action);
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldMarkAPluginInvalidIfAtLoadOfAnyExtensionPointInItFails.
@Test
void shouldMarkAPluginInvalidIfAtLoadOfAnyExtensionPointInItFails() {
String id = "com.tw.go.exception.throwing.at.loadplugin";
GoPluginBundleDescriptor pluginDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor(id, exceptionThrowingAtLoadDescriptorBundleDir));
registry.loadPlugin(pluginDescriptor);
assertThat(pluginDescriptor.isInvalid()).isFalse();
pluginOSGiFramework.loadPlugin(pluginDescriptor);
assertThat(pluginDescriptor.isInvalid()).isTrue();
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldLoadAValidGoPluginOSGiBundleAndShouldBeDiscoverableThroughPluginIDFilter.
@Test
void shouldLoadAValidGoPluginOSGiBundleAndShouldBeDiscoverableThroughPluginIDFilter() throws Exception {
final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor(PLUGIN_ID, descriptorBundleDir));
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
String filterByPluginID = String.format("(%s=%s)", "PLUGIN_ID", "testplugin.descriptorValidator");
BundleContext context = bundle.getBundleContext();
ServiceReference<?>[] allServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), filterByPluginID);
assertThat(allServiceReferences.length).isEqualTo(1);
try {
GoPlugin service = (GoPlugin) context.getService(allServiceReferences[0]);
service.pluginIdentifier();
} catch (Exception e) {
fail(String.format("pluginIdentifier should have been called. Exception: %s", e.getMessage()));
}
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldHandleErrorGeneratedByAValidGoPluginOSGiBundleAtUsageTime.
@Test
void shouldHandleErrorGeneratedByAValidGoPluginOSGiBundleAtUsageTime() {
final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor(PLUGIN_ID, errorGeneratingDescriptorBundleDir));
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
assertThat(bundleDescriptor.isInvalid()).isFalse();
ActionWithReturn<GoPlugin, Object> action = (goPlugin, goPluginDescriptor) -> {
goPlugin.initializeGoApplicationAccessor(null);
return null;
};
try {
pluginOSGiFramework.doOn(GoPlugin.class, PLUGIN_ID, "extension-1", action);
fail("Should Throw An Exception");
} catch (Exception ex) {
ex.printStackTrace();
assertThat(ex.getCause() instanceof AbstractMethodError).isTrue();
}
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldLoadAValidPluginWithMultipleExtensions_ImplementingDifferentExtensions.
@Test
void shouldLoadAValidPluginWithMultipleExtensions_ImplementingDifferentExtensions() throws Exception {
final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor("valid-plugin-with-multiple-extensions", validMultipleExtensionPluginBundleDir));
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
BundleContext context = bundle.getBundleContext();
String taskExtensionFilter = String.format("(&(%s=%s)(%s=%s))", "PLUGIN_ID", "valid-plugin-with-multiple-extensions", Constants.BUNDLE_CATEGORY, "task");
String analyticsExtensionFilter = String.format("(&(%s=%s)(%s=%s))", "PLUGIN_ID", "valid-plugin-with-multiple-extensions", Constants.BUNDLE_CATEGORY, "analytics");
ServiceReference<?>[] taskExtensionServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), taskExtensionFilter);
assertThat(taskExtensionServiceReferences.length).isEqualTo(1);
assertThat(((GoPlugin) context.getService(taskExtensionServiceReferences[0])).pluginIdentifier().getExtension()).isEqualTo("task");
ServiceReference<?>[] analyticsExtensionServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), analyticsExtensionFilter);
assertThat(analyticsExtensionServiceReferences.length).isEqualTo(1);
assertThat(((GoPlugin) context.getService(analyticsExtensionServiceReferences[0])).pluginIdentifier().getExtension()).isEqualTo("analytics");
}
Aggregations