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