Search in sources :

Example 1 with ClassLoaderHook

use of org.eclipse.osgi.internal.hookregistry.ClassLoaderHook in project rt.equinox.framework by eclipse.

the class BundleLoader method searchHooks.

@SuppressWarnings("unchecked")
private <E> E searchHooks(String name, int type) throws ClassNotFoundException, FileNotFoundException {
    List<ClassLoaderHook> loaderHooks = container.getConfiguration().getHookRegistry().getClassLoaderHooks();
    if (loaderHooks == null)
        return null;
    E result = null;
    for (ClassLoaderHook hook : loaderHooks) {
        switch(type) {
            case PRE_CLASS:
                result = (E) hook.preFindClass(name, getModuleClassLoader());
                break;
            case POST_CLASS:
                result = (E) hook.postFindClass(name, getModuleClassLoader());
                break;
            case PRE_RESOURCE:
                result = (E) hook.preFindResource(name, getModuleClassLoader());
                break;
            case POST_RESOURCE:
                result = (E) hook.postFindResource(name, getModuleClassLoader());
                break;
            case PRE_RESOURCES:
                result = (E) hook.preFindResources(name, getModuleClassLoader());
                break;
            case POST_RESOURCES:
                result = (E) hook.postFindResources(name, getModuleClassLoader());
                break;
        }
        if (result != null) {
            return result;
        }
    }
    return result;
}
Also used : ClassLoaderHook(org.eclipse.osgi.internal.hookregistry.ClassLoaderHook)

Example 2 with ClassLoaderHook

use of org.eclipse.osgi.internal.hookregistry.ClassLoaderHook in project rt.equinox.framework by eclipse.

the class NativeCodeFinder method findLibrary0.

private String findLibrary0(String libname) {
    String path = null;
    List<ClassLoaderHook> hooks = generation.getBundleInfo().getStorage().getConfiguration().getHookRegistry().getClassLoaderHooks();
    for (ClassLoaderHook hook : hooks) {
        path = hook.findLocalLibrary(generation, libname);
        if (path != null) {
            return path;
        }
    }
    String mappedName = System.mapLibraryName(libname);
    String[] altMappedNames = mapLibraryNames(mappedName);
    // first check Bundle-NativeCode header
    path = findBundleNativeCode(libname, mappedName, altMappedNames);
    // next check eclipse specific support
    return path != null ? path : findEclipseNativeCode(libname, mappedName, altMappedNames);
}
Also used : ClassLoaderHook(org.eclipse.osgi.internal.hookregistry.ClassLoaderHook)

Example 3 with ClassLoaderHook

use of org.eclipse.osgi.internal.hookregistry.ClassLoaderHook in project rt.equinox.framework by eclipse.

the class ClasspathManager method findLibrary0.

private String findLibrary0(String libname) {
    List<ClassLoaderHook> hooks = hookRegistry.getClassLoaderHooks();
    String result = null;
    for (ClassLoaderHook hook : hooks) {
        try {
            result = hook.preFindLibrary(libname, classloader);
            if (result != null) {
                return result;
            }
        } catch (FileNotFoundException e) {
            return null;
        }
    }
    result = generation.findLibrary(libname);
    if (result != null) {
        return result;
    }
    // look in fragment generations
    FragmentClasspath[] currentFragments = getFragmentClasspaths();
    for (FragmentClasspath fragment : currentFragments) {
        result = fragment.getGeneration().findLibrary(libname);
        if (result != null) {
            return result;
        }
    }
    for (ClassLoaderHook hook : hooks) {
        result = hook.postFindLibrary(libname, classloader);
        if (result != null) {
            return result;
        }
    }
    return result;
}
Also used : ClassLoaderHook(org.eclipse.osgi.internal.hookregistry.ClassLoaderHook) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with ClassLoaderHook

use of org.eclipse.osgi.internal.hookregistry.ClassLoaderHook in project rt.equinox.framework by eclipse.

the class ClasspathManager method findClassPathEntry.

/**
 * Finds all the ClasspathEntry objects for the requested classpath.  This method will first call all
 * the configured class loading hooks {@link ClassLoaderHook#addClassPathEntry(ArrayList, String, ClasspathManager, Generation)}
 * methods.  This allows class loading hooks to add additional ClasspathEntry objects to the result for the
 * requested classpath.  Then the local host classpath entries and attached fragment classpath entries are
 * searched.
 * @param result a list of ClasspathEntry objects.  This list is used to add new ClasspathEntry objects to.
 * @param cp the requested classpath.
 * @param hostloader the host classpath manager for the classpath
 * @param sourceGeneration the source generation to search for the classpath
 */
