Search in sources :

Example 6 with ModuleClassLoader

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

the class ContextFinder method basicFindClassLoaders.

// Return a list of all classloaders on the stack that are neither the
// ContextFinder classloader nor the boot classloader.  The last classloader
// in the list is either a bundle classloader or the framework's classloader
// We assume that the bootclassloader never uses the context classloader to find classes in itself.
List<ClassLoader> basicFindClassLoaders() {
    Class<?>[] stack = contextFinder.getClassContext();
    List<ClassLoader> result = new ArrayList<>(1);
    ClassLoader previousLoader = null;
    for (int i = 1; i < stack.length; i++) {
        ClassLoader tmp = stack[i].getClassLoader();
        if (stack[i] != THIS && tmp != null && tmp != this) {
            if (checkClassLoader(tmp)) {
                if (previousLoader != tmp) {
                    result.add(tmp);
                    previousLoader = tmp;
                }
            }
            // stop at the framework classloader or the first bundle classloader
            if (tmp == finderClassLoader || tmp instanceof ModuleClassLoader)
                break;
        }
    }
    return result;
}
Also used : ModuleClassLoader(org.eclipse.osgi.internal.loader.ModuleClassLoader) ModuleClassLoader(org.eclipse.osgi.internal.loader.ModuleClassLoader)

Example 7 with ModuleClassLoader

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

the class EquinoxBundle method getResources.

@Override
public Enumeration<URL> getResources(String name) throws IOException {
    try {
        equinoxContainer.checkAdminPermission(this, AdminPermission.RESOURCE);
    } catch (SecurityException e) {
        return null;
    }
    checkValid();
    if (isFragment()) {
        return null;
    }
    ModuleClassLoader classLoader = getModuleClassLoader(false);
    Enumeration<URL> result = null;
    if (classLoader != null) {
        result = classLoader.getResources(name);
    } else {
        result = new ClasspathManager((Generation) module.getCurrentRevision().getRevisionInfo(), null).findLocalResources(name);
    }
    return result != null && result.hasMoreElements() ? result : null;
}
Also used : ClasspathManager(org.eclipse.osgi.internal.loader.classpath.ClasspathManager) ModuleClassLoader(org.eclipse.osgi.internal.loader.ModuleClassLoader) URL(java.net.URL)

Example 8 with ModuleClassLoader

use of org.eclipse.osgi.internal.loader.ModuleClassLoader 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 9 with ModuleClassLoader

use of org.eclipse.osgi.internal.loader.ModuleClassLoader 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)

Aggregations

ModuleClassLoader (org.eclipse.osgi.internal.loader.ModuleClassLoader)9 URL (java.net.URL)4 File (java.io.File)3 ClasspathManager (org.eclipse.osgi.internal.loader.classpath.ClasspathManager)3 URLClassLoader (java.net.URLClassLoader)2 ArrayList (java.util.ArrayList)2 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)2 BundleLoader (org.eclipse.osgi.internal.loader.BundleLoader)2 BundleFile (org.eclipse.osgi.storage.bundlefile.BundleFile)2 Bundle (org.osgi.framework.Bundle)2 BundleWiring (org.osgi.framework.wiring.BundleWiring)2 BufferedWriter (java.io.BufferedWriter)1 Closeable (java.io.Closeable)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1