Search in sources :

Example 16 with ResolverHookFactory

use of org.osgi.framework.hooks.resolver.ResolverHookFactory in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testBug370258_beginException.

public void testBug370258_beginException() {
    final boolean[] endCalled = { false };
    ResolverHookFactory endHook = new ResolverHookFactory() {

        public ResolverHook begin(Collection triggers) {
            return new ResolverHook() {

                public void filterSingletonCollisions(BundleCapability singleton, Collection collisionCandidates) {
                // Nothing
                }

                public void filterResolvable(Collection candidates) {
                    throw new RuntimeException("Error");
                }

                public void filterMatches(BundleRequirement requirement, Collection candidates) {
                // Nothing
                }

                public void end() {
                    endCalled[0] = true;
                }
            };
        }
    };
    ResolverHookFactory error = new ResolverHookFactory() {

        public ResolverHook begin(Collection triggers) {
            throw new RuntimeException("Error");
        }
    };
    ServiceRegistration endReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, endHook, null);
    ServiceRegistration errorReg = OSGiTestsActivator.getContext().registerService(ResolverHookFactory.class, error, null);
    try {
        // $NON-NLS-1$
        Bundle test = installer.installBundle("test");
        try {
            test.start();
            fail("Should not be able to start this bundle");
        } catch (BundleException e) {
            // expected
            assertEquals("Wrong exception type.", BundleException.REJECTED_BY_HOOK, e.getType());
        }
    } catch (BundleException e) {
        fail("Unexpected install fail", e);
    } finally {
        errorReg.unregister();
        endReg.unregister();
    }
    assertTrue("end is not called", endCalled[0]);
}
Also used : ResolverHookFactory(org.osgi.framework.hooks.resolver.ResolverHookFactory) ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) Bundle(org.osgi.framework.Bundle) Collection(java.util.Collection) BundleException(org.osgi.framework.BundleException) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 17 with ResolverHookFactory

use of org.osgi.framework.hooks.resolver.ResolverHookFactory in project fabric8 by jboss-fuse.

the class AgentTest method testAgent.

