Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2019-05-17 09:09:03 -0400
committerThomas Watson2019-05-17 09:09:03 -0400
commite54512c98f6a448fad797d66d5e7a1f88cbc8403 (patch)
tree415eca1b13c2544e681cd89e53a273dd5990baaf
parent922d596b4ac992de19fb8ea8a63fec3010c8a6ec (diff)
downloadrt.equinox.framework-I20190604-1800.tar.gz
rt.equinox.framework-I20190604-1800.tar.xz
rt.equinox.framework-I20190604-1800.zip
Change-Id: I98ab87486d3c8066f86609fc4d2959d5df1325c0 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java8
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java11
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

Back to the top