Search in sources :

Example 76 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring in project felix by apache.

the class DTOFactory method createBundleWireDTO.

private static BundleWireDTO createBundleWireDTO(Wire wire, Set<BundleRevisionDTO> resources, Set<NodeDTO> nodes) {
    BundleWireDTO wdto = new BundleWireDTO();
    if (wire instanceof BundleWire) {
        BundleWire w = (BundleWire) wire;
        BundleWiring pw = w.getProviderWiring();
        addWiringNodeIfNotPresent(pw, resources, nodes);
        wdto.providerWiring = getWiringID(pw);
        BundleWiring rw = w.getRequirerWiring();
        addWiringNodeIfNotPresent(rw, resources, nodes);
        wdto.requirerWiring = getWiringID(rw);
    }
    wdto.provider = getResourceIDAndAdd(wire.getProvider(), resources);
    wdto.requirer = getResourceIDAndAdd(wire.getRequirer(), resources);
    wdto.capability = new CapabilityRefDTO();
    wdto.capability.capability = getCapabilityID(wire.getCapability());
    wdto.capability.resource = getResourceIDAndAdd(wire.getCapability().getResource(), resources);
    wdto.requirement = new RequirementRefDTO();
    wdto.requirement.requirement = getRequirementID(wire.getRequirement());
    wdto.requirement.resource = getResourceIDAndAdd(wire.getRequirement().getResource(), resources);
    return wdto;
}
Also used : CapabilityRefDTO(org.osgi.resource.dto.CapabilityRefDTO) BundleWiring(org.osgi.framework.wiring.BundleWiring) RequirementRefDTO(org.osgi.resource.dto.RequirementRefDTO) BundleWireDTO(org.osgi.framework.wiring.dto.BundleWireDTO) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 77 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring in project felix by apache.

the class ConfigurationProcessor method activate.

/**
 * A bundle is starting.
 *
 * @param bundle the bundle
 */
public void activate(Bundle bundle) {
    if (!m_enabled && Extender.getIPOJOBundleContext().getBundle().getBundleId() == bundle.getBundleId()) {
        // Fast return if the configuration tracking is disabled, or if we are iPOJO
        return;
    }
    // It's not required to process bundle not importing the configuration package.
    final String imports = bundle.getHeaders().get(Constants.IMPORT_PACKAGE);
    if (imports == null || !imports.contains("org.apache.felix.ipojo.configuration")) {
        // TODO Check dynamic imports to verify if the package is not imported lazily.
        return;
    }
    BundleWiring wiring = bundle.adapt(BundleWiring.class);
    if (wiring == null) {
        // Invalid state.
        m_logger.log(Log.ERROR, "The bundle " + bundle.getBundleId() + " (" + bundle.getSymbolicName() + ") " + "cannot be adapted to BundleWiring, state: " + bundle.getState());
        return;
    }
    // Only lookup for local classes, parent classes will be analyzed on demand.
    Collection<String> resources = wiring.listResources("/", "*.class", BundleWiring.FINDENTRIES_RECURSE + BundleWiring.LISTRESOURCES_LOCAL);
    if (resources == null) {
        m_logger.log(Log.ERROR, "The bundle " + bundle.getBundleId() + " (" + bundle.getSymbolicName() + ") " + " does not have any classes to be analyzed");
        return;
    }
    m_logger.log(Log.DEBUG, resources.size() + " classes found");
    handleResources(bundle, resources, wiring.getClassLoader());
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring)

Example 78 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.

the class EquinoxBundle method adapt0.

