Search in sources :

Example 11 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class ScopeManager method filterResolvable.

public void filterResolvable(Collection<BundleRevision> candidates) {
    for (Iterator<BundleRevision> i = candidates.iterator(); i.hasNext(); ) {
        BundleRevision candidate = i.next();
        ScopeImpl scope = scopes.getScope(candidate.getBundle());
        if (scope.isUpdating())
            i.remove();
    }
}
Also used : BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 12 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class Activator method forceBuilder.

private boolean forceBuilder(BundleContext context) {
    String forceBuilderProp = context.getProperty(FORCE_BUILDER);
    if (forceBuilderProp != null) {
        return true;
    }
    BundleRevision revision = context.getBundle().adapt(BundleRevision.class);
    return !(revision.getDeclaredCapabilities(FORCE_BUILDER).isEmpty());
}
Also used : BundleRevision(org.osgi.framework.wiring.BundleRevision)

Example 13 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class ClientWeavingHookGenericCapabilityTest method testHeadersFromFragment.

@Test
public void testHeadersFromFragment() throws Exception {
    // Register the bundle that provides the SPI implementation.
    Bundle providerBundle = mockProviderBundle("impl1", 1);
    activator.registerProviderBundle("org.apache.aries.mytest.MySPI", providerBundle, new HashMap<String, Object>());
    Dictionary<String, String> fragmentConsumerHeaders = new Hashtable<String, String>();
    fragmentConsumerHeaders.put(SpiFlyConstants.REQUIRE_CAPABILITY, SpiFlyConstants.CLIENT_REQUIREMENT);
    Bundle fragment = EasyMock.createMock(Bundle.class);
    EasyMock.expect(fragment.getHeaders()).andReturn(fragmentConsumerHeaders).anyTimes();
    EasyMock.replay(fragment);
    BundleRevision frev = EasyMock.createMock(BundleRevision.class);
    EasyMock.expect(frev.getBundle()).andReturn(fragment).anyTimes();
    EasyMock.replay(frev);
    BundleRequirement req = EasyMock.createMock(BundleRequirement.class);
    EasyMock.expect(req.getRevision()).andReturn(frev).anyTimes();
    EasyMock.replay(req);
    BundleWire wire = EasyMock.createMock(BundleWire.class);
    EasyMock.expect(wire.getRequirement()).andReturn(req).anyTimes();
    EasyMock.replay(wire);
    List<BundleWire> wires = Collections.singletonList(wire);
    BundleWiring wiring = EasyMock.createMock(BundleWiring.class);
    EasyMock.expect(wiring.getProvidedWires("osgi.wiring.host")).andReturn(wires).anyTimes();
    EasyMock.replay(wiring);
    BundleRevision rev = EasyMock.createMock(BundleRevision.class);
    EasyMock.expect(rev.getWiring()).andReturn(wiring).anyTimes();
    EasyMock.replay(rev);
    Bundle consumerBundle = mockConsumerBundle(new Hashtable<String, String>(), rev, providerBundle);
    activator.addConsumerWeavingData(consumerBundle, SpiFlyConstants.REQUIRE_CAPABILITY);
    Bundle spiFlyBundle = mockSpiFlyBundle("spifly", Version.parseVersion("1.9.4"), consumerBundle, providerBundle);
    WeavingHook wh = new ClientWeavingHook(spiFlyBundle.getBundleContext(), activator);
    // Weave the TestClient class.
    URL clsUrl = getClass().getResource("TestClient.class");
    Assert.assertNotNull("Precondition", clsUrl);
    String clientClassName = "org.apache.aries.spifly.dynamic.TestClient";
    WovenClass wc = new MyWovenClass(clsUrl, clientClassName, consumerBundle);
    Assert.assertEquals("Precondition", 0, wc.getDynamicImports().size());
    wh.weave(wc);
    Assert.assertEquals(1, wc.getDynamicImports().size());
    String di1 = "org.apache.aries.spifly;bundle-symbolic-name=spifly;bundle-version=1.9.4";
    String di2 = "org.apache.aries.spifly;bundle-version=1.9.4;bundle-symbolic-name=spifly";
    String di = wc.getDynamicImports().get(0);
    Assert.assertTrue("Weaving should have added a dynamic import", di1.equals(di) || di2.equals(di));
    // Invoke the woven class and check that it properly sets the TCCL so that the
    // META-INF/services/org.apache.aries.mytest.MySPI file from impl1 is visible.
    Class<?> cls = wc.getDefinedClass();
    Method method = cls.getMethod("test", new Class[] { String.class });
    Object result = method.invoke(cls.newInstance(), "hello");
    Assert.assertEquals(Collections.singleton("olleh"), result);
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) BundleWiring(org.osgi.framework.wiring.BundleWiring) WovenClass(org.osgi.framework.hooks.weaving.WovenClass) Method(java.lang.reflect.Method) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) URL(java.net.URL) BundleRevision(org.osgi.framework.wiring.BundleRevision) WeavingHook(org.osgi.framework.hooks.weaving.WeavingHook) Test(org.junit.Test)

