Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java')
-rw-r--r--bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java
new file mode 100644
index 00000000..a72f261a
--- /dev/null
+++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java
@@ -0,0 +1,29 @@
+package org.eclipse.e4.tools.compat.internal;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+@SuppressWarnings("deprecation")
+public class Util {
+ public static Bundle getBundle(String bundleName) {
+ final Bundle bundle = FrameworkUtil.getBundle(Util.class);
+ final BundleContext ctx = bundle.getBundleContext();
+ final ServiceReference<PackageAdmin> ref = bundle.getBundleContext().getServiceReference(
+ PackageAdmin.class);
+ final PackageAdmin bundleAdmin = ctx.getService(ref);
+ final Bundle[] bundles = bundleAdmin.getBundles(bundleName, null);
+ if (bundles == null) {
+ return null;
+ }
+ // Return the first bundle that is not installed or uninstalled
+ for (int i = 0; i < bundles.length; i++) {
+ if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
+ return bundles[i];
+ }
+ }
+ return null;
+ }
+}

Back to the top