Search in sources :

Example 31 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation in project rt.equinox.framework by eclipse.

the class BundleLoader method clearManifestLocalizationCache.

protected void clearManifestLocalizationCache() {
    Generation hostGen = (Generation) wiring.getRevision().getRevisionInfo();
    hostGen.clearManifestCache();
    List<ModuleWire> hostWires = wiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    // doing a null check because there is no lock on the module database here
    if (hostWires != null) {
        for (ModuleWire fragmentWire : hostWires) {
            Generation fragGen = (Generation) fragmentWire.getRequirer().getRevisionInfo();
            fragGen.clearManifestCache();
        }
    }
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ModuleWire(org.eclipse.osgi.container.ModuleWire)

Example 32 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation in project rt.equinox.framework by eclipse.

the class BundleLoader method getModuleClassLoader.

public ModuleClassLoader getModuleClassLoader() {
    ModuleClassLoader result = classloader;
    if (result != null) {
        return result;
    }
    // doing optimistic class loader creating here to avoid holding any locks,
    // this may result in multiple classloaders being constructed but only one will be used.
    final List<ClassLoaderHook> hooks = container.getConfiguration().getHookRegistry().getClassLoaderHooks();
    final Generation generation = (Generation) wiring.getRevision().getRevisionInfo();
    if (System.getSecurityManager() == null) {
        result = createClassLoaderPrivledged(parent, generation.getBundleInfo().getStorage().getConfiguration(), this, generation, hooks);
    } else {
        final ClassLoader cl = parent;
        result = AccessController.doPrivileged(new PrivilegedAction<ModuleClassLoader>() {

            @Override
            public ModuleClassLoader run() {
                return createClassLoaderPrivledged(cl, generation.getBundleInfo().getStorage().getConfiguration(), BundleLoader.this, generation, hooks);
            }
        });
    }
    // Not ideal, but hooks really should do little work from classLoaderCreated method.
    synchronized (classLoaderCreatedMonitor) {
        if (classLoaderCreated == null) {
            // must set createdClassloader before calling hooks; otherwise we could enter
            // and endless loop if the hook causes re-entry (that would be a bad hook impl)
            classLoaderCreated = result;
            // only send to hooks if this thread wins in creating the class loader.
            final ModuleClassLoader cl = result;
            // protect with doPriv to avoid bubbling up permission checks that hooks may require
            AccessController.doPrivileged(new PrivilegedAction<Object>() {

                @Override
                public Object run() {
                    for (ClassLoaderHook hook : hooks) {
                        hook.classLoaderCreated(cl);
                    }
                    return null;
                }
            });
            // finally set the class loader for use after calling hooks
            classloader = classLoaderCreated;
        } else {
            // return the classLoaderCreated here; not the final classloader
            // this is necessary in case re-entry by a hook.classLoaderCreated method
            result = classLoaderCreated;
            if (debug.DEBUG_LOADER) {
                // $NON-NLS-1$ //$NON-NLS-2$
                Debug.println("BundleLoader[" + this + "].getModuleClassLoader() - created duplicate classloader");
            }
        }
    }
    return result;
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ClassLoaderHook(org.eclipse.osgi.internal.hookregistry.ClassLoaderHook) PrivilegedAction(java.security.PrivilegedAction)

Example 33 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation in project rt.equinox.framework by eclipse.

the class ClasspathManager method loadFragments.

public synchronized void loadFragments(Collection<ModuleRevision> addedFragments) {
    List<FragmentClasspath> result = new ArrayList<>(Arrays.asList(fragments));
    for (ModuleRevision addedFragment : addedFragments) {
        Generation fragGeneration = (Generation) addedFragment.getRevisionInfo();
        String[] cp = getClassPath(addedFragment);
        ClasspathEntry[] fragEntries = buildClasspath(cp, this, fragGeneration);
        FragmentClasspath fragClasspath = new FragmentClasspath(fragGeneration, fragEntries);
        insertFragment(fragClasspath, result);
    }
    fragments = result.toArray(new FragmentClasspath[result.size()]);
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ArrayList(java.util.ArrayList) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 34 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation in project rt.equinox.framework by eclipse.

the class ClasspathManager method buildFragmentClasspaths.

private FragmentClasspath[] buildFragmentClasspaths(ModuleClassLoader hostloader, ClasspathManager manager) {
    if (hostloader == null) {
        return emptyFragments;
    }
    List<ModuleWire> fragmentWires = hostloader.getBundleLoader().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    if (fragmentWires == null || fragmentWires.isEmpty()) {
        // we don't hold locks while checking the graph, just return if no longer valid
        return emptyFragments;
    }
    List<FragmentClasspath> result = new ArrayList<>(fragmentWires.size());
    for (ModuleWire fragmentWire : fragmentWires) {
        ModuleRevision revision = fragmentWire.getRequirer();
        Generation fragGeneration = (Generation) revision.getRevisionInfo();
        String[] cp = getClassPath(revision);
        ClasspathEntry[] fragEntries = buildClasspath(cp, manager, fragGeneration);
        FragmentClasspath fragClasspath = new FragmentClasspath(fragGeneration, fragEntries);
        insertFragment(fragClasspath, result);
    }
    return result.toArray(new FragmentClasspath[result.size()]);
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ModuleWire(org.eclipse.osgi.container.ModuleWire) ArrayList(java.util.ArrayList) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Aggregations

Generation (org.eclipse.osgi.storage.BundleInfo.Generation)34 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)15 ArrayList (java.util.ArrayList)10 Module (org.eclipse.osgi.container.Module)10 IOException (java.io.IOException)8 File (java.io.File)7 BundleFile (org.eclipse.osgi.storage.bundlefile.BundleFile)7 DirBundleFile (org.eclipse.osgi.storage.bundlefile.DirBundleFile)6 NestedDirBundleFile (org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile)6 ZipBundleFile (org.eclipse.osgi.storage.bundlefile.ZipBundleFile)6 BundleException (org.osgi.framework.BundleException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 URL (java.net.URL)3 ProtectionDomain (java.security.ProtectionDomain)3 ModuleRevisionBuilder (org.eclipse.osgi.container.ModuleRevisionBuilder)3 ModuleWire (org.eclipse.osgi.container.ModuleWire)3 SystemModule (org.eclipse.osgi.container.SystemModule)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2