| package org.eclipse.ptp.rdt.sync.git.core.tests; |
| |
| import org.osgi.framework.Bundle; |
| import org.osgi.framework.BundleActivator; |
| import org.osgi.framework.BundleContext; |
| //http://wiki.eclipse.org/Eclipse_Plug-in_Development_FAQ#How_do_I_read_from_a_file_that_I.27ve_included_in_my_bundle.2Fplug-in.3F |
| //your BundleActivator implementation will probably look something |
| //like the following |
| import org.osgi.framework.ServiceReference; |
| |
| public class Activator implements BundleActivator { |
| private static Activator instance; |
| |
| private Bundle bundle; |
| |
| public void start(BundleContext context) throws Exception { |
| instance = this; |
| bundle = context.getBundle(); |
| } |
| |
| public void stop(BundleContext context) throws Exception { |
| instance = null; |
| } |
| |
| public static Activator getDefault() { |
| return instance; |
| } |
| |
| public Bundle getBundle() { |
| return bundle; |
| } |
| |
| /** |
| * Return the OSGi service with the given service interface. |
| * |
| * @param service service interface |
| * @return the specified service or null if it's not registered |
| */ |
| public static <T> T getService(Class<T> service) { |
| BundleContext context = instance.getBundle().getBundleContext(); |
| ServiceReference<T> ref = context.getServiceReference(service); |
| return ref != null ? context.getService(ref) : null; |
| } |
| } |