Search in sources :

Example 16 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation 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 17 with Generation

use of org.eclipse.osgi.storage.BundleInfo.Generation 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 18 with Generation

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

the class Storage method close.

public void close() {
    try {
        save();
    } catch (IOException e) {
        // $NON-NLS-1$
        getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Error saving on shutdown", e);
    }
    // close all the generations
    List<Module> modules = moduleContainer.getModules();
    for (Module module : modules) {
        for (ModuleRevision revision : module.getRevisions().getModuleRevisions()) {
            Generation generation = (Generation) revision.getRevisionInfo();
            if (generation != null) {
                generation.close();
            }
        }
    }
    for (ModuleRevision removalPending : moduleContainer.getRemovalPending()) {
        Generation generation = (Generation) removalPending.getRevisionInfo();
        if (generation != null) {
            generation.close();
        }
    }
    mruList.shutdown();
    adaptor.shutdownResolverExecutor();
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) IOException(java.io.IOException) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 19 with Generation

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

the class Storage method loadStorageHookData.

private void loadStorageHookData(List<Generation> generations, DataInputStream in) throws IOException {
    List<StorageHookFactory<?, ?, ?>> factories = new ArrayList<>(getConfiguration().getHookRegistry().getStorageHookFactories());
    Map<Generation, List<StorageHook<?, ?>>> hookMap = new HashMap<>();
    int numFactories = in.readInt();
    for (int i = 0; i < numFactories; i++) {
        String factoryName = in.readUTF();
        int version = in.readInt();
        StorageHookFactory<Object, Object, StorageHook<Object, Object>> factory = null;
        for (Iterator<StorageHookFactory<?, ?, ?>> iFactories = factories.iterator(); iFactories.hasNext(); ) {
            @SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next();
            if (next.getKey().equals(factoryName)) {
                factory = next;
                iFactories.remove();
                break;
            }
        }
        int dataSize = in.readInt();
        byte[] bytes = new byte[dataSize];
        in.readFully(bytes);
        if (factory != null) {
            DataInputStream temp = new DataInputStream(new ByteArrayInputStream(bytes));
            try {
                if (factory.isCompatibleWith(version)) {
                    Object loadContext = factory.createLoadContext(version);
                    for (Generation generation : generations) {
                        if (generation.getBundleInfo().getBundleId() == 0) {
                            // ignore system bundle
                            continue;
                        }
                        StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation);
                        hook.load(loadContext, temp);
                        getHooks(hookMap, generation).add(hook);
                    }
                } else {
                    // recover by reinitializing the hook
                    for (Generation generation : generations) {
                        if (generation.getBundleInfo().getBundleId() == 0) {
                            // ignore system bundle
                            continue;
                        }
                        StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation);
                        hook.initialize(generation.getHeaders());
                        getHooks(hookMap, generation).add(hook);
                    }
                }
            } catch (BundleException e) {
                throw new IOException(e);
            } finally {
                temp.close();
            }
        }
    }
    // now we need to recover for any hooks that are left
    for (Iterator<StorageHookFactory<?, ?, ?>> iFactories = factories.iterator(); iFactories.hasNext(); ) {
        @SuppressWarnings("unchecked") StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next();
        // recover by reinitializing the hook
        for (Generation generation : generations) {
            if (generation.getBundleInfo().getBundleId() == 0) {
                // ignore system bundle
                continue;
            }
            StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation);
            try {
                hook.initialize(generation.getHeaders());
                getHooks(hookMap, generation).add(hook);
            } catch (BundleException e) {
                throw new IOException(e);
            }
        }
    }
    // now set the hooks to the generations
    for (Generation generation : generations) {
        generation.setStorageHooks(Collections.unmodifiableList(getHooks(hookMap, generation)), false);
    }
}
Also used : StorageHookFactory(org.eclipse.osgi.internal.hookregistry.StorageHookFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) StorageHook(org.eclipse.osgi.internal.hookregistry.StorageHookFactory.StorageHook) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) MRUBundleFileList(org.eclipse.osgi.storage.bundlefile.MRUBundleFileList) List(java.util.List) BundleException(org.osgi.framework.BundleException)

Example 20 with Generation

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

the class BundleContextImpl method installBundle.

public Bundle installBundle(String location, InputStream in) throws BundleException {
    checkValid();
    try {
        URLConnection content = container.getStorage().getContentConnection(null, location, in);
        Generation generation = container.getStorage().install(bundle.getModule(), location, content);
        return generation.getRevision().getBundle();
    } catch (IOException e) {
        // $NON-NLS-1$
        throw new BundleException("Error reading bundle content.", e);
    }
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) URLConnection(java.net.URLConnection)

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