summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ross2013-06-25 16:39:41 (EDT)
committer Thomas Watson2013-06-26 14:27:27 (EDT)
commit6348a20e4f5c94c5d048f56287768feb1538ce7b (patch)
tree7baef07fa5d12fde58bdc2a433803197d2b68681
parent88580f7595f0f7b09de84ddc0eb281b81da6857d (diff)
downloadrt.equinox.framework-6348a20e4f5c94c5d048f56287768feb1538ce7b.zip
rt.equinox.framework-6348a20e4f5c94c5d048f56287768feb1538ce7b.tar.gz
rt.equinox.framework-6348a20e4f5c94c5d048f56287768feb1538ce7b.tar.bz2
Bug 407416 - [unity] Allow storage hooks to validate the Generation.
The framework will now ask storage hooks to validate bundles at load time. If a storage hook throws an IllegalStateException, the bundle will be discarded.
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/StorageHookFactory.java4
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java8
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java59
3 files changed, 44 insertions, 27 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/StorageHookFactory.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/StorageHookFactory.java
index e99097c..7c928e3 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/StorageHookFactory.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/StorageHookFactory.java
@@ -144,9 +144,9 @@ public abstract class StorageHookFactory<S, L, H extends StorageHookFactory.Stor
/**
* Validates the data in this storage hook, if the data is invalid then an illegal state
* exception is thrown
- * @throws IllegalArgumentException if the data is invalid
+ * @throws IllegalStateException if the data is invalid
*/
- public void validate() throws IllegalArgumentException {
+ public void validate() throws IllegalStateException {
// do nothing by default
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java
index 8f6e85a..c499c81 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java
@@ -304,6 +304,14 @@ public final class BundleInfo {
}
return currentFinder.findLibrary(libname);
}
+
+ List<StorageHook<?, ?>> getStorageHooks() {
+ synchronized (this.genMonitor) {
+ // TODO Not sure if the extra protection of returning a copy is
+ // necessary but played it safe.
+ return new ArrayList<StorageHook<?, ?>>(storageHooks);
+ }
+ }
}
private final Storage storage;
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java
index 5614c27..4b0715d 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java
@@ -79,7 +79,7 @@ public class Storage {
Storage storage = new Storage(container);
// Do some operations that need to happen on the fully constructed Storage before returning it
storage.checkSystemBundle();
- storage.discardBundles();
+ storage.discardBundlesOnLoad();
storage.installExtensions();
// TODO hack to make sure all bundles are in UNINSTALLED state before system bundle init is called
storage.getModuleContainer().setInitialModuleStates();
@@ -183,35 +183,44 @@ public class Storage {
return permData;
}
- private void discardBundles() throws BundleException {
- if (getConfiguration().inCheckConfigurationMode()) {
- Collection<Module> discarded = new ArrayList<Module>(0);
- 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)) {
- discarded.add(module);
- moduleContainer.uninstall(module);
- generation.delete();
- }
+ private void discardBundlesOnLoad() throws BundleException {
+ Collection<Module> discarded = new ArrayList<Module>(0);
+ 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)) {
+ discarded.add(module);
+ moduleContainer.uninstall(module);
+ generation.delete();
}
- if (!discarded.isEmpty()) {
- try {
- moduleContainer.refresh(discarded);
- } catch (ResolutionException e) {
- throw new BundleException("Error discarding bundles.", e); //$NON-NLS-1$
- }
+ }
+ if (!discarded.isEmpty()) {
+ try {
+ moduleContainer.refresh(discarded);
+ } catch (ResolutionException e) {
+ throw new BundleException("Error discarding bundles.", e); //$NON-NLS-1$
}
}
}
- private static boolean needsDiscarding(Generation generation) {
- File content = generation.getContent();
- if (generation.isDirectory())
- content = new File(content, "META-INF/MANIFEST.MF"); //$NON-NLS-1$
- return generation.getLastModified() != secureAction.lastModified(content);
+ private boolean needsDiscarding(Generation generation) {
+ for (StorageHook<?, ?> hook : generation.getStorageHooks()) {
+ try {
+ hook.validate();
+ } catch (IllegalStateException e) {
+ // TODO Logging?
+ return true;
+ }
+ }
+ if (getConfiguration().inCheckConfigurationMode()) {
+ File content = generation.getContent();
+ if (generation.isDirectory())
+ content = new File(content, "META-INF/MANIFEST.MF"); //$NON-NLS-1$
+ return generation.getLastModified() != secureAction.lastModified(content);
+ }
+ return false;
}
private void checkSystemBundle() {