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);
}
}
}
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;
}
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();
}
}
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()]);
}
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);
}
}
Aggregations