Search in sources :

Example 6 with PackageSource

use of org.eclipse.osgi.internal.loader.sources.PackageSource in project rt.equinox.framework by eclipse.

the class BundleLoader method addExportedProvidersFor.

final void addExportedProvidersFor(String packageName, List<PackageSource> result, Collection<BundleLoader> visited) {
    if (visited.contains(this))
        return;
    visited.add(this);
    // See if we locally provide the package.
    PackageSource local = null;
    if (isExportedPackage(packageName))
        local = exportSources.getPackageSource(packageName);
    else if (isSubstitutedExport(packageName)) {
        result.add(findImportedSource(packageName, visited));
        // should not continue to required bundles in this case
        return;
    }
    // Must search required bundles that are exported first.
    for (ModuleWire bundleWire : requiredBundleWires) {
        if (local != null || BundleNamespace.VISIBILITY_REEXPORT.equals(bundleWire.getRequirement().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE))) {
            // always add required bundles first if we locally provide the package
            // This allows a bundle to provide a package from a required bundle without
            // re-exporting the whole required bundle.
            BundleLoader loader = (BundleLoader) bundleWire.getProviderWiring().getModuleLoader();
            if (loader != null) {
                loader.addExportedProvidersFor(packageName, result, visited);
            }
        }
    }
    // now add the locally provided package.
    if (local != null)
        result.add(local);
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) PackageSource(org.eclipse.osgi.internal.loader.sources.PackageSource) NullPackageSource(org.eclipse.osgi.internal.loader.sources.NullPackageSource)

Example 7 with PackageSource

use of org.eclipse.osgi.internal.loader.sources.PackageSource in project rt.equinox.framework by eclipse.

the class BundleLoader method findResource.

/**
 * Finds the resource for a bundle.  This method is used for delegation by the bundle's classloader.
 */
public URL findResource(String name) {
    if (debug.DEBUG_LOADER)
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Debug.println("BundleLoader[" + this + "].findResource(" + name + ")");
    if ((name.length() > 1) && (name.charAt(0) == '/'))
        /* if name has a leading slash */
        name = name.substring(1);
    /* remove leading slash before search */
    String pkgName = getResourcePackageName(name);
    boolean bootDelegation = false;
    // First check the parent classloader for system resources, if it is a java resource.
    if (parent != null) {
        if (pkgName.startsWith(JAVA_PACKAGE))
            // we never delegate java resource requests past the parent
            return parent.getResource(name);
        else if (container.isBootDelegationPackage(pkgName)) {
            // 2) if part of the bootdelegation list then delegate to parent and continue of failure
            URL result = parent.getResource(name);
            if (result != null)
                return result;
            bootDelegation = true;
        }
    }
    URL result = null;
    try {
        result = (URL) searchHooks(name, PRE_RESOURCE);
    } catch (FileNotFoundException e) {
        return null;
    } catch (ClassNotFoundException e) {
    // will not happen
    }
    if (result != null)
        return result;
    // 3) search the imported packages
    PackageSource source = findImportedSource(pkgName, null);
    if (source != null) {
        if (debug.DEBUG_LOADER) {
            // $NON-NLS-1$ //$NON-NLS-2$
            Debug.println("BundleLoader[" + this + "] loading from import package: " + source);
        }
        // 3) found import source terminate search at the source
        return source.getResource(name);
    }
    // 4) search the required bundles
    source = findRequiredSource(pkgName, null);
    if (source != null) {
        if (debug.DEBUG_LOADER) {
            // $NON-NLS-1$ //$NON-NLS-2$
            Debug.println("BundleLoader[" + this + "] loading from required bundle package: " + source);
        }
        // 4) attempt to load from source but continue on failure
        result = source.getResource(name);
    }
    // 5) search the local bundle
    if (result == null)
        result = findLocalResource(name);
    if (result != null)
        return result;
    // 6) attempt to find a dynamic import source; only do this if a required source was not found
    if (source == null) {
        source = findDynamicSource(pkgName);
        if (source != null)
            // must return the result of the dynamic import and do not continue
            return source.getResource(name);
    }
    if (result == null)
        try {
            result = (URL) searchHooks(name, POST_RESOURCE);
        } catch (FileNotFoundException e) {
            return null;
        } catch (ClassNotFoundException e) {
        // will not happen
        }
    // do buddy policy loading
    if (result == null && policy != null)
        result = policy.doBuddyResourceLoading(name);
    if (result != null)
        return result;
    // or last resort; do class context trick to work around VM bugs
    if (parent != null && !bootDelegation && (container.getConfiguration().compatibilityBootDelegation || isRequestFromVM()))
        // we don't need to continue if the resource is not found here
        return parent.getResource(name);
    return result;
}
Also used : PackageSource(org.eclipse.osgi.internal.loader.sources.PackageSource) NullPackageSource(org.eclipse.osgi.internal.loader.sources.NullPackageSource) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL)

Example 8 with PackageSource

use of org.eclipse.osgi.internal.loader.sources.PackageSource in project rt.equinox.framework by eclipse.

the class BundleLoader method getPackageSource.

/*
	 * Gets the package source for the pkgName.  This will include the local package source
	 * if the bundle exports the package.  This is used to compare the PackageSource of a 
	 * package from two different bundles.
	 */
public final PackageSource getPackageSource(String pkgName) {
    PackageSource result = findSource(pkgName);
    if (!isExportedPackage(pkgName))
        return result;
    // if the package is exported then we need to get the local source
    PackageSource localSource = exportSources.getPackageSource(pkgName);
    if (result == null)
        return localSource;
    if (localSource == null)
        return result;
    return createMultiSource(pkgName, new PackageSource[] { result, localSource });
}
Also used : PackageSource(org.eclipse.osgi.internal.loader.sources.PackageSource) NullPackageSource(org.eclipse.osgi.internal.loader.sources.NullPackageSource)

