Search in sources :

Example 6 with ModuleRevision

use of org.eclipse.osgi.container.ModuleRevision 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 7 with ModuleRevision

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

the class Storage method update.

public Generation update(Module module, 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);
    }
    boolean isReference = in instanceof ReferenceInputStream;
    File staged = stageContent(in, sourceURL);
    ModuleRevision current = module.getCurrentRevision();
    Generation currentGen = (Generation) current.getRevisionInfo();
    BundleInfo bundleInfo = currentGen.getBundleInfo();
    Generation newGen = bundleInfo.createGeneration();
    try {
        File contentFile = getContentFile(staged, isReference, bundleInfo.getBundleId(), newGen.getGenerationId());
        newGen.setContent(contentFile, isReference);
        // Check that we can open the bundle file
        newGen.getBundleFile().open();
        setStorageHooks(newGen);
        ModuleRevisionBuilder builder = getBuilder(newGen);
        moduleContainer.update(module, builder, newGen);
    } catch (Throwable t) {
        if (!isReference) {
            try {
                delete(staged);
            } catch (IOException e) {
            // tried our best
            }
        }
        newGen.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 {
        bundleInfo.unlockGeneration(newGen);
    }
    return newGen;
}
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) ReferenceInputStream(org.eclipse.osgi.storage.url.reference.ReferenceInputStream) IOException(java.io.IOException) URL(java.net.URL) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ModuleRevisionBuilder(org.eclipse.osgi.container.ModuleRevisionBuilder) BundleException(org.osgi.framework.BundleException) 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) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 8 with ModuleRevision

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

the class Storage method refresh.

private void refresh(Module module) throws BundleException {
    ModuleRevision current = module.getCurrentRevision();
    Generation currentGen = (Generation) current.getRevisionInfo();
    File content = currentGen.getContent();
    // $NON-NLS-1$ //$NON-NLS-2$
    String spec = (currentGen.isReference() ? "reference:" : "") + content.toURI().toString();
    URLConnection contentConn;
    try {
        contentConn = getContentConnection(spec);
    } catch (IOException e) {
        // $NON-NLS-1$
        throw new BundleException("Error reading bundle content.", e);
    }
    update(module, contentConn);
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) 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) URLConnection(java.net.URLConnection)

Example 9 with ModuleRevision

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

the class Storage method getUpdateLocation0.

String getUpdateLocation0(Module module) {
    ModuleRevision current = module.getCurrentRevision();
    Generation generation = (Generation) current.getRevisionInfo();
    String updateLocation = generation.getHeaders().get(Constants.BUNDLE_UPDATELOCATION);
    if (updateLocation == null) {
        updateLocation = module.getLocation();
    }
    if (updateLocation.startsWith(INITIAL_LOCATION)) {
        updateLocation = updateLocation.substring(INITIAL_LOCATION.length());
    }
    return updateLocation;
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 10 with ModuleRevision

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

the class Handler method findBundleEntry.

protected BundleEntry findBundleEntry(URL url, Module module) throws IOException {
    ModuleRevision revision = module.getCurrentRevision();
    BundleInfo.Generation revisionInfo = (BundleInfo.Generation) revision.getRevisionInfo();
    BundleEntry entry = revisionInfo == null ? null : revisionInfo.getBundleFile().getEntry(url.getPath());
    if (entry == null) {
        String path = url.getPath();
        if (revisionInfo != null && (path.indexOf('%') >= 0 || path.indexOf('+') >= 0)) {
            entry = revisionInfo.getBundleFile().getEntry(LocationHelper.decode(path, true));
            if (entry != null) {
                return entry;
            }
            entry = revisionInfo.getBundleFile().getEntry(LocationHelper.decode(path, false));
            if (entry != null) {
                return entry;
            }
        }
        throw new FileNotFoundException(url.getPath());
    }
    return entry;
}
Also used : BundleInfo(org.eclipse.osgi.storage.BundleInfo) FileNotFoundException(java.io.FileNotFoundException) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) BundleEntry(org.eclipse.osgi.storage.bundlefile.BundleEntry)

Aggregations

ModuleRevision (org.eclipse.osgi.container.ModuleRevision)35 Module (org.eclipse.osgi.container.Module)21 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)15 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)12 ArrayList (java.util.ArrayList)9 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)9 ModuleWire (org.eclipse.osgi.container.ModuleWire)9 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)8 Test (org.junit.Test)8 BundleException (org.osgi.framework.BundleException)5 IOException (java.io.IOException)4 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)4 File (java.io.File)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 SystemModule (org.eclipse.osgi.container.SystemModule)3 BundleFile (org.eclipse.osgi.storage.bundlefile.BundleFile)3 DirBundleFile (org.eclipse.osgi.storage.bundlefile.DirBundleFile)3 NestedDirBundleFile (org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile)3 ZipBundleFile (org.eclipse.osgi.storage.bundlefile.ZipBundleFile)3