Search in sources :

Example 6 with Generation

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

the class ServiceRegistry method hasListenServicePermission.

/**
 * Check for permission to listen to a service.
 */
static boolean hasListenServicePermission(ServiceEvent event, BundleContextImpl context) {
    ModuleRevision revision = context.getBundleImpl().getModule().getCurrentRevision();
    if (revision == null) {
        return false;
    }
    ProtectionDomain domain = ((Generation) revision.getRevisionInfo()).getDomain();
    if (domain == null) {
        return true;
    }
    return domain.implies(new ServicePermission(event.getServiceReference(), ServicePermission.GET));
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 7 with Generation

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

the class SignedBundleHook method getSignedContent.

public SignedContent getSignedContent(Bundle bundle) throws IOException, InvalidKeyException, SignatureException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException {
    final Generation generation = (Generation) ((EquinoxBundle) bundle).getModule().getCurrentRevision().getRevisionInfo();
    StorageHookImpl hook = generation.getStorageHook(SignedStorageHook.class);
    SignedContent result = hook != null ? hook.signedContent : null;
    if (result != null)
        // just reuse the signed content the storage hook
        return result;
    // must create a new signed content using the raw file
    if (System.getSecurityManager() == null)
        return getSignedContent(generation.getBundleFile().getBaseFile());
    try {
        return AccessController.doPrivileged(new PrivilegedExceptionAction<SignedContent>() {

            public SignedContent run() throws Exception {
                return getSignedContent(generation.getBundleFile().getBaseFile());
            }
        });
    } catch (PrivilegedActionException e) {
        if (e.getException() instanceof IOException)
            throw (IOException) e.getException();
        if (e.getException() instanceof InvalidKeyException)
            throw (InvalidKeyException) e.getException();
        if (e.getException() instanceof SignatureException)
            throw (SignatureException) e.getException();
        if (e.getException() instanceof CertificateException)
            throw (CertificateException) e.getException();
        if (e.getException() instanceof NoSuchAlgorithmException)
            throw (NoSuchAlgorithmException) e.getException();
        if (e.getException() instanceof NoSuchProviderException)
            throw (NoSuchProviderException) e.getException();
        // $NON-NLS-1$
        throw new RuntimeException("Unknown error.", e.getException());
    }
}
Also used : StorageHookImpl(org.eclipse.osgi.internal.signedcontent.SignedStorageHook.StorageHookImpl) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) Generation(org.eclipse.osgi.storage.BundleInfo.Generation)

Example 8 with Generation

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

the class FrameworkExtensionInstaller method getExtensionFiles.

/**
 * Returns a list of classpath files for an extension bundle
 * @param revision revision for the extension bundle
 * @return a list of classpath files for an extension bundle
 */
private File[] getExtensionFiles(ModuleRevision revision) {
    List<ModuleCapability> metaDatas = revision.getModuleCapabilities(EquinoxModuleDataNamespace.MODULE_DATA_NAMESPACE);
    @SuppressWarnings("unchecked") List<String> paths = metaDatas.isEmpty() ? null : (List<String>) metaDatas.get(0).getAttributes().get(EquinoxModuleDataNamespace.CAPABILITY_CLASSPATH);
    if (paths == null) {
        paths = new ArrayList<>(1);
        // $NON-NLS-1$
        paths.add(".");
    }
    if (configuration.inDevelopmentMode()) {
        String[] devPaths = configuration.getDevClassPath(revision.getSymbolicName());
        for (String devPath : devPaths) {
            paths.add(devPath);
        }
    }
    List<File> results = new ArrayList<>(paths.size());
    for (String path : paths) {
        if (".".equals(path)) {
            // $NON-NLS-1$
            results.add(((Generation) revision.getRevisionInfo()).getBundleFile().getBaseFile());
        } else {
            File result = ((Generation) revision.getRevisionInfo()).getBundleFile().getFile(path, false);
            if (result != null)
                results.add(result);
        }
    }
    return results.toArray(new File[results.size()]);
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ArrayList(java.util.ArrayList) ModuleCapability(org.eclipse.osgi.container.ModuleCapability) File(java.io.File)

Example 9 with Generation

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

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

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