Search in sources :

Example 26 with ModuleRevision

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

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

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

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

the class PackageAdminImpl method getExportedPackages.

public ExportedPackage[] getExportedPackages(Bundle bundle) {
    if (bundle == null) {
        return getExportedPackages((String) null);
    }
    Module module = StartLevelImpl.getModule(bundle);
    Collection<ModuleRevision> revisions = module == null ? Collections.<ModuleRevision>emptyList() : module.getRevisions().getModuleRevisions();
    Collection<ExportedPackage> allExports = new ArrayList<>();
    for (ModuleRevision revision : revisions) {
        ModuleWiring wiring = revision.getWiring();
        if (wiring != null) {
            List<ModuleCapability> providedPackages = wiring.getModuleCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
            if (providedPackages != null) {
                for (ModuleCapability providedPackage : providedPackages) {
                    allExports.add(new ExportedPackageImpl(providedPackage, wiring));
                }
            }
        }
    }
    return allExports.isEmpty() ? null : allExports.toArray(new ExportedPackage[allExports.size()]);
}
Also used : ExportedPackage(org.osgi.service.packageadmin.ExportedPackage) ArrayList(java.util.ArrayList) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) ModuleCapability(org.eclipse.osgi.container.ModuleCapability) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

Example 30 with ModuleRevision

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

the class EclipseLazyStarter method preFindLocalClass.

@Override
public void preFindLocalClass(String name, ClasspathManager manager) throws ClassNotFoundException {
    if (initiatingClassName.get() == null) {
        initiatingClassName.set(name);
    }
    ModuleRevision revision = manager.getGeneration().getRevision();
    Module module = revision.getRevisions().getModule();
    // been initialized (though it may have been destroyed) so just return the class.
    if (alreadyActive.contains(module.getState()))
        return;
    // The bundle is not active and does not require activation, just return the class
    if (!shouldActivateFor(name, module, revision, manager))
        return;
    Deque<ClasspathManager> stack = activationStack.get();
    if (stack == null) {
        stack = new ArrayDeque<>(6);
        activationStack.set(stack);
    }
    // the initiating class has been defined (see postFindLocalClass)
    if (!stack.contains(manager)) {
        // only add the manager if it has not been added already
        stack.addFirst(manager);
    }
}
Also used : ClasspathManager(org.eclipse.osgi.internal.loader.classpath.ClasspathManager) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

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