@Test
public void testAgent() throws Exception {
    System.setProperty("karaf.data", new File("target/karaf/data").getAbsolutePath());
    System.setProperty("karaf.home", new File("target/karaf").getAbsolutePath());
    Dictionary<String, String> resolverProps = new Hashtable<>();
    resolverProps.put(ServiceConstants.PROPERTY_REPOSITORIES, "http://repository.jboss.org/nexus/content/repositories/fs-public/@id=jboss.fs.public," + "https://repository.jboss.org/nexus/content/groups/ea/@id=jboss.ea.repo," + "http://repo1.maven.org/maven2@id=maven.central.repo," + "http://download.eng.bos.redhat.com/brewroot/repos/jb-fuse-6.2-build/latest/maven@id=brew");
    MavenResolver mavenResolver = MavenResolvers.createMavenResolver(resolverProps, null);
    DownloadManager manager = DownloadManagers.createDownloadManager(mavenResolver, Executors.newScheduledThreadPool(8));
    BundleContext systemBundleContext = createMock(BundleContext.class);
    TestSystemBundle systemBundle = createTestSystemBundle("/common", "system-bundle");
    systemBundle.setBundleContext(systemBundleContext);
    Bundle serviceBundle = createTestBundle(1l, Bundle.ACTIVE, "/common", "fabric-agent");
    expect(systemBundleContext.getBundle()).andReturn(systemBundle).anyTimes();
    expect(systemBundleContext.getBundles()).andReturn(new Bundle[] { systemBundle }).anyTimes();
    long nextBundleId = 2;
    List<Bundle> mockBundles = new ArrayList<>();
    String karafVersion = System.getProperty("karaf-version");
    String[] bundles = { "mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.api/1.0.1", "mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.cm/1.1.0", "mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core/1.8.0", "mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core.compatibility/1.0.0", "mvn:org.apache.aries.proxy/org.apache.aries.proxy/1.1.1", "mvn:org.apache.aries/org.apache.aries.util/1.1.3", "mvn:org.apache.felix/org.apache.felix.configadmin/1.8.12", "mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.command/" + karafVersion, "mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.config/" + karafVersion, "mvn:org.apache.karaf.jaas/org.apache.karaf.jaas.modules/" + karafVersion, "mvn:org.apache.karaf.shell/org.apache.karaf.shell.commands/" + karafVersion, "mvn:org.apache.karaf.shell/org.apache.karaf.shell.console/" + karafVersion, "mvn:org.apache.karaf.shell/org.apache.karaf.shell.dev/" + karafVersion, "mvn:org.apache.karaf.shell/org.apache.karaf.shell.log/" + karafVersion, "mvn:org.apache.karaf.shell/org.apache.karaf.shell.osgi/" + karafVersion, "mvn:org.apache.karaf.shell/org.apache.karaf.shell.packages/" + karafVersion, "mvn:org.apache.karaf.shell/org.apache.karaf.shell.ssh/" + karafVersion, "mvn:org.apache.mina/mina-core/2.0.13", "mvn:org.apache.sshd/sshd-core/0.14.0.redhat-001", "mvn:org.ow2.asm/asm-all/5.0.4", "mvn:org.ops4j.pax.logging/pax-logging-api/1.9.1", "mvn:org.ops4j.pax.logging/pax-logging-service/1.9.1" };
    for (String bundleUri : bundles) {
        File file = mavenResolver.download(bundleUri);
        Hashtable<String, String> headers = doGetMetadata(file);
        TestBundle bundle = new TestBundle(++nextBundleId, bundleUri, Bundle.INSTALLED, headers) {

            @Override
            public void setStartLevel(int startlevel) {
            }

            @Override
            public void start() throws BundleException {
            }
        };
        expect(systemBundleContext.installBundle(EasyMock.eq(bundleUri), EasyMock.<InputStream>anyObject())).andReturn(bundle);
    }
    ServiceRegistration registration = EasyMock.createMock(ServiceRegistration.class);
    expect(systemBundleContext.registerService(EasyMock.eq(ResolverHookFactory.class), EasyMock.<ResolverHookFactory>anyObject(), EasyMock.<Dictionary>isNull())).andReturn(registration);
    registration.unregister();
    replay(systemBundleContext, registration);
    for (Bundle bundle : mockBundles) {
        replay(bundle);
    }
    Agent agent = new Agent(serviceBundle, systemBundleContext, manager) {

        @Override
        protected <T> void awaitService(Class<T> serviceClass, String filterspec, int timeout, TimeUnit timeUnit) {
        }
    };
    String karafFeaturesUrl = "mvn:org.apache.karaf.assemblies.features/standard/" + System.getProperty("karaf-version") + "/xml/features";
    agent.provision(Collections.singleton(karafFeaturesUrl), Collections.singleton("ssh"), Collections.<String>emptySet(), Collections.<String>emptySet(), Collections.<String>emptySet(), new HashSet<>(Arrays.asList("mvn:org.ops4j.pax.logging/pax-logging-api/1.9.1", "mvn:org.ops4j.pax.logging/pax-logging-service/1.9.1", "mvn:org.apache.felix/org.apache.felix.configadmin/1.8.12")), Collections.<String, Map<VersionRange, Map<String, String>>>emptyMap());
}
Also used : ResolverHookFactory(org.osgi.framework.hooks.resolver.ResolverHookFactory) Bundle(org.osgi.framework.Bundle) VersionRange(org.apache.felix.utils.version.VersionRange) DownloadManager(io.fabric8.agent.download.DownloadManager) MavenResolver(io.fabric8.maven.MavenResolver) TimeUnit(java.util.concurrent.TimeUnit) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Aggregations

ResolverHookFactory (org.osgi.framework.hooks.resolver.ResolverHookFactory)17 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)15 Bundle (org.osgi.framework.Bundle)8 BundleCapability (org.osgi.framework.wiring.BundleCapability)8 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)8 Collection (java.util.Collection)7 BundleException (org.osgi.framework.BundleException)7 ServiceRegistration (org.osgi.framework.ServiceRegistration)7 BundleRevision (org.osgi.framework.wiring.BundleRevision)6 Test (org.junit.Test)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Equinox (org.eclipse.osgi.launch.Equinox)3 BundleContext (org.osgi.framework.BundleContext)3 HashMap (java.util.HashMap)2 List (java.util.List)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Module (org.eclipse.osgi.container.Module)2