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;
}
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;
}
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;
}
});
}
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;
}
Aggregations