Search in sources :

Example 6 with BundleLoader

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

the class EquinoxBundle method getModuleClassLoader.

private ModuleClassLoader getModuleClassLoader(boolean logResolveError) {
    ResolutionReport report = resolve();
    if (logResolveError && !Module.RESOLVED_SET.contains(module.getState())) {
        String reportMessage = report.getResolutionReportMessage(module.getCurrentRevision());
        equinoxContainer.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, this, new BundleException(reportMessage, BundleException.RESOLVE_ERROR));
    }
    return AccessController.doPrivileged(new PrivilegedAction<ModuleClassLoader>() {

        @Override
        public ModuleClassLoader run() {
            ModuleWiring wiring = getModule().getCurrentRevision().getWiring();
            if (wiring != null) {
                ModuleLoader moduleLoader = wiring.getModuleLoader();
                if (moduleLoader instanceof BundleLoader) {
                    return ((BundleLoader) moduleLoader).getModuleClassLoader();
                }
            }
            return null;
        }
    });
}
Also used : ModuleLoader(org.eclipse.osgi.container.ModuleLoader) ModuleClassLoader(org.eclipse.osgi.internal.loader.ModuleClassLoader) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) BundleException(org.osgi.framework.BundleException) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Example 7 with BundleLoader

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

the class WeavingHookConfigurator method processClass.

public byte[] processClass(String name, byte[] classbytes, ClasspathEntry classpathEntry, BundleEntry entry, ClasspathManager manager) {
    ServiceRegistry registry = getRegistry();
    if (registry == null)
        // no registry somehow we are loading classes before the registry has been created
        return null;
    ModuleClassLoader classLoader = manager.getClassLoader();
    BundleLoader loader = classLoader.getBundleLoader();
    // create a woven class object and add it to the thread local stack
    WovenClassImpl wovenClass = new WovenClassImpl(name, classbytes, entry, classpathEntry, loader, container, blackList);
    WovenClassContext context = wovenClassContext.get();
    if (context == null) {
        context = new WovenClassContext();
        wovenClassContext.set(context);
    }
    context.wovenClassStack.add(wovenClass);
    // will not have been woven at all.
    if (!context.processClassNameStack.contains(name)) {
        context.processClassNameStack.add(name);
        // call the weaving hooks
        try {
            return wovenClass.callHooks();
        } catch (Throwable t) {
            ServiceRegistration<?> errorHook = wovenClass.getErrorHook();
            Bundle errorBundle = errorHook != null ? errorHook.getReference().getBundle() : manager.getGeneration().getRevision().getBundle();
            container.getEventPublisher().publishFrameworkEvent(FrameworkEvent.ERROR, errorBundle, t);
            // fail hard with a class loading error
            // $NON-NLS-1$
            ClassFormatError error = new ClassFormatError("Unexpected error from weaving hook.");
            error.initCause(t);
            throw error;
        } finally {
            context.processClassNameStack.remove(name);
        }
    }
    return null;
}
Also used : ModuleClassLoader(org.eclipse.osgi.internal.loader.ModuleClassLoader) ServiceRegistry(org.eclipse.osgi.internal.serviceregistry.ServiceRegistry) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Example 8 with BundleLoader

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

the class RegisteredPolicy method loadResources.

public Enumeration<URL> loadResources(String name) {
    if (allDependents == null)
        return null;
    Enumeration<URL> results = null;
    int size = allDependents.size();
    for (int i = 0; i < size; i++) {
        try {
            ModuleWiring searchWiring = allDependents.get(i);
            BundleLoader searchLoader = (BundleLoader) searchWiring.getModuleLoader();
            if (searchLoader != null) {
                results = BundleLoader.compoundEnumerations(results, searchLoader.findResources(name));
            }
        } catch (IOException e) {
        // Ignore and keep looking
        }
    }
    return results;
}
Also used : ModuleWiring(org.eclipse.osgi.container.ModuleWiring) IOException(java.io.IOException) URL(java.net.URL) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Example 9 with BundleLoader

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

the class RegisteredPolicy method loadClass.

public Class<?> loadClass(String name) {
    if (allDependents == null)
        return null;
    Class<?> result = null;
    int size = allDependents.size();
    for (int i = 0; i < size && result == null; i++) {
        ModuleWiring searchWiring = allDependents.get(i);
        BundleLoader searchLoader = (BundleLoader) searchWiring.getModuleLoader();
        if (searchLoader != null) {
            try {
                result = searchLoader.findClass(name);
            } catch (ClassNotFoundException e) {
                // Nothing to do, just keep looking
                continue;
            }
        }
    }
    return result;
}
Also used : ModuleWiring(org.eclipse.osgi.container.ModuleWiring) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Example 10 with BundleLoader

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

the class RegisteredPolicy method loadResource.

public URL loadResource(String name) {
    if (allDependents == null)
        return null;
    URL result = null;
    int size = allDependents.size();
    for (int i = 0; i < size && result == null; i++) {
        ModuleWiring searchWiring = allDependents.get(i);
        BundleLoader searchLoader = (BundleLoader) searchWiring.getModuleLoader();
        if (searchLoader != null) {
            result = searchLoader.findResource(name);
        }
    }
    return result;
}
Also used : ModuleWiring(org.eclipse.osgi.container.ModuleWiring) URL(java.net.URL) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Aggregations

BundleLoader (org.eclipse.osgi.internal.loader.BundleLoader)12 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)8 URL (java.net.URL)4 SystemBundleLoader (org.eclipse.osgi.internal.loader.SystemBundleLoader)3 IOException (java.io.IOException)2 EquinoxBundle (org.eclipse.osgi.internal.framework.EquinoxBundle)2 ModuleClassLoader (org.eclipse.osgi.internal.loader.ModuleClassLoader)2 Bundle (org.osgi.framework.Bundle)2 ProtectionDomain (java.security.ProtectionDomain)1 Module (org.eclipse.osgi.container.Module)1 ModuleLoader (org.eclipse.osgi.container.ModuleLoader)1 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)1 SystemModule (org.eclipse.osgi.container.SystemModule)1 BundlePermissions (org.eclipse.osgi.internal.permadmin.BundlePermissions)1 ServiceRegistry (org.eclipse.osgi.internal.serviceregistry.ServiceRegistry)1 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)1 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)1 BundleException (org.osgi.framework.BundleException)1 ServiceFactory (org.osgi.framework.ServiceFactory)1 Capability (org.osgi.resource.Capability)1