Search in sources :

Example 26 with Generation

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

the class Storage method checkSystemBundle.

private void checkSystemBundle() {
    Module systemModule = moduleContainer.getModule(0);
    Generation newGeneration = null;
    try {
        if (systemModule == null) {
            BundleInfo info = new BundleInfo(this, 0, Constants.SYSTEM_BUNDLE_LOCATION, 0);
            newGeneration = info.createGeneration();
            File contentFile = getSystemContent();
            newGeneration.setContent(contentFile, false);
            ModuleRevisionBuilder builder = getBuilder(newGeneration);
            systemModule = moduleContainer.install(null, Constants.SYSTEM_BUNDLE_LOCATION, builder, newGeneration);
            moduleContainer.resolve(Arrays.asList(systemModule), false);
        } else {
            ModuleRevision currentRevision = systemModule.getCurrentRevision();
            Generation currentGeneration = currentRevision == null ? null : (Generation) currentRevision.getRevisionInfo();
            if (currentGeneration == null) {
                // $NON-NLS-1$
                throw new IllegalStateException("No current revision for system bundle.");
            }
            try {
                ModuleRevisionBuilder newBuilder = getBuilder(currentGeneration);
                if (needUpdate(currentRevision, newBuilder)) {
                    newGeneration = currentGeneration.getBundleInfo().createGeneration();
                    File contentFile = getSystemContent();
                    newGeneration.setContent(contentFile, false);
                    moduleContainer.update(systemModule, newBuilder, newGeneration);
                    moduleContainer.refresh(Collections.singleton(systemModule));
                } else {
                    if (currentRevision.getWiring() == null) {
                        // must resolve before continuing to ensure extensions get attached
                        moduleContainer.resolve(Collections.singleton(systemModule), true);
                    }
                }
            } catch (BundleException e) {
                // $NON-NLS-1$
                throw new IllegalStateException("Could not create a builder for the system bundle.", e);
            }
        }
        ModuleRevision currentRevision = systemModule.getCurrentRevision();
        List<ModuleCapability> nativeEnvironments = currentRevision.getModuleCapabilities(NativeNamespace.NATIVE_NAMESPACE);
        Map<String, Object> configMap = equinoxContainer.getConfiguration().getInitialConfig();
        for (ModuleCapability nativeEnvironment : nativeEnvironments) {
            nativeEnvironment.setTransientAttrs(configMap);
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        Requirement osgiPackageReq = ModuleContainer.createRequirement(PackageNamespace.PACKAGE_NAMESPACE, Collections.singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + PackageNamespace.PACKAGE_NAMESPACE + "=org.osgi.framework)"), Collections.<String, String>emptyMap());
        Collection<BundleCapability> osgiPackages = moduleContainer.getFrameworkWiring().findProviders(osgiPackageReq);
        for (BundleCapability packageCapability : osgiPackages) {
            if (packageCapability.getRevision().getBundle().getBundleId() == 0) {
                Version v = (Version) packageCapability.getAttributes().get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
                if (v != null) {
                    this.equinoxContainer.getConfiguration().setConfiguration(Constants.FRAMEWORK_VERSION, v.toString());
                    break;
                }
            }
        }
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        // $NON-NLS-1$
        throw new RuntimeException("Error occurred while checking the system module.", e);
    } finally {
        if (newGeneration != null) {
            newGeneration.getBundleInfo().unlockGeneration(newGeneration);
        }
    }
}
Also used : ModuleCapability(org.eclipse.osgi.container.ModuleCapability) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) NoSuchElementException(java.util.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) Requirement(org.osgi.resource.Requirement) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) Version(org.osgi.framework.Version) ModuleRevisionBuilder(org.eclipse.osgi.container.ModuleRevisionBuilder) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module) BundleCapability(org.osgi.framework.wiring.BundleCapability) 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 27 with Generation

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

the class EquinoxBundle method getGenerations.

