blob: 4a7bd5a69920fe14a6dca802f7480f87f6446f8e [file] [log] [blame]
package org.eclipse.remote.internal.jsch.core;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.jsch.core.IJSchService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends Plugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.remote.jsch.core"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
/**
* Get unique identifier
*
* @return
* @since 5.0
*/
public static String getUniqueIdentifier() {
if (getDefault() == null) {
return PLUGIN_ID;
}
return getDefault().getBundle().getSymbolicName();
}
/**
* Logs the specified status with this plug-in's log.
*
* @param status
* status to log
*/
public static void log(IStatus status) {
getDefault().getLog().log(status);
}
/**
* Logs an internal error with the specified message.
*
* @param message
* the error message to log
*/
public static void log(String message) {
log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, message, null));
}
/**
* Logs an internal error with the specified throwable
*
* @param e
* the exception to be logged
*/
public static void log(Throwable e) {
log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, e.getMessage(), e));
}
private IJSchService fJSchService;
/**
* The constructor
*/
public Activator() {
}
/**
* 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 = plugin.getBundle().getBundleContext();
ServiceReference<T> ref = context.getServiceReference(service);
return ref != null ? context.getService(ref) : null;
}
public IJSchService getService() {
return fJSchService;
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
ServiceReference<IJSchService> reference = context.getServiceReference(IJSchService.class);
fJSchService = context.getService(reference);
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
}