diff options
author | Thomas Watson | 2019-05-17 13:09:03 +0000 |
---|---|---|
committer | Thomas Watson | 2019-05-17 13:09:03 +0000 |
commit | e54512c98f6a448fad797d66d5e7a1f88cbc8403 (patch) | |
tree | 415eca1b13c2544e681cd89e53a273dd5990baaf | |
parent | 922d596b4ac992de19fb8ea8a63fec3010c8a6ec (diff) | |
download | rt.equinox.framework-e54512c98f6a448fad797d66d5e7a1f88cbc8403.tar.gz rt.equinox.framework-e54512c98f6a448fad797d66d5e7a1f88cbc8403.tar.xz rt.equinox.framework-e54512c98f6a448fad797d66d5e7a1f88cbc8403.zip |
Bug 547431 - PackageAdminImpl doesn't use the new FrameworkUtilHelperS4_12_0_RC2S4_12_0_RC1aS4_12_0_RC1S4_12_0_M3R4_12I20190605-1800I20190605-0600I20190604-1800I20190604-0600I20190603-1800I20190603-0600I20190602-1800I20190602-0600I20190601-1800I20190531-1800I20190531-0245I20190529-2005I20190529-1800I20190529-0600I20190528-1800I20190528-0915I20190528-0850I20190528-0600I20190527-1805I20190527-0600I20190526-1800I20190526-0600I20190525-1800I20190525-0600I20190524-1800I20190524-0135I20190522-1800I20190522-0600I20190521-1800I20190521-0600I20190520-1805I20190520-0600I20190519-1800I20190518-1800I20190517-1800R4_12_maintenance
Change-Id: I98ab87486d3c8066f86609fc4d2959d5df1325c0
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
2 files changed, 10 insertions, 9 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java index 490044def..78aba2011 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java @@ -25,12 +25,12 @@ import org.eclipse.osgi.internal.hookregistry.HookRegistry; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.eclipse.osgi.tests.bundles.SystemBundleTests; import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; import org.osgi.framework.launch.Framework; import org.osgi.framework.wiring.BundleRevision; import org.osgi.resource.Capability; +import org.osgi.service.packageadmin.PackageAdmin; public class StorageHookTests extends AbstractFrameworkHookTests { private static final String TEST_BUNDLE = "test"; @@ -222,10 +222,14 @@ public class StorageHookTests extends AbstractFrameworkHookTests { assertEquals("Wrong number of capabilities.", 1, testCaps.size()); } + @SuppressWarnings("deprecation") public void testFrameworkUtilHelper() throws Exception { initAndStartFramework(); Class<?> frameworkUtilClass = classLoader.loadClass("org.osgi.framework.FrameworkUtil"); - Bundle b = (Bundle) frameworkUtilClass.getMethod("getBundle", Class.class).invoke(null, BundleContext.class); + Bundle b = (Bundle) frameworkUtilClass.getMethod("getBundle", Class.class).invoke(null, String.class); + assertEquals("Wrong bundle found.", framework.getBundleContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION), b); + PackageAdmin packageAdmin = framework.getBundleContext().getService(framework.getBundleContext().getServiceReference(PackageAdmin.class)); + b = packageAdmin.getBundle(String.class); assertEquals("Wrong bundle found.", framework.getBundleContext().getBundle(Constants.SYSTEM_BUNDLE_LOCATION), b); } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java index 3a9fcd420..bb6c2f254 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java @@ -35,8 +35,8 @@ import org.eclipse.osgi.internal.container.Capabilities; import org.eclipse.osgi.internal.container.InternalUtils; import org.eclipse.osgi.internal.framework.EquinoxContainer; import org.osgi.framework.Bundle; -import org.osgi.framework.BundleReference; import org.osgi.framework.Constants; +import org.osgi.framework.FrameworkUtil; import org.osgi.framework.Version; import org.osgi.framework.VersionRange; import org.osgi.framework.namespace.BundleNamespace; @@ -298,14 +298,11 @@ public class PackageAdminImpl implements PackageAdmin { } Bundle getBundlePriv(Class<?> clazz) { - ClassLoader cl = clazz.getClassLoader(); - if (cl instanceof BundleReference) { - return ((BundleReference) cl).getBundle(); - } - if (cl == getClass().getClassLoader()) { + Bundle b = FrameworkUtil.getBundle(clazz); + if (b == null && clazz.getClassLoader() == getClass().getClassLoader()) { return container.getModule(0).getBundle(); } - return null; + return b; } @Override |