@SuppressWarnings("unchecked")
private <A> A adapt0(Class<A> adapterType) {
    if (AccessControlContext.class.equals(adapterType)) {
        Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
        ProtectionDomain domain = current.getDomain();
        return (A) (domain == null ? null : new AccessControlContext(new ProtectionDomain[] { domain }));
    }
    if (BundleContext.class.equals(adapterType)) {
        try {
            return (A) getBundleContext();
        } catch (SecurityException e) {
            return null;
        }
    }
    if (BundleRevision.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        return (A) module.getCurrentRevision();
    }
    if (BundleRevisions.class.equals(adapterType)) {
        return (A) module.getRevisions();
    }
    if (BundleStartLevel.class.equals(adapterType)) {
        return (A) module;
    }
    if (BundleWiring.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        ModuleRevision revision = module.getCurrentRevision();
        if (revision == null) {
            return null;
        }
        return (A) revision.getWiring();
    }
    if (BundleDTO.class.equals(adapterType)) {
        // Unfortunately we need to lock here to make sure the BSN and version
        // are consistent in case of updates
        readLock();
        try {
            return (A) DTOBuilder.newBundleDTO(this);
        } finally {
            readUnlock();
        }
    }
    if (BundleStartLevelDTO.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        return (A) DTOBuilder.newBundleStartLevelDTO(this, module);
    }
    if (BundleRevisionDTO.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        return (A) DTOBuilder.newBundleRevisionDTO(module.getCurrentRevision());
    }
    if (BundleRevisionDTO[].class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        // proper locking for us.
        return (A) DTOBuilder.newArrayBundleRevisionDTO(module.getRevisions());
    }
    if (BundleWiringDTO.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        readLock();
        try {
            return (A) DTOBuilder.newBundleWiringDTO(module.getCurrentRevision());
        } finally {
            readUnlock();
        }
    }
    if (BundleWiringDTO[].class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        readLock();
        try {
            return (A) DTOBuilder.newArrayBundleWiringDTO(module.getRevisions());
        } finally {
            readUnlock();
        }
    }
    if (ServiceReferenceDTO[].class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        BundleContextImpl current = getBundleContextImpl();
        ServiceReference<?>[] references = (current == null) ? null : equinoxContainer.getServiceRegistry().getRegisteredServices(current);
        return (A) DTOBuilder.newArrayServiceReferenceDTO(references);
    }
    if (getBundleId() == 0) {
        if (Framework.class.equals(adapterType)) {
            return (A) this;
        }
        if (FrameworkStartLevel.class.equals(adapterType)) {
            return (A) module.getContainer().getFrameworkStartLevel();
        }
        if (FrameworkWiring.class.equals(adapterType)) {
            return (A) module.getContainer().getFrameworkWiring();
        }
        if (FrameworkDTO.class.equals(adapterType)) {
            BundleContextImpl current = getBundleContextImpl();
            Map<String, String> configuration = equinoxContainer.getConfiguration().getConfiguration();
            readLock();
            try {
                return (A) DTOBuilder.newFrameworkDTO(current, configuration);
            } finally {
                readUnlock();
            }
        }
        if (FrameworkStartLevelDTO.class.equals(adapterType)) {
            return (A) DTOBuilder.newFrameworkStartLevelDTO(module.getContainer().getFrameworkStartLevel());
        }
        if (FrameworkWiringDTO.class.equals(adapterType)) {
            readLock();
            try {
                Set<BundleWiring> allWirings = new HashSet<>();
                for (Module m : module.getContainer().getModules()) {
                    for (BundleRevision revision : m.getRevisions().getRevisions()) {
                        BundleWiring wiring = revision.getWiring();
                        if (wiring != null) {
                            allWirings.add(wiring);
                        }
                    }
                }
                for (ModuleRevision revision : module.getContainer().getRemovalPending()) {
                    BundleWiring wiring = revision.getWiring();
                    if (wiring != null) {
                        allWirings.add(wiring);
                    }
                }
                return (A) DTOBuilder.newFrameworkWiringDTO(allWirings);
            } finally {
                readUnlock();
            }
        }
    }
    // Equinox extras
    if (Module.class.equals(adapterType)) {
        return (A) module;
    }
    if (ProtectionDomain.class.equals(adapterType)) {
        Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
        return (A) current.getDomain();
    }
    return null;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) BundleRevisionDTO(org.osgi.framework.wiring.dto.BundleRevisionDTO) BundleWiring(org.osgi.framework.wiring.BundleWiring) ServiceReference(org.osgi.framework.ServiceReference) ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) AccessControlContext(java.security.AccessControlContext) BundleWiringDTO(org.osgi.framework.wiring.dto.BundleWiringDTO) BundleRevision(org.osgi.framework.wiring.BundleRevision) SystemModule(org.eclipse.osgi.container.SystemModule) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) HashSet(java.util.HashSet)

Example 79 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.

the class StateResolverTest method testResolveFragmentEE02.

