Search in sources :

Example 26 with ExportPackageDescription

use of org.eclipse.osgi.service.resolver.ExportPackageDescription in project rt.equinox.framework by eclipse.

the class TestRFC79_006 method checkWiringState_1.

// end of method
public void checkWiringState_1() {
    ExportPackageDescription[] exports = bundle_1.getResolvedImports();
    assertNotNull("export array is unexpectedly null", exports);
    assertTrue("export array is unexpectedly empty", exports.length > 0);
    for (int i = 0; i < exports.length; i++) {
        ExportPackageDescription exp = exports[i];
        String exportPackageName = exp.getName();
        assertNotNull("package name is null", exportPackageName);
        if (exportPackageName.equals("org.xml.sax")) {
            assertNotNull("Package [org.xml.sax] is not wired when it should be ", exp.getExporter());
            assertEquals("Package [org.xml.sax] is wired incorrectly ", exp.getExporter(), bundle_3);
        } else if (exportPackageName.equals("org.w3c.dom")) {
            assertNotNull("Package [org.w3c.dom] is not wired when it should be ", exp.getExporter());
            assertEquals("Package [org.w3c.dom] is wired incorrectly ", exp.getExporter(), bundle_4);
        } else if (exportPackageName.equals("javax.xml.parsers")) {
            assertNotNull("Package [javax] is not wired when it should be ", exp.getExporter());
            assertEquals("Package [javax] is wired incorrectly ", exp.getExporter(), bundle_6);
        }
    }
// end for
}
Also used : ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription)

Example 27 with ExportPackageDescription

use of org.eclipse.osgi.service.resolver.ExportPackageDescription in project rt.equinox.framework by eclipse.

the class TestRFC79_006 method checkWiringState_6.

// end method
public void checkWiringState_6() {
    ExportPackageDescription[] exports = bundle_6.getResolvedImports();
    assertNotNull("export array is unexpectedly null", exports);
    assertTrue("export array is unexpectedly empty", exports.length > 0);
    for (int i = 0; i < exports.length; i++) {
        ExportPackageDescription exp = exports[i];
        String exportPackageName = exp.getName();
        assertNotNull("package name is null", exportPackageName);
        if (exportPackageName.equals("org.w3c.dom")) {
            assertNotNull("Package [org.w3c.dom] is not wired when it should be ", exp.getExporter());
            assertEquals("Package [org.w3c.dom] is wired incorrectly ", exp.getExporter(), bundle_4);
        } else if (exportPackageName.equals("org.xml.sax")) {
            assertNotNull("Package [org.xml.sax] is not wired when it should be ", exp.getExporter());
            assertEquals("Package [org.xml.sax] is wired incorrectly ", exp.getExporter(), bundle_3);
        }
    }
// end for
}
Also used : ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription)

Example 28 with ExportPackageDescription

use of org.eclipse.osgi.service.resolver.ExportPackageDescription in project rt.equinox.framework by eclipse.

the class ResolverBundle method initialize.

