diff options
author | Thomas Watson | 2014-02-21 21:44:22 +0000 |
---|---|---|
committer | Thomas Watson | 2014-02-21 21:44:22 +0000 |
commit | 10d59fd586440c09b9f0ab7af79c3650c81a8cfa (patch) | |
tree | f13793e7b605fc244fb01d5cc9735576ea08208f | |
parent | c48f9c82ccc057bc15a37ed9be7d059803c390b2 (diff) | |
download | rt.equinox.framework-10d59fd586440c09b9f0ab7af79c3650c81a8cfa.tar.gz rt.equinox.framework-10d59fd586440c09b9f0ab7af79c3650c81a8cfa.tar.xz rt.equinox.framework-10d59fd586440c09b9f0ab7af79c3650c81a8cfa.zip |
Bug 428803 - Clean up container package
18 files changed, 224 insertions, 72 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/ResolutionReportTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/ResolutionReportTest.java index 95f484d4a..bc4939bc6 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/ResolutionReportTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/ResolutionReportTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation and others. + * Copyright (c) 2013, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,7 +16,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.*; -import org.eclipse.osgi.container.*; +import org.eclipse.osgi.container.Module; +import org.eclipse.osgi.container.ModuleContainer; import org.eclipse.osgi.report.resolution.ResolutionReport; import org.eclipse.osgi.tests.container.dummys.*; import org.junit.Test; @@ -50,13 +51,6 @@ public class ResolutionReportTest extends AbstractTest { } @Test - public void testResolutionReportBuilder() { - org.eclipse.osgi.container.ModuleResolutionReport.Builder builder = new org.eclipse.osgi.container.ModuleResolutionReport.Builder(); - ResolutionReport report = builder.build(null, null); - assertNotNull("Resolution report was null", report); - } - - @Test public void testResolutionReportEntryFilteredByResolverHook() throws Exception { DummyResolverHook hook = new DummyResolverHook() { @Override @@ -211,12 +205,12 @@ public class ResolutionReportTest extends AbstractTest { // TODO Need to test both mandatory and optional triggers. private void assertResolutionDoesNotSucceed(ModuleContainer container, Collection<Module> modules) { - ModuleResolutionReport report = container.resolve(modules, true); + ResolutionReport report = container.resolve(modules, true); assertNotNull("Resolution should not have succeeded", report.getResolutionException()); } private void assertResolutionSucceeds(ModuleContainer container, Collection<Module> modules) { - ModuleResolutionReport report = container.resolve(modules, false); + ResolutionReport report = container.resolve(modules, false); assertNull("Unexpected resolution exception", report.getResolutionException()); } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java index 572053a5c..48e20cd58 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java @@ -20,6 +20,7 @@ import org.eclipse.osgi.container.ModuleContainerAdaptor.ContainerEvent; import org.eclipse.osgi.container.ModuleContainerAdaptor.ModuleEvent; import org.eclipse.osgi.container.builders.OSGiManifestBuilderFactory; import org.eclipse.osgi.container.namespaces.EclipsePlatformNamespace; +import org.eclipse.osgi.report.resolution.ResolutionReport; import org.eclipse.osgi.tests.container.dummys.*; import org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent; import org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent; @@ -196,7 +197,7 @@ public class TestModuleContainer extends AbstractTest { Module c7 = installDummyModule("c7_v1.MF", "c7", container); installDummyModule("c6_v1.MF", "c6", container); - ModuleResolutionReport report = container.resolve(Arrays.asList(c7), true); + ResolutionReport report = container.resolve(Arrays.asList(c7), true); Assert.assertNotNull("Expected a resolution exception", report.getResolutionException()); // Should resolve now diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java index 2c6fc83a1..5a8c272f1 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/core/runtime/adaptor/EclipseStarter.java @@ -20,7 +20,8 @@ import java.util.*; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import org.eclipse.core.runtime.internal.adaptor.*; -import org.eclipse.osgi.container.*; +import org.eclipse.osgi.container.Module; +import org.eclipse.osgi.container.ModuleRevision; import org.eclipse.osgi.container.namespaces.EquinoxModuleDataNamespace; import org.eclipse.osgi.framework.log.FrameworkLog; import org.eclipse.osgi.framework.log.FrameworkLogEntry; @@ -31,6 +32,7 @@ import org.eclipse.osgi.internal.location.EquinoxLocations; import org.eclipse.osgi.internal.location.LocationHelper; import org.eclipse.osgi.internal.messages.Msg; import org.eclipse.osgi.launch.Equinox; +import org.eclipse.osgi.report.resolution.ResolutionReport; import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.service.environment.EnvironmentInfo; import org.eclipse.osgi.service.runnable.ApplicationLauncher; @@ -378,7 +380,7 @@ public class EclipseStarter { return appLauncher.reStart(argument); } catch (Exception e) { if (log != null && context != null) { // context can be null if OSGi failed to launch (bug 151413) - ModuleResolutionReport report = context.getBundle().adapt(Module.class).getContainer().resolve(null, false); + ResolutionReport report = context.getBundle().adapt(Module.class).getContainer().resolve(null, false); for (Resource unresolved : report.getEntries().keySet()) { String bsn = ((ModuleRevision) unresolved).getSymbolicName(); FrameworkLogEntry logEntry = new FrameworkLogEntry(bsn != null ? bsn : EquinoxContainer.NAME, FrameworkLogEntry.WARNING, 0, Msg.Module_ResolveError + report.getResolutionReportMessage(unresolved), 1, null, null); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/Module.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/Module.java index bc21bbd3e..d4b00fc4c 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/Module.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/Module.java @@ -16,6 +16,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; import org.eclipse.osgi.container.ModuleContainerAdaptor.ModuleEvent; import org.eclipse.osgi.internal.messages.Msg; +import org.eclipse.osgi.report.resolution.ResolutionReport; import org.osgi.framework.*; import org.osgi.framework.startlevel.BundleStartLevel; import org.osgi.framework.wiring.BundleRevision; @@ -53,8 +54,7 @@ public abstract class Module implements BundleReference, BundleStartLevel, Compa TRANSIENT_IF_AUTO_START, /** * The module start operation that indicates the module is being started because of a - * lazy start trigger class load. This option must be used with the - * {@link StartOptions#TRANSIENT transient} options. + * lazy start trigger class load. */ LAZY_TRIGGER; @@ -400,7 +400,7 @@ public abstract class Module implements BundleReference, BundleStartLevel, Compa // bundles are started at the same time from different threads unlockStateChange(ModuleEvent.STARTED); lockedStarted = false; - ModuleResolutionReport report; + ResolutionReport report; try { inStartResolve.set(Boolean.TRUE); report = getRevisions().getContainer().resolve(Arrays.asList(this), true); @@ -600,7 +600,7 @@ public abstract class Module implements BundleReference, BundleStartLevel, Compa /** * Performs any work associated with starting a module. For example, * loading and calling start on an activator. - * @throws BundleException + * @throws BundleException if there was an exception starting the module */ protected void startWorker() throws BundleException { // Do nothing @@ -623,7 +623,9 @@ public abstract class Module implements BundleReference, BundleStartLevel, Compa } /** - * @throws BundleException + * Performs any work associated with stopping a module. For example, + * calling stop on an activator. + * @throws BundleException if there was an exception stopping the module */ protected void stopWorker() throws BundleException { // Do nothing @@ -656,7 +658,7 @@ public abstract class Module implements BundleReference, BundleStartLevel, Compa } /** - * The container is done with the revision and it has been complete removed. + * The container is done with the revision and it has been completely removed. * This method allows the resources behind the revision to be cleaned up. * @param revision the revision to clean up */ diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleCapability.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleCapability.java index f4b1cfd03..63e630486 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleCapability.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleCapability.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 IBM Corporation and others. + * Copyright (c) 2012, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -61,10 +61,18 @@ public final class ModuleCapability implements BundleCapability { return attributes; } + /** + * Only used by the system module for setting transient attributes associated + * with the {@link NativeNamespace osgi.native} namespace. + * @param transientAttrs + */ public void setTransientAttrs(Map<String, ?> transientAttrs) { if (this.transientAttrs == null) { throw new UnsupportedOperationException(namespace + ": namespace does not support transient attributes."); //$NON-NLS-1$ } + if (!(getResource().getRevisions().getModule() instanceof SystemModule)) { + throw new UnsupportedOperationException("Only allowed to set transient attributes for the system module: " + getResource()); //$NON-NLS-1$ + } this.transientAttrs.clear(); this.transientAttrs.putAll(transientAttrs); } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainer.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainer.java index adab408d9..f50f496dc 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainer.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainer.java @@ -30,6 +30,7 @@ import org.eclipse.osgi.internal.container.LockSet; import org.eclipse.osgi.internal.debug.Debug; import org.eclipse.osgi.internal.framework.EquinoxConfiguration; import org.eclipse.osgi.internal.messages.Msg; +import org.eclipse.osgi.report.resolution.ResolutionReport; import org.eclipse.osgi.report.resolution.ResolutionReport.Entry; import org.eclipse.osgi.service.debug.DebugOptions; import org.eclipse.osgi.util.NLS; @@ -91,7 +92,7 @@ public final class ModuleContainer { private final long moduleLockTimeout; /** - * Constructs a new container with the specified collision hook, resolver hook, resolver and module database. + * Constructs a new container with the specified adaptor, module database. * @param adaptor the adaptor for the container * @param moduledataBase the module database */ @@ -415,15 +416,15 @@ public final class ModuleContainer { * @see FrameworkWiring#resolveBundles(Collection) * @return A resolution report for the resolve operation */ - public ModuleResolutionReport resolve(Collection<Module> triggers, boolean triggersMandatory) { + public ResolutionReport resolve(Collection<Module> triggers, boolean triggersMandatory) { return resolve(triggers, triggersMandatory, false); } - private ModuleResolutionReport resolve(Collection<Module> triggers, boolean triggersMandatory, boolean restartTriggers) { + private ResolutionReport resolve(Collection<Module> triggers, boolean triggersMandatory, boolean restartTriggers) { if (isRefreshingSystemModule()) { return new ModuleResolutionReport(null, Collections.<Resource, List<Entry>> emptyMap(), new ResolutionException("Unable to resolve while shutting down the framework.")); //$NON-NLS-1$ } - ModuleResolutionReport report = null; + ResolutionReport report = null; do { try { report = resolveAndApply(triggers, triggersMandatory, restartTriggers); @@ -440,7 +441,7 @@ public final class ModuleContainer { return report; } - private ModuleResolutionReport resolveAndApply(Collection<Module> triggers, boolean triggersMandatory, boolean restartTriggers) { + private ResolutionReport resolveAndApply(Collection<Module> triggers, boolean triggersMandatory, boolean restartTriggers) { if (triggers == null) triggers = new ArrayList<Module>(0); Collection<ModuleRevision> triggerRevisions = new ArrayList<ModuleRevision>(triggers.size()); @@ -936,9 +937,11 @@ public final class ModuleContainer { * Refreshes the specified collection of modules. * @param initial the modules to refresh or {@code null} to refresh the * removal pending. + * @return a resolution report for the resolve operation that may have + * occurred during the refresh operation. * @see FrameworkWiring#refreshBundles(Collection, FrameworkListener...) */ - public ModuleResolutionReport refresh(Collection<Module> initial) { + public ResolutionReport refresh(Collection<Module> initial) { initial = initial == null ? null : new ArrayList<Module>(initial); Collection<Module> refreshTriggers = unresolve(initial); if (!isRefreshingSystemModule()) { diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainerAdaptor.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainerAdaptor.java index ced7cc585..080123363 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainerAdaptor.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleContainerAdaptor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 IBM Corporation and others. + * Copyright (c) 2012, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,8 +23,67 @@ import org.osgi.framework.hooks.resolver.ResolverHookFactory; * @since 3.10 */ public abstract class ModuleContainerAdaptor { + /** + * Event types that may be {@link #publishContainerEvent(ContainerEvent, Module, Throwable, FrameworkListener...) published} + * for a container. + * + */ public enum ContainerEvent { - REFRESH, START_LEVEL, STARTED, STOPPED, STOPPED_UPDATE, STOPPED_REFRESH, STOPPED_TIMEOUT, ERROR, WARNING, INFO + /** + * A container {@link ModuleContainer#refresh(java.util.Collection) refresh} operation has completed + */ + REFRESH, + + /** + * A container {@link ModuleContainer#getFrameworkStartLevel() start level} change has completed. + */ + START_LEVEL, + + /** + * The container has been started. + */ + STARTED, + + /** + * This event is returned by {@link SystemModule#waitForStop(long)} + * to indicate that the container has stopped. + */ + STOPPED, + + /** + * This event is returned by {@link SystemModule#waitForStop(long)} + * to indicate that the container has stopped because of an update + * operation. + */ + STOPPED_UPDATE, + + /** + * This event is returned by {@link SystemModule#waitForStop(long)} + * to indicate that the container has stopped because of an refresh + * operation. + */ + STOPPED_REFRESH, + + /** + * This event is returned by {@link SystemModule#waitForStop(long)} + * to indicate that the wait operation has timed out.. + */ + STOPPED_TIMEOUT, + + /** + * An event fired for an error condition. + */ + ERROR, + + /** + * An event fired for a warning condition. + */ + WARNING, + + /** + * An event fired for informational purposes only. + */ + INFO } /** diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java index 5482159f5..57ed77d82 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleDatabase.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 IBM Corporation and others. + * Copyright (c) 2012, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -131,6 +131,7 @@ public class ModuleDatabase { /** * Constructs a new empty database. + * @param adaptor the module container adaptor */ public ModuleDatabase(ModuleContainerAdaptor adaptor) { this.adaptor = adaptor; @@ -727,6 +728,7 @@ public class ModuleDatabase { } /** + * Acquires the read lock for this database. * @see ReadLock#lock() */ public final void readLock() { @@ -734,6 +736,7 @@ public class ModuleDatabase { } /** + * Acquires the write lock for this database. * Same as {@link WriteLock#lock()} except an illegal * state exception is thrown if the current thread holds * one or more read locks. @@ -751,6 +754,7 @@ public class ModuleDatabase { } /** + * Attempts to release the read lock for this database. * @see ReadLock#unlock() */ public final void readUnlock() { @@ -758,6 +762,7 @@ public class ModuleDatabase { } /** + * Attempts to release the write lock for this database. * @see WriteLock#unlock() */ public final void writeUnlock() { @@ -844,7 +849,7 @@ public class ModuleDatabase { /** * Loads information into this database from the input data stream. This data - * base must be empty and never been modified (the {@link #getRevisionsTimestamp() timestamp} is zero. + * base must be empty and never been modified (the {@link #getRevisionsTimestamp() timestamp} is zero). * All stored modules are loaded into this database. If the input stream contains * wiring then it will also be loaded into this database. * <p> diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleLoader.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleLoader.java index e0987234c..4437438a2 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleLoader.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleLoader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 IBM Corporation and others. + * Copyright (c) 2012, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,20 +13,25 @@ package org.eclipse.osgi.container; import java.net.URL; import java.util.Collection; import java.util.List; +import org.eclipse.osgi.container.Module.StartOptions; /** + * A module loader is what connects a {@link ModuleWiring} to a real classloader. * @since 3.10 */ -public interface ModuleLoader { +public abstract class ModuleLoader { /** - * - * @param path - * @param filePattern - * @param options - * @return TODO + * Returns entries in wiring this module loader + * is associated with. + * @param path The path name in which to look. + * @param filePattern The file name pattern for selecting entries in the + * specified path + * @param options The options for listing resource names. + * @return An unmodifiable list of URL objects for each matching entry, or + * an empty list if no matching entry could be found * @see ModuleWiring#findEntries(String, String, int) */ - public List<URL> findEntries(String path, String filePattern, int options); + protected abstract List<URL> findEntries(String path, String filePattern, int options); /** * @@ -36,17 +41,34 @@ public interface ModuleLoader { * @return TODO * @see ModuleWiring#listResources(String, String, int) */ - public Collection<String> listResources(String path, String filePattern, int options); + protected abstract Collection<String> listResources(String path, String filePattern, int options); /** - * - * @return TODO + * Returns the class loader for this module loader. A <code>null</code> + * value will be returned if this module loader is for a fragment. + * @return The class loader for this module loader. + * @see ModuleWiring#getClassLoader() */ - public ClassLoader getClassLoader(); + protected abstract ClassLoader getClassLoader(); - public boolean getAndSetTrigger(); + /** + * Is called by {@link Module#start(Module.StartOptions...)} when + * using the {@link StartOptions#LAZY_TRIGGER} option is used. + * @return false if the trigger was not previously set; otherwise + * true is returned + */ + protected abstract boolean getAndSetTrigger(); - public boolean isTriggerSet(); + /** + * Returns true if the lazy trigger is set for this module loader + * @return true if the lazy trigger is set for this module loader + */ + public abstract boolean isTriggerSet(); - public void loadFragments(Collection<ModuleRevision> fragments); + /** + * Dynamically loads fragment revisions to this already resolved + * module loader. + * @param fragments the fragments to load + */ + protected abstract void loadFragments(Collection<ModuleRevision> fragments); } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java index 359d9db75..eba7c0d90 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleResolutionReport.java @@ -22,11 +22,12 @@ import org.osgi.resource.*; import org.osgi.service.resolver.ResolutionException; /** + * A resolution report implementation used by the container for resolution operations. * @since 3.10 */ -public class ModuleResolutionReport implements ResolutionReport { +class ModuleResolutionReport implements ResolutionReport { - public static class Builder { + static class Builder { private final Map<Resource, List<Entry>> resourceToEntries = new HashMap<Resource, List<Entry>>(); public void addEntry(Resource resource, Entry.Type type, Object data) { @@ -43,7 +44,7 @@ public class ModuleResolutionReport implements ResolutionReport { } } - private static class EntryImpl implements Entry { + static class EntryImpl implements Entry { private final Object data; private final Type type; diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRevisionBuilder.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRevisionBuilder.java index 165d73b26..1c12b17e3 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRevisionBuilder.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRevisionBuilder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 IBM Corporation and others. + * Copyright (c) 2012, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRevisions.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRevisions.java index 4f0f6f853..a7cfa37b3 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRevisions.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleRevisions.java @@ -61,6 +61,11 @@ public final class ModuleRevisions implements BundleRevisions { } } + /** + * Same as {@link ModuleRevisions#getRevisions()} except it + * returns a list of {@link ModuleRevision}. + * @return the list of module revisions + */ public List<ModuleRevision> getModuleRevisions() { synchronized (monitor) { return new ArrayList<ModuleRevision>(revisions); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java index 62c989ae4..f4c5c5621 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/ModuleWiring.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 IBM Corporation and others. + * Copyright (c) 2012, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -374,6 +374,11 @@ public final class ModuleWiring implements BundleWiring { return substitutedPkgNames.contains(capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE)); } + /** + * Returns true if the specified package name has been substituted in this wiring + * @param packageName the package name to check + * @return true if the specified package name has been substituted in this wiring + */ public boolean isSubstitutedPackage(String packageName) { return substitutedPkgNames.contains(packageName); } @@ -399,6 +404,13 @@ public final class ModuleWiring implements BundleWiring { return true; } + /** + * Adds the {@link ModuleRevisionBuilder#getRequirements() requirements} from + * the specified builder to this wiring. The new requirements must be in the + * {@link PackageNamespace}. These requirements are transient + * and will not exist when loading up persistent wirings. + * @param builder the builder that defines the new dynamic imports. + */ public void addDynamicImports(ModuleRevisionBuilder builder) { List<GenericInfo> newImports = builder.getRequirements(); List<ModuleRequirement> newRequirements = new ArrayList<ModuleRequirement>(); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/SystemModule.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/SystemModule.java index 21a4db2ca..9c586109b 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/SystemModule.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/SystemModule.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 IBM Corporation and others. + * Copyright (c) 2012, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,10 +16,15 @@ import org.eclipse.osgi.container.ModuleContainer.ContainerStartLevel; import org.eclipse.osgi.container.ModuleContainerAdaptor.ContainerEvent; import org.eclipse.osgi.container.ModuleContainerAdaptor.ModuleEvent; import org.eclipse.osgi.internal.messages.Msg; +import org.eclipse.osgi.report.resolution.ResolutionReport; import org.osgi.framework.*; +import org.osgi.framework.launch.Framework; import org.osgi.service.resolver.ResolutionException; /** + * A special kind of module that represents the system module for the container. Additinal + * methods are available on the system module for operations that effect the whole container. + * For example, initializing the container, restarting and waiting for the container to stop. * @since 3.10 */ public abstract class SystemModule extends Module { @@ -29,6 +34,10 @@ public abstract class SystemModule extends Module { super(new Long(0), Constants.SYSTEM_BUNDLE_LOCATION, container, EnumSet.of(Settings.AUTO_START, Settings.USE_ACTIVATION_POLICY), new Integer(0)); } + /** + * Initializes the module container + * @throws BundleException if an exeption occurred while initializing + */ public final void init() throws BundleException { getRevisions().getContainer().checkAdminPermission(getBundle(), AdminPermission.EXECUTE); boolean lockedStarted = false; @@ -45,7 +54,7 @@ public abstract class SystemModule extends Module { // bundles are started at the same time from different threads unlockStateChange(ModuleEvent.STARTED); lockedStarted = false; - ModuleResolutionReport report; + ResolutionReport report; try { report = getRevisions().getContainer().resolve(Arrays.asList((Module) this), true); } finally { @@ -91,6 +100,14 @@ public abstract class SystemModule extends Module { } } + /** + * Waits until the module container has stopped. + * @param timeout The amount of time to wait. + * @return The container event indicated why the framework stopped + * or if there was a time out waiting for stop. + * @see Framework#waitForStop(long) + * @throws InterruptedException if the thread was interrupted while waiting + */ public ContainerEvent waitForStop(long timeout) throws InterruptedException { final boolean waitForever = timeout == 0; final long start = System.currentTimeMillis(); @@ -192,6 +209,11 @@ public abstract class SystemModule extends Module { notifyWaitForStop(containerEvent); } + /** + * Restarts the module container. + * @see Framework#update() + * @throws BundleException + */ public void update() throws BundleException { getContainer().checkAdminPermission(getBundle(), AdminPermission.LIFECYCLE); State previousState; diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/builders/OSGiManifestBuilderFactory.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/builders/OSGiManifestBuilderFactory.java index 843491409..9ba4e1442 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/builders/OSGiManifestBuilderFactory.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/builders/OSGiManifestBuilderFactory.java @@ -29,6 +29,7 @@ import org.osgi.framework.wiring.BundleRevision; import org.osgi.resource.Namespace; /** + * A factory for creating {@link ModuleRevisionBuilder}s based on OSGi bundle manifests. * @since 3.10 * @noinstantiate This class is not intended to be instantiated by clients. */ @@ -46,10 +47,30 @@ public final class OSGiManifestBuilderFactory { private static final Collection<String> SYSTEM_CAPABILITIES = Collections.unmodifiableCollection(Arrays.asList(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE, NativeNamespace.NATIVE_NAMESPACE)); private static final Collection<String> PROHIBITED_CAPABILITIES = Collections.unmodifiableCollection(Arrays.asList(IdentityNamespace.IDENTITY_NAMESPACE)); + /** + * Creates a builder for the specified bundle manifest + * @param manifest the bundle manifest + * @return a builder for the specified bundle manifest + * @throws BundleException if the bundle manifest is invalid + */ public static ModuleRevisionBuilder createBuilder(Map<String, String> manifest) throws BundleException { return createBuilder(manifest, null, null, null); } + /** + * Creates a builder for the specified bundle manifest. An alias can be supplied + * for the symbolic name. Also extra package exports and extra provided capabilities + * may be specified outside of the supplied manifest. This is useful for creating + * a builder for the system module which takes into account the configuration + * properties {@link Constants#FRAMEWORK_SYSTEMPACKAGES_EXTRA} and + * {@link Constants#FRAMEWORK_SYSTEMCAPABILITIES_EXTRA}. + * @param manifest the bundle manifest + * @param symbolicNameAlias the symbolic name alias. A <code>null</code> value is allowed. + * @param extraExports the extra package exports. A <code>null</code> value is allowed. + * @param extraCapabilities the extra proided capabilities. A <code>null</code> value is allowed. + * @return a builder for the specified bundle manifest + * @throws BundleException if the bundle manifest is invalid + */ public static ModuleRevisionBuilder createBuilder(Map<String, String> manifest, String symbolicNameAlias, String extraExports, String extraCapabilities) throws BundleException { ModuleRevisionBuilder builder = new ModuleRevisionBuilder(); @@ -572,7 +593,7 @@ public final class OSGiManifestBuilderFactory { // we look for the extension activator for fragments // probably should do this only for framework extensions, but there is no harm to check for others // it is only acted upon for framework extension fragments - activator = manifest.get(EquinoxModuleDataNamespace.EXTENSION_ACTIVATOR_HEADER); + activator = manifest.get(Constants.EXTENSION_BUNDLE_ACTIVATOR); } if (activator != null) { attributes.put(EquinoxModuleDataNamespace.CAPABILITY_ACTIVATOR, activator); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/namespaces/EquinoxModuleDataNamespace.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/namespaces/EquinoxModuleDataNamespace.java index 132a9546a..ed100699b 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/namespaces/EquinoxModuleDataNamespace.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/container/namespaces/EquinoxModuleDataNamespace.java @@ -69,11 +69,6 @@ public class EquinoxModuleDataNamespace extends Namespace { public static final String AUTOSTART_HEADER = "Eclipse-AutoStart"; //$NON-NLS-1$ /** - * The Equinox specific header that framework extension can used to specify an activator class. - */ - public static final String EXTENSION_ACTIVATOR_HEADER = "ExtensionBundle-Activator"; //$NON-NLS-1$ - - /** * Namespace name for equinox module data. Unlike typical name spaces * this namespace is not intended to be used as an attribute. */ diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java index 2da50f502..425363384 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java @@ -45,7 +45,7 @@ import org.osgi.framework.wiring.BundleWiring; * of a BundleLoader unless it is necessary. * @see org.eclipse.osgi.internal.loader.BundleLoaderSources */ -public class BundleLoader implements ModuleLoader { +public class BundleLoader extends ModuleLoader { public final static String DEFAULT_PACKAGE = "."; //$NON-NLS-1$ public final static String JAVA_PACKAGE = "java."; //$NON-NLS-1$ @@ -241,7 +241,7 @@ public class BundleLoader implements ModuleLoader { } @Override - public void loadFragments(Collection<ModuleRevision> fragments) { + protected void loadFragments(Collection<ModuleRevision> fragments) { synchronized (classLoaderMonitor) { addFragmentExports(wiring.getModuleCapabilities(PackageNamespace.PACKAGE_NAMESPACE)); loadClassLoaderFragments(fragments); @@ -277,7 +277,7 @@ public class BundleLoader implements ModuleLoader { } @Override - public ClassLoader getClassLoader() { + protected ClassLoader getClassLoader() { return getModuleClassLoader(); } @@ -663,7 +663,7 @@ public class BundleLoader implements ModuleLoader { } @Override - public Collection<String> listResources(String path, String filePattern, int options) { + protected Collection<String> listResources(String path, String filePattern, int options) { String pkgName = getResourcePackageName(path.endsWith("/") ? path : path + '/'); //$NON-NLS-1$ if ((path.length() > 1) && (path.charAt(0) == '/')) /* if name has a leading slash */ path = path.substring(1); /* remove leading slash before search */ @@ -728,7 +728,7 @@ public class BundleLoader implements ModuleLoader { } @Override - public List<URL> findEntries(String path, String filePattern, int options) { + protected List<URL> findEntries(String path, String filePattern, int options) { return getModuleClassLoader().findEntries(path, filePattern, options); } @@ -1108,7 +1108,7 @@ public class BundleLoader implements ModuleLoader { } @Override - public boolean getAndSetTrigger() { + protected boolean getAndSetTrigger() { return triggerClassLoaded.getAndSet(true); } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/FragmentLoader.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/FragmentLoader.java index a1346241a..91e764bd3 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/FragmentLoader.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/FragmentLoader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation and others. + * Copyright (c) 2013, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,25 +15,25 @@ import java.util.*; import org.eclipse.osgi.container.ModuleLoader; import org.eclipse.osgi.container.ModuleRevision; -public class FragmentLoader implements ModuleLoader { +public class FragmentLoader extends ModuleLoader { @Override - public List<URL> findEntries(String path, String filePattern, int options) { + protected List<URL> findEntries(String path, String filePattern, int options) { return Collections.emptyList(); } @Override - public Collection<String> listResources(String path, String filePattern, int options) { + protected Collection<String> listResources(String path, String filePattern, int options) { return Collections.emptyList(); } @Override - public ClassLoader getClassLoader() { + protected ClassLoader getClassLoader() { return null; } @Override - public boolean getAndSetTrigger() { + protected boolean getAndSetTrigger() { // nothing to do here return false; } @@ -45,7 +45,7 @@ public class FragmentLoader implements ModuleLoader { } @Override - public void loadFragments(Collection<ModuleRevision> fragments) { + protected void loadFragments(Collection<ModuleRevision> fragments) { // do nothing } |