use of org.eclipse.osgi.container.ModuleRevision 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);
}
}
use of org.eclipse.osgi.container.ModuleRevision in project rt.equinox.framework by eclipse.
the class Storage method update.
public Generation update(Module module, URLConnection content) throws BundleException {
if (osgiLocation.isReadOnly()) {
// $NON-NLS-1$
throw new BundleException("The framework storage area is read only.", BundleException.INVALID_OPERATION);
}
URL sourceURL = content.getURL();
InputStream in;
try {
in = content.getInputStream();
} catch (Throwable e) {
// $NON-NLS-1$
throw new BundleException("Error reading bundle content.", e);
}
boolean isReference = in instanceof ReferenceInputStream;
File staged = stageContent(in, sourceURL);
ModuleRevision current = module.getCurrentRevision();
Generation currentGen = (Generation) current.getRevisionInfo();
BundleInfo bundleInfo = currentGen.getBundleInfo();
Generation newGen = bundleInfo.createGeneration();
try {
File contentFile = getContentFile(staged, isReference, bundleInfo.getBundleId(), newGen.getGenerationId());
newGen.setContent(contentFile, isReference);
// Check that we can open the bundle file
newGen.getBundleFile().open();
setStorageHooks(newGen);
ModuleRevisionBuilder builder = getBuilder(newGen);
moduleContainer.update(module, builder, newGen);
} catch (Throwable t) {
if (!isReference) {
try {
delete(staged);
} catch (IOException e) {
// tried our best
}
}
newGen.delete();
if (t instanceof SecurityException) {
// if the cause is a bundle exception then throw that
if (t.getCause() instanceof BundleException) {
throw (BundleException) t.getCause();
}
throw (SecurityException) t;
}
if (t instanceof BundleException) {
throw (BundleException) t;
}
// $NON-NLS-1$
throw new BundleException("Error occurred installing a bundle.", t);
} finally {
bundleInfo.unlockGeneration(newGen);
}
return newGen;
}
use of org.eclipse.osgi.container.ModuleRevision in project rt.equinox.framework by eclipse.
the class Storage method refresh.
private void refresh(Module module) throws BundleException {
ModuleRevision current = module.getCurrentRevision();
Generation currentGen = (Generation) current.getRevisionInfo();
File content = currentGen.getContent();
// $NON-NLS-1$ //$NON-NLS-2$
String spec = (currentGen.isReference() ? "reference:" : "") + content.toURI().toString();
URLConnection contentConn;
try {
contentConn = getContentConnection(spec);
} catch (IOException e) {
// $NON-NLS-1$
throw new BundleException("Error reading bundle content.", e);
}
update(module, contentConn);
}
use of org.eclipse.osgi.container.ModuleRevision in project rt.equinox.framework by eclipse.
the class Storage method getUpdateLocation0.
String getUpdateLocation0(Module module) {
ModuleRevision current = module.getCurrentRevision();
Generation generation = (Generation) current.getRevisionInfo();
String updateLocation = generation.getHeaders().get(Constants.BUNDLE_UPDATELOCATION);
if (updateLocation == null) {
updateLocation = module.getLocation();
}
if (updateLocation.startsWith(INITIAL_LOCATION)) {
updateLocation = updateLocation.substring(INITIAL_LOCATION.length());
}
return updateLocation;
}
use of org.eclipse.osgi.container.ModuleRevision in project rt.equinox.framework by eclipse.
the class Handler method findBundleEntry.
protected BundleEntry findBundleEntry(URL url, Module module) throws IOException {
ModuleRevision revision = module.getCurrentRevision();
BundleInfo.Generation revisionInfo = (BundleInfo.Generation) revision.getRevisionInfo();
BundleEntry entry = revisionInfo == null ? null : revisionInfo.getBundleFile().getEntry(url.getPath());
if (entry == null) {
String path = url.getPath();
if (revisionInfo != null && (path.indexOf('%') >= 0 || path.indexOf('+') >= 0)) {
entry = revisionInfo.getBundleFile().getEntry(LocationHelper.decode(path, true));
if (entry != null) {
return entry;
}
entry = revisionInfo.getBundleFile().getEntry(LocationHelper.decode(path, false));
if (entry != null) {
return entry;
}
}
throw new FileNotFoundException(url.getPath());
}
return entry;
}
Aggregations