void initialize(boolean useSelectedExports) {
    if (getBundleDescription().getHost() != null) {
        host = new BundleConstraint(this, getBundleDescription().getHost());
        exports = new ResolverExport[0];
        imports = new ResolverImport[0];
        requires = new BundleConstraint[0];
        GenericSpecification[] requirements = getBundleDescription().getGenericRequires();
        List<GenericConstraint> constraints = new ArrayList<>();
        for (GenericSpecification requirement : requirements) {
            if (StateImpl.OSGI_EE_NAMESPACE.equals(requirement.getType())) {
                constraints.add(new GenericConstraint(this, requirement, resolver.isDevelopmentMode()));
            }
        }
        genericReqiures = constraints.toArray(new GenericConstraint[constraints.size()]);
        GenericDescription[] capabilities = getBundleDescription().getGenericCapabilities();
        GenericCapability identity = null;
        for (GenericDescription capability : capabilities) {
            if (IdentityNamespace.IDENTITY_NAMESPACE.equals(capability.getType())) {
                identity = new GenericCapability(this, capability, resolver.isDevelopmentMode());
                break;
            }
        }
        genericCapabilities = identity == null ? new GenericCapability[0] : new GenericCapability[] { identity };
        return;
    }
    ImportPackageSpecification[] actualImports = getBundleDescription().getImportPackages();
    // Reorder imports so that optionals are at the end so that we wire statics before optionals
    List<ResolverImport> importList = new ArrayList<>(actualImports.length);
    for (int i = actualImports.length - 1; i >= 0; i--) if (ImportPackageSpecification.RESOLUTION_OPTIONAL.equals(actualImports[i].getDirective(Constants.RESOLUTION_DIRECTIVE)))
        importList.add(new ResolverImport(this, actualImports[i]));
    else
        importList.add(0, new ResolverImport(this, actualImports[i]));
    imports = importList.toArray(new ResolverImport[importList.size()]);
    ExportPackageDescription[] actualExports = useSelectedExports ? getBundleDescription().getSelectedExports() : getBundleDescription().getExportPackages();
    exports = new ResolverExport[actualExports.length];
    for (int i = 0; i < actualExports.length; i++) exports[i] = new ResolverExport(this, actualExports[i]);
    BundleSpecification[] actualRequires = getBundleDescription().getRequiredBundles();
    requires = new BundleConstraint[actualRequires.length];
    for (int i = 0; i < requires.length; i++) requires[i] = new BundleConstraint(this, actualRequires[i]);
    GenericSpecification[] actualGenericRequires = getBundleDescription().getGenericRequires();
    genericReqiures = new GenericConstraint[actualGenericRequires.length];
    for (int i = 0; i < genericReqiures.length; i++) {
        genericReqiures[i] = new GenericConstraint(this, actualGenericRequires[i], resolver.isDevelopmentMode());
    }
    GenericDescription[] actualCapabilities = useSelectedExports ? getBundleDescription().getSelectedGenericCapabilities() : getBundleDescription().getGenericCapabilities();
    genericCapabilities = new GenericCapability[actualCapabilities.length];
    for (int i = 0; i < genericCapabilities.length; i++) {
        genericCapabilities[i] = new GenericCapability(this, actualCapabilities[i], resolver.isDevelopmentMode());
    }
    fragments = null;
    fragmentExports = null;
    fragmentImports = null;
    fragmentRequires = null;
    fragmentGenericCapabilities = null;
    fragmentGenericRequires = null;
}
Also used : ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription) ArrayList(java.util.ArrayList) GenericDescription(org.eclipse.osgi.service.resolver.GenericDescription) BundleSpecification(org.eclipse.osgi.service.resolver.BundleSpecification) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint) ImportPackageSpecification(org.eclipse.osgi.service.resolver.ImportPackageSpecification) GenericSpecification(org.eclipse.osgi.service.resolver.GenericSpecification)

Example 29 with ExportPackageDescription

use of org.eclipse.osgi.service.resolver.ExportPackageDescription in project rt.equinox.framework by eclipse.

the class ResolverImpl method getExportsWiredTo.

private static ExportPackageDescription[] getExportsWiredTo(ResolverBundle rb, Map<String, List<StateWire>> stateWires) {
    // Gather exports that have been wired to
    ResolverImport[] imports = rb.getImportPackages();
    List<ExportPackageDescription> exportsWiredTo = new ArrayList<>(imports.length);
    List<StateWire> importWires = new ArrayList<>(imports.length);
    for (int i = 0; i < imports.length; i++) if (imports[i].getSelectedSupplier() != null) {
        ExportPackageDescription supplier = (ExportPackageDescription) imports[i].getSelectedSupplier().getBaseDescription();
        exportsWiredTo.add(supplier);
        StateWire wire = newStateWire(rb.getBundleDescription(), imports[i].getVersionConstraint(), supplier.getExporter(), supplier);
        importWires.add(wire);
    }
    if (stateWires != null && !importWires.isEmpty())
        stateWires.put(BundleRevision.PACKAGE_NAMESPACE, importWires);
    return exportsWiredTo.toArray(new ExportPackageDescription[exportsWiredTo.size()]);
}
Also used : ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription) ArrayList(java.util.ArrayList) StateWire(org.eclipse.osgi.service.resolver.StateWire) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint)