Example 9 with PackageSource

use of org.eclipse.osgi.internal.loader.sources.PackageSource in project rt.equinox.framework by eclipse.

the class BundleLoader method createExportPackageSource.

final PackageSource createExportPackageSource(ModuleWire importWire, Collection<BundleLoader> visited) {
    String name = (String) importWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
    BundleLoader providerLoader = (BundleLoader) importWire.getProviderWiring().getModuleLoader();
    if (providerLoader == null) {
        return createMultiSource(name, new PackageSource[0]);
    }
    PackageSource requiredSource = providerLoader.findRequiredSource(name, visited);
    PackageSource exportSource = providerLoader.exportSources.createPackageSource(importWire.getCapability(), false);
    if (requiredSource == null)
        return exportSource;
    return createMultiSource(name, new PackageSource[] { requiredSource, exportSource });
}
Also used : PackageSource(org.eclipse.osgi.internal.loader.sources.PackageSource) NullPackageSource(org.eclipse.osgi.internal.loader.sources.NullPackageSource)

Example 10 with PackageSource

use of org.eclipse.osgi.internal.loader.sources.PackageSource in project rt.equinox.framework by eclipse.

the class BundleLoader method findResources.

/**
 * Finds the resources for a bundle.  This  method is used for delegation by the bundle's classloader.
 */
public Enumeration<URL> findResources(String name) throws IOException {
    if (debug.DEBUG_LOADER)
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Debug.println("BundleLoader[" + this + "].findResources(" + name + ")");
    // do not delegate to parent because ClassLoader#getResources already did and it is final!!
    if ((name.length() > 1) && (name.charAt(0) == '/'))
        /* if name has a leading slash */
        name = name.substring(1);
    /* remove leading slash before search */
    String pkgName = getResourcePackageName(name);
    Enumeration<URL> result = emptyEnumeration();
    boolean bootDelegation = false;
    // First check the parent classloader for system resources, if it is a java resource.
    if (parent != null) {
        if (pkgName.startsWith(JAVA_PACKAGE))
            // we never delegate java resource requests past the parent
            return parent.getResources(name);
        else if (container.isBootDelegationPackage(pkgName)) {
            // 2) if part of the bootdelegation list then delegate to parent and continue
            result = compoundEnumerations(result, parent.getResources(name));
            bootDelegation = true;
        }
    }
    try {
        Enumeration<URL> hookResources = searchHooks(name, PRE_RESOURCES);
        if (hookResources != null) {
            return compoundEnumerations(result, hookResources);
        }
    } catch (ClassNotFoundException e) {
    // will not happen
    } catch (FileNotFoundException e) {
        return result;
    }
    // 3) search the imported packages
    PackageSource source = findImportedSource(pkgName, null);
    if (source != null) {
        if (debug.DEBUG_LOADER) {
            // $NON-NLS-1$ //$NON-NLS-2$
            Debug.println("BundleLoader[" + this + "] loading from import package: " + source);
        }
        // 3) found import source terminate search at the source
        return compoundEnumerations(result, source.getResources(name));
    }
    // 4) search the required bundles
    source = findRequiredSource(pkgName, null);
    if (source != null) {
        if (debug.DEBUG_LOADER) {
            // $NON-NLS-1$ //$NON-NLS-2$
            Debug.println("BundleLoader[" + this + "] loading from required bundle package: " + source);
        }
        // 4) attempt to load from source but continue on failure
        result = compoundEnumerations(result, source.getResources(name));
    }
    // 5) search the local bundle
    // compound the required source results with the local ones
    Enumeration<URL> localResults = findLocalResources(name);
    result = compoundEnumerations(result, localResults);
    // 6) attempt to find a dynamic import source; only do this if a required source was not found
    if (source == null && !result.hasMoreElements()) {
        source = findDynamicSource(pkgName);
        if (source != null)
            return compoundEnumerations(result, source.getResources(name));
    }
    if (!result.hasMoreElements())
        try {
            Enumeration<URL> hookResources = searchHooks(name, POST_RESOURCES);
            result = compoundEnumerations(result, hookResources);
        } catch (ClassNotFoundException e) {
        // will not happen
        } catch (FileNotFoundException e) {
            return null;
        }
    if (policy != null) {
        Enumeration<URL> buddyResult = policy.doBuddyResourcesLoading(name);
        result = compoundEnumerations(result, buddyResult);
    }
    // or last resort; do class context trick to work around VM bugs
    if (!result.hasMoreElements()) {
        if (parent != null && !bootDelegation && (container.getConfiguration().compatibilityBootDelegation || isRequestFromVM()))
            // we don't need to continue if the resource is not found here
            return parent.getResources(name);
    }
    return result;
}
Also used : Enumeration(java.util.Enumeration) PackageSource(org.eclipse.osgi.internal.loader.sources.PackageSource) NullPackageSource(org.eclipse.osgi.internal.loader.sources.NullPackageSource) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL)

Aggregations

NullPackageSource (org.eclipse.osgi.internal.loader.sources.NullPackageSource)10 PackageSource (org.eclipse.osgi.internal.loader.sources.PackageSource)10 ModuleWire (org.eclipse.osgi.container.ModuleWire)5 FileNotFoundException (java.io.FileNotFoundException)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)1 KeyedElement (org.eclipse.osgi.framework.util.KeyedElement)1 KeyedHashSet (org.eclipse.osgi.framework.util.KeyedHashSet)1