diff options
author | Anjum Fatima | 2020-01-21 20:41:04 +0000 |
---|---|---|
committer | Anjum Fatima | 2020-01-21 21:33:14 +0000 |
commit | 703c3f5583fedcb1efdbea652ba95c0c0d98b272 (patch) | |
tree | bd72a2cc521c1f72f1e88802f71b742fbd693718 | |
parent | ba0afe2be6d07f1791f4a592c697eb549b931d1b (diff) | |
download | rt.equinox.framework-703c3f5583fedcb1efdbea652ba95c0c0d98b272.tar.gz rt.equinox.framework-703c3f5583fedcb1efdbea652ba95c0c0d98b272.tar.xz rt.equinox.framework-703c3f5583fedcb1efdbea652ba95c0c0d98b272.zip |
Bug 552573: Reverse the order of the BundleActivators stop() in the
framework implementation which keeps the track of BundleActivators.
Change-Id: I37142e7f9354861259338a87f7964eb41970f421
Signed-off-by: Anjum Fatima <anjum.eclipse@gmail.com>
12 files changed, 257 insertions, 5 deletions
diff --git a/bundles/org.eclipse.osgi.tests/.classpath b/bundles/org.eclipse.osgi.tests/.classpath index c1b87a66f..dbab082d2 100644 --- a/bundles/org.eclipse.osgi.tests/.classpath +++ b/bundles/org.eclipse.osgi.tests/.classpath @@ -112,6 +112,7 @@ <classpathentry kind="src" output="bundle_tests/geturl" path="bundles_src/geturl"/> <classpathentry kind="src" output="bundle_tests/test.bug375784" path="bundles_src/test.bug375784"/> <classpathentry kind="src" output="bundle_tests/storage.hooks.a" path="bundles_src/storage.hooks.a"/> + <classpathentry kind="src" output="bundle_tests/activator.hooks.a" path="bundles_src/activator.hooks.a"/> <classpathentry kind="src" output="bundle_tests/test.bug412228" path="bundles_src/test.bug412228"/> <classpathentry kind="src" output="bundle_tests/test.uninstall.start1" path="bundles_src/test.uninstall.start1"/> <classpathentry kind="src" output="bundle_tests/test.uninstall.start2" path="bundles_src/test.uninstall.start2"/> diff --git a/bundles/org.eclipse.osgi.tests/build.properties b/bundles/org.eclipse.osgi.tests/build.properties index b5f9ec757..985449baa 100644 --- a/bundles/org.eclipse.osgi.tests/build.properties +++ b/bundles/org.eclipse.osgi.tests/build.properties @@ -239,6 +239,8 @@ source.bundle_tests/test.bug375784.jar = bundles_src/test.bug306181b/ manifest.bundle_tests/test.bug375784.jar = META-INF/MANIFEST.MF source.bundle_tests/storage.hooks.a.jar = bundles_src/storage.hooks.a/ manifest.bundle_tests/storage.hooks.a.jar = META-INF/MANIFEST.MF +source.bundle_tests/activator.hooks.a.jar = bundles_src/activator.hooks.a/ +manifest.bundle_tests/activator.hooks.a.jar = META-INF/MANIFEST.MF source.bundle_tests/test.bug412228.jar = bundles_src/test.bug412228/ manifest.bundle_tests/test.bug412228.jar = META-INF/MANIFEST.MF source.bundle_tests/test.uninstall.start1.jar = bundles_src/test.uninstall.start1/ @@ -386,6 +388,7 @@ jars.compile.order = bundle_tests/ext.framework.b.jar,\ bundle_tests/geturl.jar,\ bundle_tests/test.bug375784.jar,\ bundle_tests/storage.hooks.a.jar,\ + bundle_tests/activator.hooks.a.jar,\ bundle_tests/test.plugins.a.jar,\ bundle_tests/test.plugins.b.jar,\ bundle_tests/test.plugins.c.jar,\ diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/META-INF/MANIFEST.MF new file mode 100644 index 000000000..9ced5b560 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: activator.hooks.a diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator1.java b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator1.java new file mode 100644 index 000000000..1c1057fe0 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator1.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.osgi.tests.hooks.framework.activator.a; + +import java.util.List; +import org.eclipse.osgi.internal.hookregistry.ActivatorHookFactory; +import org.eclipse.osgi.internal.hookregistry.HookConfigurator; +import org.eclipse.osgi.internal.hookregistry.HookRegistry; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class TestHookConfigurator1 implements HookConfigurator { + + public static volatile List<String> events; + + public void addHooks(HookRegistry hookRegistry) { + hookRegistry.addActivatorHookFactory(new ActivatorHookFactory() { + + @Override + public BundleActivator createActivator() { + return new BundleActivator() { + @Override + public void start(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK1 STARTED"); + } + } + + @Override + public void stop(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK1 STOPPED"); + } + } + }; + } + }); + } + +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator2.java b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator2.java new file mode 100644 index 000000000..b9724a59c --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator2.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.osgi.tests.hooks.framework.activator.a; + +import java.util.List; +import org.eclipse.osgi.internal.hookregistry.ActivatorHookFactory; +import org.eclipse.osgi.internal.hookregistry.HookConfigurator; +import org.eclipse.osgi.internal.hookregistry.HookRegistry; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class TestHookConfigurator2 implements HookConfigurator { + public static volatile List<String> events; + + @Override + public void addHooks(HookRegistry hookRegistry) { + hookRegistry.addActivatorHookFactory(new ActivatorHookFactory() { + + @Override + public BundleActivator createActivator() { + return new BundleActivator() { + @Override + public void start(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK2 STARTED"); + } + } + + @Override + public void stop(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK2 STOPPED"); + } + } + }; + } + }); + + } +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator3.java b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator3.java new file mode 100644 index 000000000..85e2bfec3 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/activator.hooks.a/org/eclipse/osgi/tests/hooks/framework/activator/a/TestHookConfigurator3.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.osgi.tests.hooks.framework.activator.a; + +import java.util.List; +import org.eclipse.osgi.internal.hookregistry.ActivatorHookFactory; +import org.eclipse.osgi.internal.hookregistry.HookConfigurator; +import org.eclipse.osgi.internal.hookregistry.HookRegistry; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class TestHookConfigurator3 implements HookConfigurator { + public static volatile List<String> events; + + @Override + public void addHooks(HookRegistry hookRegistry) { + hookRegistry.addActivatorHookFactory(new ActivatorHookFactory() { + + @Override + public BundleActivator createActivator() { + return new BundleActivator() { + @Override + public void start(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK3 STARTED"); + } + } + + @Override + public void stop(BundleContext context) throws Exception { + if (events != null) { + events.add("HOOK3 STOPPED"); + } + } + }; + } + }); + + } +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/ext.framework.a.importer/ext/framework/a/importer/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/ext.framework.a.importer/ext/framework/a/importer/Activator.java index e85f33529..367c27c11 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/ext.framework.a.importer/ext/framework/a/importer/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/ext.framework.a.importer/ext/framework/a/importer/Activator.java @@ -14,9 +14,12 @@ package ext.framework.a.importer; import ext.framework.a.FrameworkExtTest; -import java.io.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.URL; import org.eclipse.osgi.tests.bundles.AbstractBundleTests; +import org.eclipse.osgi.tests.bundles.ExtensionBundleTests; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -25,6 +28,7 @@ public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { AbstractBundleTests.simpleResults.addEvent(new FrameworkExtTest().testIt("success")); //$NON-NLS-1$ AbstractBundleTests.simpleResults.addEvent(getURLContent(this.getClass().getResource("/ext/framework/a/fwkresource.txt"))); //$NON-NLS-1$ + ExtensionBundleTests.events.add(context.getBundle().getSymbolicName() + " STARTED"); } private String getURLContent(URL resource) throws IOException { @@ -37,7 +41,7 @@ public class Activator implements BundleActivator { } public void stop(BundleContext context) throws Exception { - // nothing + ExtensionBundleTests.events.add(context.getBundle().getSymbolicName() + " STOPPED"); } } diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/ext.framework.a.requires/ext/framework/a/requires/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/ext.framework.a.requires/ext/framework/a/requires/Activator.java index 09a88fdb6..7367f0a25 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/ext.framework.a.requires/ext/framework/a/requires/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/ext.framework.a.requires/ext/framework/a/requires/Activator.java @@ -14,9 +14,12 @@ package ext.framework.a.requires; import ext.framework.a.FrameworkExtTest; -import java.io.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.URL; import org.eclipse.osgi.tests.bundles.AbstractBundleTests; +import org.eclipse.osgi.tests.bundles.ExtensionBundleTests; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -25,6 +28,7 @@ public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { AbstractBundleTests.simpleResults.addEvent(new FrameworkExtTest().testIt("success")); //$NON-NLS-1$ AbstractBundleTests.simpleResults.addEvent(getURLContent(this.getClass().getResource("/ext/framework/a/fwkresource.txt"))); //$NON-NLS-1$ + ExtensionBundleTests.events.add(context.getBundle().getSymbolicName() + " STARTED"); } private String getURLContent(URL resource) throws IOException { @@ -37,7 +41,7 @@ public class Activator implements BundleActivator { } public void stop(BundleContext context) throws Exception { - // nothing + ExtensionBundleTests.events.add(context.getBundle().getSymbolicName() + " STOPPED"); } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ExtensionBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ExtensionBundleTests.java index b94c08db9..fb2953472 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ExtensionBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ExtensionBundleTests.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.osgi.tests.bundles; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import junit.framework.Test; import junit.framework.TestSuite; @@ -28,6 +30,8 @@ public class ExtensionBundleTests extends AbstractBundleTests { return new TestSuite(ExtensionBundleTests.class); } + public static List<String> events = new ArrayList<>(); + public void testFrameworkExtension01() throws Exception { Bundle fwkext = installer.installBundle("ext.framework.a", false); //$NON-NLS-1$ Bundle importer = installer.installBundle("ext.framework.a.importer"); //$NON-NLS-1$ @@ -84,4 +88,28 @@ public class ExtensionBundleTests extends AbstractBundleTests { BundleWire eeWire = wiring.getRequiredWires(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE).get(0); assertEquals("Wrong provider for osgi.ee: " + eeWire.getProvider().getBundle(), 0, eeWire.getProvider().getBundle().getBundleId()); } + + public void testActivatorOrder() throws Exception { + Bundle b = installer.installBundle("ext.framework.a", false); + Bundle bImp = installer.installBundle("ext.framework.a.importer"); + Bundle bReq = installer.installBundle("ext.framework.a.requires"); + installer.resolveBundles(new Bundle[] {b, bImp, bReq}); + + try { + bImp.start(); + bReq.start(); + } finally { + installer.uninstallAllBundles(); + } + List<String> expectedEvents = Arrays.asList(bImp.getSymbolicName() + " STARTED", bReq.getSymbolicName() + " STARTED", bReq.getSymbolicName() + " STOPPED", bImp.getSymbolicName() + " STOPPED"); + assertEquals("Expected number of events not found", expectedEvents.size(), events.size()); + for (int i = 0; i < events.size(); i++) { + assertEquals("Expected event not found", expectedEvents.get(i), events.get(i)); + } + } + + public void tearDown() throws Exception { + super.tearDown(); + events.clear(); + } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ActivatorOrderTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ActivatorOrderTest.java new file mode 100644 index 000000000..1261d26bb --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ActivatorOrderTest.java @@ -0,0 +1,53 @@ +package org.eclipse.osgi.tests.hooks.framework; + +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import org.eclipse.osgi.internal.hookregistry.HookRegistry; +import org.eclipse.osgi.tests.OSGiTestsActivator; +import org.osgi.framework.Constants; +import org.osgi.framework.launch.Framework; + +public class ActivatorOrderTest extends AbstractFrameworkHookTests { + + private Framework framework; + private static final String HOOK_CONFIGURATOR_BUNDLE = "activator.hooks.a"; + private static final String HOOK_CONFIGURATOR_CLASS1 = "org.eclipse.osgi.tests.hooks.framework.activator.a.TestHookConfigurator1"; + private static final String HOOK_CONFIGURATOR_CLASS2 = "org.eclipse.osgi.tests.hooks.framework.activator.a.TestHookConfigurator2"; + private static final String HOOK_CONFIGURATOR_CLASS3 = "org.eclipse.osgi.tests.hooks.framework.activator.a.TestHookConfigurator3"; + + @Override + protected void setUp() throws Exception { + super.setUp(); + String loc = bundleInstaller.getBundleLocation(HOOK_CONFIGURATOR_BUNDLE); + loc = loc.substring(loc.indexOf("file:")); + classLoader.addURL(new URL(loc)); + File file = OSGiTestsActivator.getContext().getDataFile(getName()); + HashMap<String, String> configuration = new HashMap<>(); + configuration.put(Constants.FRAMEWORK_STORAGE, file.getAbsolutePath()); + configuration.put(HookRegistry.PROP_HOOK_CONFIGURATORS, HOOK_CONFIGURATOR_CLASS1 + "," + HOOK_CONFIGURATOR_CLASS2 + "," + HOOK_CONFIGURATOR_CLASS3); + + framework = createFramework(configuration); + } + + public void testActivatorOrder() throws Exception { + List<String> actualEvents = new ArrayList<>(); + Class<?> clazz1 = classLoader.loadClass(HOOK_CONFIGURATOR_CLASS1); + clazz1.getField("events").set(null, actualEvents); + Class<?> clazz2 = classLoader.loadClass(HOOK_CONFIGURATOR_CLASS2); + clazz2.getField("events").set(null, actualEvents); + Class<?> clazz3 = classLoader.loadClass(HOOK_CONFIGURATOR_CLASS3); + clazz3.getField("events").set(null, actualEvents); + + List<String> expectedEvents = Arrays.asList("HOOK1 STARTED", "HOOK2 STARTED", "HOOK3 STARTED", "HOOK3 STOPPED", "HOOK2 STOPPED", "HOOK1 STOPPED"); + + initAndStart(framework); + stop(framework); + assertEquals("Activator order not as expected", expectedEvents, actualEvents); + + } + +} diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AllFrameworkHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AllFrameworkHookTests.java index d86f3efd9..1eeaacc46 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AllFrameworkHookTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AllFrameworkHookTests.java @@ -25,6 +25,7 @@ public class AllFrameworkHookTests { suite.addTest(new TestSuite(ContextFinderTests.class)); suite.addTest(new TestSuite(DevClassPathWithExtensionTests.class)); suite.addTest(new TestSuite(EmbeddedEquinoxWithURLInClassLoadTests.class)); + suite.addTest(new TestSuite(ActivatorOrderTest.class)); return suite; } } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java index e21515254..f4bddd5c5 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/FrameworkExtensionInstaller.java @@ -244,7 +244,9 @@ public class FrameworkExtensionInstaller { current = new ArrayMap<>(hookActivators.getKeys(), hookActivators.getValues()); hookActivators.clear(); } - for (BundleActivator activator : current) { + // indexing into the current collection the hard way to reverse de-activation + for (int i = current.getKeys().size() - 1; i >= 0; i--) { + BundleActivator activator = current.getKey(i); try { activator.stop(context); } catch (Exception e) { |