Example 30 with ExportPackageDescription

use of org.eclipse.osgi.service.resolver.ExportPackageDescription in project rt.equinox.framework by eclipse.

the class ResolverImpl method resolveDynamicImport.

private ExportPackageDescription resolveDynamicImport(ResolverImport dynamicImport, String requestedPackage) {
    String importName = dynamicImport.getName();
    // If the import uses a wildcard, then temporarily replace this with the requested package
    if (// $NON-NLS-1$
    importName.equals("*") || (importName.endsWith(".*") && requestedPackage.startsWith(importName.substring(0, importName.length() - 1)))) {
        // $NON-NLS-1$
        dynamicImport.setName(requestedPackage);
    }
    try {
        // Resolve the import
        if (!requestedPackage.equals(dynamicImport.getName()))
            return null;
        if (resolveImport(dynamicImport, new ArrayList<ResolverBundle>())) {
            // populate the grouping checker with current imports
            groupingChecker.populateRoots(dynamicImport.getBundle());
            while (dynamicImport.getSelectedSupplier() != null) {
                if (groupingChecker.isDynamicConsistent(dynamicImport.getBundle(), (ResolverExport) dynamicImport.getSelectedSupplier()) != null) {
                    // not consistent; try the next
                    dynamicImport.selectNextSupplier();
                } else {
                    // If the import resolved then return it's matching export
                    if (DEBUG_IMPORTS)
                        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                        ResolverImpl.log("Resolved dynamic import: " + dynamicImport.getBundle() + ":" + dynamicImport.getName() + " -> " + ((ResolverExport) dynamicImport.getSelectedSupplier()).getExporter() + ":" + requestedPackage);
                    // now that we have an export to wire to; populate the roots for that package for the bundle
                    ResolverExport export = (ResolverExport) dynamicImport.getSelectedSupplier();
                    groupingChecker.populateRoots(dynamicImport.getBundle(), export);
                    ExportPackageDescription supplier = export.getExportPackageDescription();
                    if (supplier != null)
                        addStateWire(dynamicImport.getBundleDescription(), dynamicImport.getVersionConstraint(), supplier.getExporter(), supplier);
                    return supplier;
                }
            }
            dynamicImport.clearPossibleSuppliers();
        }
    } finally {
        // exported packages can be found for it
        if (// $NON-NLS-1$
        importName.endsWith("*"))
            dynamicImport.clearPossibleSuppliers();
        // Reset the import package name
        dynamicImport.setName(null);
    }
    return null;
}
Also used : ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription)

Aggregations

ExportPackageDescription (org.eclipse.osgi.service.resolver.ExportPackageDescription)61 State (org.eclipse.osgi.service.resolver.State)22 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)21 Hashtable (java.util.Hashtable)15 ArrayList (java.util.ArrayList)6 StateObjectFactory (org.eclipse.osgi.service.resolver.StateObjectFactory)6 VersionConstraint (org.eclipse.osgi.service.resolver.VersionConstraint)5 BundleSpecification (org.eclipse.osgi.service.resolver.BundleSpecification)4 ImportPackageSpecification (org.eclipse.osgi.service.resolver.ImportPackageSpecification)4 GenericDescription (org.eclipse.osgi.service.resolver.GenericDescription)3 ExportPackageDescriptionImpl (org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl)2 BaseDescription (org.eclipse.osgi.service.resolver.BaseDescription)2 GenericSpecification (org.eclipse.osgi.service.resolver.GenericSpecification)2 StateWire (org.eclipse.osgi.service.resolver.StateWire)2 AccessRule (org.eclipse.tycho.classpath.ClasspathEntry.AccessRule)2 DefaultAccessRule (org.eclipse.tycho.core.osgitools.DefaultClasspathEntry.DefaultAccessRule)2 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1 List (java.util.List)1 GenericDescriptionImpl (org.eclipse.osgi.internal.resolver.GenericDescriptionImpl)1