package mit.edu.concurrencyrefactorings.tests; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceDescription; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; /** * The activator class controls the plug-in life cycle */ public class Activator extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "mit.edu.concurrencyRefactorings.tests"; // The shared instance private static Activator plugin; /** * The constructor */ public Activator() { } /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } /** * Returns the shared instance * * @return the shared instance */ public static Activator getDefault() { return plugin; } public static IWorkspace getWorkspace() { return ResourcesPlugin.getWorkspace(); } public static void enableAutobuild(boolean enable) throws CoreException { // disable auto build IWorkspace workspace= getWorkspace(); IWorkspaceDescription desc= workspace.getDescription(); desc.setAutoBuilding(enable); workspace.setDescription(desc); } public File getFileInPlugin(IPath path) throws CoreException { try { URL installURL= new URL(getBundle().getEntry("/"), path.toString()); URL localURL= FileLocator.toFileURL(installURL); return new File(localURL.getFile()); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, e.getMessage(), e)); } } public static String getPluginId() { return PLUGIN_ID; } public static void log(IStatus status) { getDefault().getLog().log(status); } public static void logErrorMessage(String message) { log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, message, null)); } public static void logErrorStatus(String message, IStatus status) { if (status == null) { logErrorMessage(message); return; } MultiStatus multi= new MultiStatus(getPluginId(), IStatus.ERROR, message, null); multi.add(status); log(multi); } public static void log(Throwable e) { log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, e.getMessage(), e)); //$NON-NLS-1$ } public InputStream getTestResourceStream(String fileName) throws IOException { IPath path= new Path("resources").append(fileName); URL url= new URL(getBundle().getEntry("/"), path.toString()); return url.openStream(); } }