Example 14 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class ClientWeavingHookGenericCapabilityTest method mockConsumerBundle.

private Bundle mockConsumerBundle(Dictionary<String, String> headers, BundleRevision rev, Bundle... otherBundles) {
    // Create a mock object for the client bundle which holds the code that uses ServiceLoader.load()
    // or another SPI invocation.
    BundleContext bc = EasyMock.createMock(BundleContext.class);
    Bundle consumerBundle = EasyMock.createMock(Bundle.class);
    EasyMock.expect(consumerBundle.getSymbolicName()).andReturn("testConsumer").anyTimes();
    EasyMock.expect(consumerBundle.getVersion()).andReturn(new Version(1, 2, 3)).anyTimes();
    EasyMock.expect(consumerBundle.getHeaders()).andReturn(headers).anyTimes();
    EasyMock.expect(consumerBundle.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.expect(consumerBundle.getBundleId()).andReturn(Long.MAX_VALUE).anyTimes();
    EasyMock.expect(consumerBundle.adapt(BundleRevision.class)).andReturn(rev).anyTimes();
    EasyMock.replay(consumerBundle);
    List<Bundle> allBundles = new ArrayList<Bundle>(Arrays.asList(otherBundles));
    allBundles.add(consumerBundle);
    EasyMock.expect(bc.getBundles()).andReturn(allBundles.toArray(new Bundle[] {})).anyTimes();
    EasyMock.replay(bc);
    return consumerBundle;
}
Also used : Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) ArrayList(java.util.ArrayList) BundleContext(org.osgi.framework.BundleContext)

Example 15 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision in project aries by apache.

the class BundleWiringState method getCurrentRevisionDeclaredCapabilities.

/* (non-Javadoc)
     * @see org.osgi.jmx.framework.BundleRevisionsStateMBean#getCurrentRevisionDeclaredCapabilities(long, java.lang.String)
     */
public CompositeData[] getCurrentRevisionDeclaredCapabilities(long bundleId, String namespace) throws IOException {
    Bundle bundle = FrameworkUtils.resolveBundle(bundleContext, bundleId);
    BundleRevision revision = bundle.adapt(BundleRevision.class);
    return BundleWiringData.getCapabilitiesCompositeData(revision.getDeclaredCapabilities(namespace));
}
Also used : Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Aggregations

BundleRevision (org.osgi.framework.wiring.BundleRevision)66 Bundle (org.osgi.framework.Bundle)38 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)14 Map (java.util.Map)11 Test (org.junit.Test)11 BundleCapability (org.osgi.framework.wiring.BundleCapability)11 BundleWiring (org.osgi.framework.wiring.BundleWiring)11 Resource (org.osgi.resource.Resource)11 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)9 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)9 HashSet (java.util.HashSet)8 BundleWire (org.osgi.framework.wiring.BundleWire)8 BundleConstituent (org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent)7 Set (java.util.Set)6 TreeMap (java.util.TreeMap)6 TabularData (javax.management.openmbean.TabularData)6 IOException (java.io.IOException)5 Collection (java.util.Collection)5 List (java.util.List)5