Search in sources :

Example 6 with Module

use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.

the class BundleLocalizationImpl method getLocalization.

/**
 * The getLocalization method gets a ResourceBundle object for the given
 * locale and bundle.
 *
 * @return A <code>ResourceBundle</code> object for the given bundle and locale.
 * If null is passed for the locale parameter, the default locale is used.
 */
public ResourceBundle getLocalization(Bundle bundle, String locale) {
    Module m = ((EquinoxBundle) bundle).getModule();
    ModuleRevision r = m.getCurrentRevision();
    Generation g = (Generation) r.getRevisionInfo();
    return g.getResourceBundle(locale);
}
Also used : EquinoxBundle(org.eclipse.osgi.internal.framework.EquinoxBundle) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 7 with Module

use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.

the class Storage method refreshStaleBundles.

private void refreshStaleBundles() throws BundleException {
    Collection<Module> needsRefresh = new ArrayList<>(0);
    // First uninstall any modules that had their content changed or deleted
    for (Module module : moduleContainer.getModules()) {
        if (module.getId() == Constants.SYSTEM_BUNDLE_ID)
            continue;
        ModuleRevision revision = module.getCurrentRevision();
        Generation generation = (Generation) revision.getRevisionInfo();
        if (needsDiscarding(generation)) {
            needsRefresh.add(module);
            moduleContainer.uninstall(module);
            generation.delete();
        }
    }
    // because the runtime version changed.
    if (refreshMRBundles.get()) {
        needsRefresh.addAll(refreshMRJarBundles());
    }
    // refresh the modules that got deleted or are Multi-Release bundles
    if (!needsRefresh.isEmpty()) {
        moduleContainer.refresh(needsRefresh);
    }
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ArrayList(java.util.ArrayList) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 8 with Module

use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.

the class Storage method install.

public Generation install(Module origin, String bundleLocation, URLConnection content) throws BundleException {
    if (osgiLocation.isReadOnly()) {
        // $NON-NLS-1$
        throw new BundleException("The framework storage area is read only.", BundleException.INVALID_OPERATION);
    }
    URL sourceURL = content.getURL();
    InputStream in;
    try {
        in = content.getInputStream();
    } catch (Throwable e) {
        // $NON-NLS-1$
        throw new BundleException("Error reading bundle content.", e);
    }
    // Check if the bundle already exists at this location
    // before doing the staging and generation creation.
    // This is important since some installers seem to continually
    // re-install bundles using the same location each startup
    Module existingLocation = moduleContainer.getModule(bundleLocation);
    if (existingLocation != null) {
        // Another thread could win the location lock and install before this thread does.
        try {
            in.close();
        } catch (IOException e) {
        // ignore
        }
        if (origin != null) {
            // Check that the existing location is visible from the origin module
            Bundle bundle = origin.getBundle();
            BundleContext context = bundle == null ? null : bundle.getBundleContext();
            if (context != null && context.getBundle(existingLocation.getId()) == null) {
                Bundle b = existingLocation.getBundle();
                throw new BundleException(NLS.bind(Msg.ModuleContainer_NameCollisionWithLocation, new Object[] { b.getSymbolicName(), b.getVersion(), bundleLocation }), BundleException.REJECTED_BY_HOOK);
            }
        }
        return (Generation) existingLocation.getCurrentRevision().getRevisionInfo();
    }
    boolean isReference = in instanceof ReferenceInputStream;
    File staged = stageContent(in, sourceURL);
    Generation generation = null;
    try {
        Long nextID = moduleDatabase.getAndIncrementNextId();
        BundleInfo info = new BundleInfo(this, nextID, bundleLocation, 0);
        generation = info.createGeneration();
        File contentFile = getContentFile(staged, isReference, nextID, generation.getGenerationId());
        generation.setContent(contentFile, isReference);
        // Check that we can open the bundle file
        generation.getBundleFile().open();
        setStorageHooks(generation);
        ModuleRevisionBuilder builder = getBuilder(generation);
        builder.setId(nextID);
        Module m = moduleContainer.install(origin, bundleLocation, builder, generation);
        if (!nextID.equals(m.getId())) {
            // this revision is already installed. delete the generation
            generation.delete();
            return (Generation) m.getCurrentRevision().getRevisionInfo();
        }
        return generation;
    } catch (Throwable t) {
        if (!isReference) {
            try {
                delete(staged);
            } catch (IOException e) {
            // tried our best
            }
        }
        if (generation != null) {
            generation.delete();
            generation.getBundleInfo().delete();
        }
        if (t instanceof SecurityException) {
            // if the cause is a bundle exception then throw that
            if (t.getCause() instanceof BundleException) {
                throw (BundleException) t.getCause();
            }
            throw (SecurityException) t;
        }
        if (t instanceof BundleException) {
            throw (BundleException) t;
        }
        // $NON-NLS-1$
        throw new BundleException("Error occurred installing a bundle.", t);
    } finally {
        if (generation != null) {
            generation.getBundleInfo().unlockGeneration(generation);
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ReferenceInputStream(org.eclipse.osgi.storage.url.reference.ReferenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) ReferenceInputStream(org.eclipse.osgi.storage.url.reference.ReferenceInputStream) URL(java.net.URL) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ModuleRevisionBuilder(org.eclipse.osgi.container.ModuleRevisionBuilder) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module) NestedDirBundleFile(org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile) File(java.io.File) ZipBundleFile(org.eclipse.osgi.storage.bundlefile.ZipBundleFile) DirBundleFile(org.eclipse.osgi.storage.bundlefile.DirBundleFile) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile) BundleContext(org.osgi.framework.BundleContext)

Example 9 with Module

use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.

the class BundleResourceHandler method openConnection.

/**
 * Establishes a connection to the resource specified by <code>URL</code>.
 * Since different protocols may have unique ways of connecting, it must be
 * overridden by the subclass.
 *
 * @return java.net.URLConnection
 * @param url java.net.URL
 *
 * @exception	IOException 	thrown if an IO error occurs during connection establishment
 */
protected URLConnection openConnection(URL url) throws IOException {
    if (// if the bundleEntry is not null then return quick
    bundleEntry != null)
        return (new BundleURLConnection(url, bundleEntry));
    String host = url.getHost();
    if (host == null) {
        throw new IOException(NLS.bind(Msg.URL_NO_BUNDLE_ID, url.toExternalForm()));
    }
    long bundleID;
    try {
        bundleID = getBundleID(host);
    } catch (NumberFormatException nfe) {
        throw (MalformedURLException) new MalformedURLException(NLS.bind(Msg.URL_INVALID_BUNDLE_ID, host)).initCause(nfe);
    }
    Module module = getModule(bundleID);
    if (module == null)
        throw new IOException(NLS.bind(Msg.URL_NO_BUNDLE_FOUND, url.toExternalForm()));
    // at URL construction.
    if (!url.getAuthority().equals(SECURITY_CHECKED)) {
        // No admin security check was made better check now.
        checkAuthorization(module);
    }
    return (new BundleURLConnection(url, findBundleEntry(url, module)));
}
Also used : IOException(java.io.IOException) Module(org.eclipse.osgi.container.Module)

Example 10 with Module

use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.

the class ClasspathManager method findLocalResources.

/**
 * Finds the local resources by searching the ClasspathEntry objects of the classpath manager.
 * @param resource the requested resource name.
 * @return an enumeration of the the requested resources
 */
public Enumeration<URL> findLocalResources(String resource) {
    Module m = generation.getRevision().getRevisions().getModule();
    List<URL> resources = new ArrayList<>(6);
    int classPathIndex = 0;
    for (ClasspathEntry cpEntry : entries) {
        if (cpEntry != null) {
            URL url = cpEntry.findResource(resource, m, classPathIndex);
            if (url != null) {
                resources.add(url);
            }
        }
        classPathIndex++;
    }
    // look in fragments
    for (FragmentClasspath fragCP : getFragmentClasspaths()) {
        for (ClasspathEntry cpEntry : fragCP.getEntries()) {
            URL url = cpEntry.findResource(resource, m, classPathIndex);
            if (url != null) {
                resources.add(url);
            }
            classPathIndex++;
        }
    }
    if (resources.size() > 0)
        return Collections.enumeration(resources);
    return EMPTY_ENUMERATION;
}
Also used : ArrayList(java.util.ArrayList) Module(org.eclipse.osgi.container.Module) URL(java.net.URL)

Aggregations

Module (org.eclipse.osgi.container.Module)119 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)92 Test (org.junit.Test)84 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)79 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)36 ModuleWire (org.eclipse.osgi.container.ModuleWire)32 HashMap (java.util.HashMap)23 ArrayList (java.util.ArrayList)22 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)22 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)21 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)12 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)10 BundleException (org.osgi.framework.BundleException)10 DummyModuleEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)9 ModuleRevisionBuilder (org.eclipse.osgi.container.ModuleRevisionBuilder)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataInputStream (java.io.DataInputStream)6 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)6 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)6