diff options
author | John Ross | 2013-06-25 20:39:41 +0000 |
---|---|---|
committer | Thomas Watson | 2013-06-26 18:27:27 +0000 |
commit | 6348a20e4f5c94c5d048f56287768feb1538ce7b (patch) | |
tree | 7baef07fa5d12fde58bdc2a433803197d2b68681 | |
parent | 88580f7595f0f7b09de84ddc0eb281b81da6857d (diff) | |
download | rt.equinox.framework-6348a20e4f5c94c5d048f56287768feb1538ce7b.tar.gz rt.equinox.framework-6348a20e4f5c94c5d048f56287768feb1538ce7b.tar.xz rt.equinox.framework-6348a20e4f5c94c5d048f56287768feb1538ce7b.zip |
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.
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 e99097cb4..7c928e36e 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 8f6e85a80..c499c8156 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 5614c2762..4b0715d03 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() { |