import org.apache.log4j.Logger;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.PackageAdmin;
/**
* The activator class controls the plug-in life cycle
// The shared instance
private static TaxonomicEditorPlugin plugin;
+
+ private PackageAdmin packageAdmin;
+
+ private ServiceReference packageAdminRef;
+
+ private BundleContext bundleContext;
/**
* The constructor
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+
+ bundleContext = context;
+
+ // this should enable automatic updating. Not working at the moment
+ packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
+ packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
+
+ // XXX start up the p2 infrastructure. Normally the p2 UI class library does
+ // this, but we are running without UI.
+ getBundle("org.eclipse.equinox.p2.exemplarysetup").start(Bundle.START_TRANSIENT); //$NON-NLS-1$
+ getBundle("org.eclipse.equinox.frameworkadmin.equinox").start(Bundle.START_TRANSIENT); //$NON-NLS-1$
+ getBundle("org.eclipse.equinox.simpleconfigurator.manipulator").start(Bundle.START_TRANSIENT); //$NON-NLS-1$
+
logger.debug("Taxonomic Editor started.");
}
+ private Bundle getBundle(String symbolicName) {
+ if (packageAdmin == null)
+ return null;
+ Bundle[] bundles = packageAdmin.getBundles(symbolicName, 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;
+ }
+
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)