use of org.eclipse.osgi.storage.url.reference.ReferenceInputStream 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.storage.url.reference.ReferenceInputStream in project rt.equinox.framework by eclipse.
the class Storage method install.
public Generation install(Module origin, String bundleLocation, 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);
}
// Check if the bundle already exists at this location
// before doing the staging and generation creation.
// This is important since some installers seem to continually
// re-install bundles using the same location each startup
Module existingLocation = moduleContainer.getModule(bundleLocation);
if (existingLocation != null) {
// Another thread could win the location lock and install before this thread does.
try {
in.close();
} catch (IOException e) {
// ignore
}
if (origin != null) {
// Check that the existing location is visible from the origin module
Bundle bundle = origin.getBundle();
BundleContext context = bundle == null ? null : bundle.getBundleContext();
if (context != null && context.getBundle(existingLocation.getId()) == null) {
Bundle b = existingLocation.getBundle();
throw new BundleException(NLS.bind(Msg.ModuleContainer_NameCollisionWithLocation, new Object[] { b.getSymbolicName(), b.getVersion(), bundleLocation }), BundleException.REJECTED_BY_HOOK);
}
}
return (Generation) existingLocation.getCurrentRevision().getRevisionInfo();
}
boolean isReference = in instanceof ReferenceInputStream;
File staged = stageContent(in, sourceURL);
Generation generation = null;
try {
Long nextID = moduleDatabase.getAndIncrementNextId();
BundleInfo info = new BundleInfo(this, nextID, bundleLocation, 0);
generation = info.createGeneration();
File contentFile = getContentFile(staged, isReference, nextID, generation.getGenerationId());
generation.setContent(contentFile, isReference);
// Check that we can open the bundle file
generation.getBundleFile().open();
setStorageHooks(generation);
ModuleRevisionBuilder builder = getBuilder(generation);
builder.setId(nextID);
Module m = moduleContainer.install(origin, bundleLocation, builder, generation);
if (!nextID.equals(m.getId())) {
// this revision is already installed. delete the generation
generation.delete();
return (Generation) m.getCurrentRevision().getRevisionInfo();
}
return generation;
} catch (Throwable t) {
if (!isReference) {
try {
delete(staged);
} catch (IOException e) {
// tried our best
}
}
if (generation != null) {
generation.delete();
generation.getBundleInfo().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 {
if (generation != null) {
generation.getBundleInfo().unlockGeneration(generation);
}
}
}
use of org.eclipse.osgi.storage.url.reference.ReferenceInputStream in project rt.equinox.framework by eclipse.
the class Storage method stageContent0.
File stageContent0(InputStream in, URL sourceURL) throws BundleException {
File outFile = null;
try {
if (in instanceof ReferenceInputStream) {
URL reference = ((ReferenceInputStream) in).getReference();
if (// $NON-NLS-1$
!"file".equals(reference.getProtocol()))
throw new BundleException(NLS.bind(Msg.ADAPTOR_URL_CREATE_EXCEPTION, reference));
return new File(reference.getPath());
}
// $NON-NLS-1$
outFile = File.createTempFile(BUNDLE_FILE_NAME, ".tmp", childRoot);
String protocol = sourceURL == null ? null : sourceURL.getProtocol();
if ("file".equals(protocol)) {
// $NON-NLS-1$
File inFile = new File(sourceURL.getPath());
inFile = LocationHelper.decodePath(inFile);
if (inFile.isDirectory()) {
// need to delete the outFile because it is not a directory
outFile.delete();
StorageUtil.copyDir(inFile, outFile);
} else {
StorageUtil.readFile(in, outFile);
}
} else {
StorageUtil.readFile(in, outFile);
}
return outFile;
} catch (IOException e) {
if (outFile != null) {
outFile.delete();
}
throw new BundleException(Msg.BUNDLE_READ_EXCEPTION, BundleException.READ_ERROR, e);
}
}
Aggregations