List<Generation> getGenerations() {
    List<Generation> result = new ArrayList<>();
    ModuleRevision current = getModule().getCurrentRevision();
    result.add((Generation) current.getRevisionInfo());
    ModuleWiring wiring = current.getWiring();
    if (wiring != null) {
        List<ModuleWire> hostWires = wiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
        if (hostWires != null) {
            for (ModuleWire hostWire : hostWires) {
                result.add((Generation) hostWire.getRequirer().getRevisionInfo());
            }
        }
    }
    return result;
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) ModuleWire(org.eclipse.osgi.container.ModuleWire) ArrayList(java.util.ArrayList) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 28 with Generation

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

the class EquinoxContainerAdaptor method clearManifestCache.

private void clearManifestCache(ModuleWiring moduleWiring) {
    boolean frameworkActive = Module.ACTIVE_SET.contains(storage.getModuleContainer().getModule(0).getState());
    ModuleRevision revision = moduleWiring.getRevision();
    Module module = revision.getRevisions().getModule();
    boolean isUninstallingOrUninstalled = State.UNINSTALLED.equals(module.getState()) ^ module.holdsTransitionEventLock(ModuleEvent.UNINSTALLED);
    if (!frameworkActive || !isUninstallingOrUninstalled) {
        // only do this when the framework is not active or when the bundle is not uninstalled
        Generation generation = (Generation) moduleWiring.getRevision().getRevisionInfo();
        generation.clearManifestCache();
    }
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) SystemModule(org.eclipse.osgi.container.SystemModule) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 29 with Generation

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

the class DevClassLoadingHook method addClassPathEntry.

@Override
public boolean addClassPathEntry(ArrayList<ClasspathEntry> cpEntries, String cp, ClasspathManager hostmanager, Generation sourceGeneration) {
    // first check that we are in devmode for this sourcedata
    String[] devClassPath = !configuration.inDevelopmentMode() ? null : configuration.getDevClassPath(sourceGeneration.getRevision().getSymbolicName());
    if (devClassPath == null || devClassPath.length == 0)
        // not in dev mode return
        return false;
    // check that dev classpath entries have not already been added; we mark this in the first entry below
    if (cpEntries.size() > 0 && cpEntries.get(0).getUserObject(KEY) != null)
        // this source has already had its dev classpath entries added.
        return false;
    boolean result = false;
    for (int i = 0; i < devClassPath.length; i++) {
        if (hostmanager.addClassPathEntry(cpEntries, devClassPath[i], hostmanager, sourceGeneration))
            result = true;
        else {
            String devCP = devClassPath[i];
            boolean fromFragment = devCP.endsWith(FRAGMENT);
            if (!fromFragment && devCP.indexOf("..") >= 0) {
                // $NON-NLS-1$
                // if in dev mode, try using cp as a relative path from the base bundle file
                File base = sourceGeneration.getBundleFile().getBaseFile();
                if (base.isDirectory()) {
                    // this is only supported for directory bundles
                    ClasspathEntry entry = hostmanager.getExternalClassPath(new File(base, devCP).getAbsolutePath(), sourceGeneration);
                    if (entry != null) {
                        cpEntries.add(entry);
                        result = true;
                    }
                }
            } else {
                // we assume absolute entries come from fragments.  Find the source
                if (fromFragment)
                    devCP = devCP.substring(0, devCP.length() - FRAGMENT.length());
                Generation fragSource = findFragmentSource(sourceGeneration, devCP, hostmanager, fromFragment);
                if (fragSource != null) {
                    ClasspathEntry entry = hostmanager.getExternalClassPath(devCP, fragSource);
                    if (entry != null) {
                        cpEntries.add(entry);
                        result = true;
                    }
                }
            }
        }
    }
    // This way we can quickly tell that dev classpath entries have been added to the list
    if (result && cpEntries.size() > 0)
        cpEntries.get(0).addUserObject(this);
    return result;
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile) File(java.io.File)

Example 30 with Generation

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

the class TrustEngineListener method getSignedContent.

private SignedContentImpl getSignedContent(Bundle bundle) {
    Generation generation = (Generation) ((EquinoxBundle) bundle).getModule().getCurrentRevision().getRevisionInfo();
    StorageHookImpl hook = generation.getStorageHook(SignedStorageHook.class);
    return hook != null ? hook.signedContent : null;
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) StorageHookImpl(org.eclipse.osgi.internal.signedcontent.SignedStorageHook.StorageHookImpl)

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