Search in sources :

Example 21 with GoPluginBundleDescriptor

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

the class FelixGoPluginOSGiFrameworkTest method shouldSkipUninstallIfPluginIsPreviouslyUninstalled.

@Test
void shouldSkipUninstallIfPluginIsPreviouslyUninstalled() throws BundleException {
    GoPluginBundleDescriptor pluginDescriptor = mock(GoPluginBundleDescriptor.class);
    when(pluginDescriptor.bundle()).thenReturn(bundle);
    when(bundle.getState()).thenReturn(Bundle.UNINSTALLED);
    spy.unloadPlugin(pluginDescriptor);
    verify(bundle, never()).start();
    verify(bundle, never()).uninstall();
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) Test(org.junit.jupiter.api.Test)

Example 22 with GoPluginBundleDescriptor

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

the class FelixGoPluginOSGiFrameworkTest method shouldUnloadAPlugin.

@Test
void shouldUnloadAPlugin() throws BundleException {
    GoPluginBundleDescriptor pluginDescriptor = mock(GoPluginBundleDescriptor.class);
    when(pluginDescriptor.bundle()).thenReturn(bundle);
    spy.unloadPlugin(pluginDescriptor);
    verify(bundle, atLeastOnce()).stop();
    verify(bundle, atLeastOnce()).uninstall();
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) Test(org.junit.jupiter.api.Test)

Example 23 with GoPluginBundleDescriptor

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

the class FelixGoPluginOSGiFrameworkTest method shouldNotFailToUnloadAPluginWhoseBundleIsNull.

@Test
void shouldNotFailToUnloadAPluginWhoseBundleIsNull() {
    GoPluginBundleDescriptor pluginDescriptor = mock(GoPluginBundleDescriptor.class);
    when(pluginDescriptor.bundle()).thenReturn(null);
    try {
        spy.unloadPlugin(pluginDescriptor);
    } catch (Exception e) {
        fail("Should not have thrown an exception");
    }
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) Test(org.junit.jupiter.api.Test)

Example 24 with GoPluginBundleDescriptor

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

the class PackageLevelClassWithPublicInnerClass method installBundleFoundInDirectory.

private Bundle installBundleFoundInDirectory(File bundleWithActivator) {
    final GoPluginDescriptor pluginDescriptor = GoPluginDescriptor.builder().id(GO_TEST_DUMMY_SYMBOLIC_NAME).version("1").bundleLocation(bundleWithActivator).isBundledPlugin(true).build();
    GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(pluginDescriptor);
    registry.fakeRegistrationOfPlugin(pluginDescriptor);
    return framework.loadPlugin(bundleDescriptor);
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)

Example 25 with GoPluginBundleDescriptor

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

the class PluginsZip method create.

public void create() {
    checkFilesAccessibility(bundledPlugins, externalPlugins);
    reset();
    MessageDigest md5Digest = DigestUtils.getMd5Digest();
    try (ZipOutputStream zos = new ZipOutputStream(new DigestOutputStream(new BufferedOutputStream(new FileOutputStream(destZipFile)), md5Digest))) {
        for (GoPluginBundleDescriptor agentPlugins : agentPlugins()) {
            String zipEntryPrefix = "external/";
            if (agentPlugins.isBundledPlugin()) {
                zipEntryPrefix = "bundled/";
            }
            zos.putNextEntry(new ZipEntry(zipEntryPrefix + new File(agentPlugins.bundleJARFileLocation()).getName()));
            Files.copy(new File(agentPlugins.bundleJARFileLocation()).toPath(), zos);
            zos.closeEntry();
        }
    } catch (Exception e) {
        LOG.error("Could not create zip of plugins for agent to download.", e);
    }
    md5DigestOfPlugins = Hex.encodeHexString(md5Digest.digest());
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) DigestOutputStream(java.security.DigestOutputStream) GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) MessageDigest(java.security.MessageDigest) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

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