public void testResolveFragmentEE02() throws BundleException, IOException {
    State state = buildEmptyState();
    Dictionary[] props = new Dictionary[] { new Hashtable() };
    // $NON-NLS-1$ //$NON-NLS-2$
    props[0].put("org.osgi.framework.executionenvironment", "test");
    state.setPlatformProperties(props);
    int bundleID = 0;
    Hashtable manifest = new Hashtable();
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.osgi");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
    BundleDescription a = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "c");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    manifest.put(Constants.IMPORT_PACKAGE, "d");
    manifest.put(Constants.FRAGMENT_HOST, "b");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
    BundleDescription c = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(b);
    state.addBundle(a);
    state.addBundle(c);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("A is not resolved", a.isResolved());
    // $NON-NLS-1$
    assertTrue("B is not resolved", b.isResolved());
    // $NON-NLS-1$
    assertFalse("C is resolved", c.isResolved());
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "d");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    manifest.put(Constants.EXPORT_PACKAGE, "d");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
    BundleDescription d = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(d);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("A is not resolved", a.isResolved());
    // $NON-NLS-1$
    assertTrue("B is not resolved", b.isResolved());
    // $NON-NLS-1$
    assertFalse("C is resolved", c.isResolved());
    // $NON-NLS-1$
    assertTrue("D is not resolved", d.isResolved());
    state.resolve(new BundleDescription[] { b });
    // $NON-NLS-1$
    assertTrue("A is not resolved", a.isResolved());
    // $NON-NLS-1$
    assertTrue("B is not resolved", b.isResolved());
    // $NON-NLS-1$
    assertTrue("C is not resolved", c.isResolved());
    // $NON-NLS-1$
    assertTrue("D is not resolved", d.isResolved());
    BundleWiring aWiring = a.getWiring();
    List aRequirements = a.getRequirements("osgi.ee");
    List aRequiredWires = aWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from system bundle", 1, aRequirements.size());
    assertEquals("Wrong number of wires from system bundle", 1, aRequiredWires.size());
    BundleWiring bWiring = b.getWiring();
    List bRequirements = b.getRequirements("osgi.ee");
    List bRequiredWires = bWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from fragment", 1, bRequirements.size());
    assertEquals("Wrong number of wires from fragment", 1, bRequiredWires.size());
    BundleWiring cWiring = c.getWiring();
    List cRequirements = c.getRequirements("osgi.ee");
    List cRequiredWires = cWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from c", 1, cRequirements.size());
    assertEquals("Wrong number of wires from c", 1, cRequiredWires.size());
    // $NON-NLS-1$
    File stateCache = OSGiTestsActivator.getContext().getDataFile("statecache");
    stateCache.mkdirs();
    StateObjectFactory.defaultFactory.writeState(state, stateCache);
    state = StateObjectFactory.defaultFactory.readState(stateCache);
    a = state.getBundle("org.eclipse.osgi", null);
    b = state.getBundle("b", null);
    c = state.getBundle("c", null);
    d = state.getBundle("d", null);
    aWiring = a.getWiring();
    aRequirements = a.getRequirements("osgi.ee");
    aRequiredWires = aWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from system bundle", 1, aRequirements.size());
    assertEquals("Wrong number of wires from system bundle", 1, aRequiredWires.size());
    bWiring = b.getWiring();
    bRequirements = b.getRequirements("osgi.ee");
    bRequiredWires = bWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from fragment", 1, bRequirements.size());
    assertEquals("Wrong number of wires from fragment", 1, bRequiredWires.size());
    cWiring = c.getWiring();
    cRequirements = c.getRequirements("osgi.ee");
    cRequiredWires = cWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from c", 1, cRequirements.size());
    assertEquals("Wrong number of wires from c", 1, cRequiredWires.size());
}
Also used : Dictionary(java.util.Dictionary) State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) BundleWiring(org.osgi.framework.wiring.BundleWiring) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 80 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring in project rt.equinox.framework by eclipse.

the class StateResolverTest method testBug369880.

public void testBug369880() throws BundleException {
    State state = buildEmptyState();
    Dictionary[] props = new Dictionary[] { new Hashtable() };
    // $NON-NLS-1$ //$NON-NLS-2$
    props[0].put("org.osgi.framework.executionenvironment", "test");
    state.setPlatformProperties(props);
    int bundleID = 0;
    Hashtable manifest = new Hashtable();
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.osgi");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
    BundleDescription a = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "org.eclipse.osgi; bundle-version=\"[1.0, 1.1)\"");
    manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(a);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("A is not resolved", a.isResolved());
    state.addBundle(b);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("B is not resolved", b.isResolved());
    BundleWiring aWiring = a.getWiring();
    List aRequirements = a.getRequirements("osgi.ee");
    List aRequiredWires = aWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from system bundle", 1, aRequirements.size());
    assertEquals("Wrong number of wires from system bundle", 1, aRequiredWires.size());
    BundleWiring bWiring = b.getWiring();
    List bRequirements = b.getRequirements("osgi.ee");
    List bRequiredWires = bWiring.getRequiredWires("osgi.ee");
    assertEquals("Wrong number of osgi.ee requirements from fragment", 1, bRequirements.size());
    assertEquals("Wrong number of wires from fragment", 1, bRequiredWires.size());
}
Also used : Dictionary(java.util.Dictionary) State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) BundleWiring(org.osgi.framework.wiring.BundleWiring) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

BundleWiring (org.osgi.framework.wiring.BundleWiring)110 Bundle (org.osgi.framework.Bundle)61 BundleWire (org.osgi.framework.wiring.BundleWire)39 ArrayList (java.util.ArrayList)23 BundleRevision (org.osgi.framework.wiring.BundleRevision)23 BundleCapability (org.osgi.framework.wiring.BundleCapability)19 Test (org.junit.Test)15 HashMap (java.util.HashMap)13 Hashtable (java.util.Hashtable)12 List (java.util.List)12 BundleContext (org.osgi.framework.BundleContext)12 URL (java.net.URL)10 Dictionary (java.util.Dictionary)10 HashSet (java.util.HashSet)9 LinkedHashMap (java.util.LinkedHashMap)8 Version (org.osgi.framework.Version)7 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)7 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)6 IAnswer (org.easymock.IAnswer)6 ServiceReference (org.osgi.framework.ServiceReference)6