private void findClassPathEntry(ArrayList<ClasspathEntry> result, String cp, ClasspathManager hostloader, Generation sourceGeneration) {
    List<ClassLoaderHook> loaderHooks = hookRegistry.getClassLoaderHooks();
    boolean hookAdded = false;
    for (ClassLoaderHook hook : loaderHooks) {
        hookAdded |= hook.addClassPathEntry(result, cp, hostloader, sourceGeneration);
    }
    if (!addClassPathEntry(result, cp, hostloader, sourceGeneration) && !hookAdded) {
        BundleException be = new BundleException(NLS.bind(Msg.BUNDLE_CLASSPATH_ENTRY_NOT_FOUND_EXCEPTION, cp, sourceGeneration.getRevision().toString()), BundleException.MANIFEST_ERROR);
        sourceGeneration.getBundleInfo().getStorage().getAdaptor().publishContainerEvent(ContainerEvent.INFO, sourceGeneration.getRevision().getRevisions().getModule(), be);
    }
}
Also used : ClassLoaderHook(org.eclipse.osgi.internal.hookregistry.ClassLoaderHook) BundleException(org.osgi.framework.BundleException)

Example 5 with ClassLoaderHook

use of org.eclipse.osgi.internal.hookregistry.ClassLoaderHook in project rt.equinox.framework by eclipse.

the class WovenClassImpl method callHooks.

byte[] callHooks() throws Throwable {
    SecurityManager sm = System.getSecurityManager();
    byte[] wovenBytes = null;
    List<String> newImports = null;
    boolean rejected = false;
    try {
        if (sm == null) {
            registry.notifyHooksPrivileged(this);
        } else {
            try {
                AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {

                    public Void run() {
                        registry.notifyHooksPrivileged(WovenClassImpl.this);
                        return null;
                    }
                });
            } catch (PrivilegedActionException e) {
                throw (RuntimeException) e.getException();
            }
        }
    } finally {
        if ((hookFlags & FLAG_HOOKCALLED) != 0) {
            for (ClassLoaderHook classLoaderHook : container.getConfiguration().getHookRegistry().getClassLoaderHooks()) {
                rejected |= classLoaderHook.rejectTransformation(className, resultBytes, classpathEntry, entry, loader.getModuleClassLoader().getClasspathManager());
            }
            if (!rejected) {
                wovenBytes = resultBytes;
                newImports = dynamicImports;
            }
            setHooksComplete();
            // Make sure setHooksComplete() has been called. The woven class
            // must be immutable in TRANSFORMED or TRANSFORMING_FAILED.
            // If error is not null, a weaving hook threw an exception.
            setState(error == null ? TRANSFORMED : TRANSFORMING_FAILED);
            // only notify listeners if the transformation was not rejected
            if (!rejected) {
                notifyWovenClassListeners();
            }
        }
    }
    if (error != null)
        throw error;
    if (newImports != null) {
        // add any new dynamic imports
        for (String newImport : newImports) {
            try {
                ManifestElement[] importElements = ManifestElement.parseHeader(Constants.IMPORT_PACKAGE, newImport);
                // Grant implied import package permissions for all dynamic
                // import packages to the woven bundle.
                addImpliedImportPackagePermissions(importElements);
                loader.addDynamicImportPackage(importElements);
            } catch (BundleException e) {
            // should not have happened; checked at add.
            }
        }
    }
    return wovenBytes;
}
Also used : ManifestElement(org.eclipse.osgi.util.ManifestElement) ClassLoaderHook(org.eclipse.osgi.internal.hookregistry.ClassLoaderHook)

Aggregations

ClassLoaderHook (org.eclipse.osgi.internal.hookregistry.ClassLoaderHook)9 FileNotFoundException (java.io.FileNotFoundException)1 URL (java.net.URL)1 PrivilegedAction (java.security.PrivilegedAction)1 DefineClassResult (org.eclipse.osgi.internal.loader.ModuleClassLoader.DefineClassResult)1 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)1 ManifestElement (org.eclipse.osgi.util.ManifestElement)1 BundleException (org.osgi.framework.BundleException)1