Search in sources :

Example 6 with GoPluginBundleDescriptor

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

the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldLoadAValidGoPluginOSGiBundle.

@Test
void shouldLoadAValidGoPluginOSGiBundle() 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);
    BundleContext context = bundle.getBundleContext();
    ServiceReference<?>[] allServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), null);
    assertThat(allServiceReferences.length).isEqualTo(1);
    try {
        GoPlugin service = (GoPlugin) context.getService(allServiceReferences[0]);
        service.pluginIdentifier();
        assertThat(getIntField(service, "loadCalled")).as("@Load should have been called").isEqualTo(1);
    } catch (Exception e) {
        fail(String.format("pluginIdentifier should have been called. Exception: %s", e.getMessage()));
    }
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) Bundle(org.osgi.framework.Bundle) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) IOException(java.io.IOException) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.jupiter.api.Test)

Example 7 with GoPluginBundleDescriptor

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

the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldUnloadALoadedPlugin.

@Test
void shouldUnloadALoadedPlugin() throws Exception {
    GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor(PLUGIN_ID, descriptorBundleDir));
    registry.loadPlugin(bundleDescriptor);
    Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
    BundleContext context = bundle.getBundleContext();
    ServiceReference<?>[] allServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), null);
    assertThat(allServiceReferences.length).isEqualTo(1);
    GoPlugin service = (GoPlugin) context.getService(allServiceReferences[0]);
    assertThat(getIntField(service, "loadCalled")).as("@Load should have been called").isEqualTo(1);
    bundleDescriptor.setBundle(bundle);
    pluginOSGiFramework.unloadPlugin(bundleDescriptor);
    assertThat(bundle.getState()).isEqualTo(Bundle.UNINSTALLED);
    assertThat(getIntField(service, "unloadCalled")).as("@UnLoad should have been called").isEqualTo(1);
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) Bundle(org.osgi.framework.Bundle) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.jupiter.api.Test)

Example 8 with GoPluginBundleDescriptor

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

the class ElasticAgentInformationMigratorImplTest method setUp.

@BeforeEach
void setUp() {
    goPluginDescriptor = GoPluginDescriptor.builder().id(PLUGIN_ID).build();
    goPluginDescriptor.setBundleDescriptor(new GoPluginBundleDescriptor(goPluginDescriptor));
    elasticAgentInformationMigrator = new ElasticAgentInformationMigratorImpl(pluginSqlMapDao, clusterProfilesService, elasticProfileService, elasticAgentExtension, pluginManager, goConfigService);
}
Also used : GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with GoPluginBundleDescriptor

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

the class ConfigRepositoryInitializerTest method setUp.

@BeforeEach
void setUp() {
    yamlPluginDescriptor = GoPluginDescriptor.builder().id(YAML_PLUGIN_ID).build();
    yamlPluginDescriptor.setBundleDescriptor(new GoPluginBundleDescriptor(yamlPluginDescriptor));
    jsonPluginDescriptor = GoPluginDescriptor.builder().id(JSON_PLUGIN_ID).build();
    jsonPluginDescriptor.setBundleDescriptor(new GoPluginBundleDescriptor(jsonPluginDescriptor));
    groovyPluginDescriptor = GoPluginDescriptor.builder().id(GROOVY_PLUGIN_ID).build();
    groovyPluginDescriptor.setBundleDescriptor(new GoPluginBundleDescriptor(groovyPluginDescriptor));
    configRepositoryInitializer = new ConfigRepositoryInitializer(pluginManager, configRepoService, materialRepository, goConfigRepoConfigDataSource, goConfigService, systemEnvironment);
    repoConfigs = new ConfigReposConfig();
    ConfigRepoConfig repoConfig1 = new ConfigRepoConfig();
    repoConfig1.setId("repo1");
    repoConfig1.setPluginId(YAML_PLUGIN_ID);
    repoConfig1.setRepo(MaterialConfigsMother.git("git-repo"));
    repoConfigs.add(repoConfig1);
    lenient().when(configRepoService.getConfigRepos()).thenReturn(repoConfigs);
    lenient().when(pluginManager.isPluginOfType(CONFIG_REPO_EXTENSION, YAML_PLUGIN_ID)).thenReturn(true);
    lenient().when(pluginManager.isPluginOfType(CONFIG_REPO_EXTENSION, JSON_PLUGIN_ID)).thenReturn(true);
}
Also used : ConfigReposConfig(com.thoughtworks.go.config.remote.ConfigReposConfig) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with GoPluginBundleDescriptor

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

the class PluginsZipTest method shouldCreateAZipWithOneCopyOfEachJar_ForAPluginBundleWithMultiplePluginsInIt.

@Test
void shouldCreateAZipWithOneCopyOfEachJar_ForAPluginBundleWithMultiplePluginsInIt() throws IOException {
    File bundledPluginJarLocation = createPluginFile(bundledPluginsDir, "bundled-multi-plugin-1.jar", "Bundled1");
    File externalPluginJarLocation = createPluginFile(externalPluginsDir, "external-multi-plugin-1.jar", "External1");
    bundledTaskPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("bundled-plugin-1", bundledPluginJarLocation, true), getPluginDescriptor("bundled-plugin-2", bundledPluginJarLocation, true));
    externalTaskPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("external-plugin-1", externalPluginJarLocation, false), getPluginDescriptor("external-plugin-2", externalPluginJarLocation, false));
    when(pluginManager.plugins()).thenReturn(Arrays.asList(bundledTaskPlugin.descriptors().get(0), bundledTaskPlugin.descriptors().get(1), externalTaskPlugin.descriptors().get(0), externalTaskPlugin.descriptors().get(1)));
    when(pluginManager.isPluginOfType("task", "bundled-plugin-1")).thenReturn(true);
    when(pluginManager.isPluginOfType("scm", "bundled-plugin-2")).thenReturn(true);
    when(pluginManager.isPluginOfType("task", "external-plugin-1")).thenReturn(true);
    when(pluginManager.isPluginOfType("artifact", "external-plugin-2")).thenReturn(true);
    pluginsZip = spy(new PluginsZip(systemEnvironment, pluginManager));
    pluginsZip.create();
    try (ZipFile zipFile = new ZipFile(expectedZipPath)) {
        assertThat(new File(expectedZipPath).exists()).as(expectedZipPath + " should exist").isTrue();
        assertThat(EnumerationUtils.toList(zipFile.entries()).size()).isEqualTo(2);
        assertThat(zipFile.getEntry("bundled/bundled-multi-plugin-1.jar")).isNotNull();
        assertThat(zipFile.getEntry("external/external-multi-plugin-1.jar")).isNotNull();
    }
}
Also used : ZipFile(java.util.zip.ZipFile) GoPluginBundleDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor) File(java.io.File) ZipFile(java.util.zip.ZipFile) 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