blob: 20799ce10727f59daf4bff602c14118cbb33ec99 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.testplugin;
import java.io.File;
import java.io.IOException;
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.IPluginDescriptor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
public class JavaTestPlugin extends Plugin {
private static JavaTestPlugin fgDefault;
public JavaTestPlugin(IPluginDescriptor descriptor) {
super(descriptor);
fgDefault= this;
}
public static JavaTestPlugin getDefault() {
return fgDefault;
}
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
public static void enableAutobuild(boolean enable) throws CoreException {
// disable auto build
IWorkspace workspace= JavaTestPlugin.getWorkspace();
IWorkspaceDescription desc= workspace.getDescription();
desc.setAutoBuilding(enable);
workspace.setDescription(desc);
}
public File getFileInPlugin(IPath path) {
try {
URL installURL= new URL(getDescriptor().getInstallURL(), path.toString());
URL localURL= Platform.asLocalURL(installURL);
return new File(localURL.getFile());
} catch (IOException e) {
log(e);
try {
URL installURL= new URL(getBundle().getEntry("/"), path.toString());
URL localURL= FileLocator.toFileURL(installURL);
return new File(localURL.getFile());
} catch (IOException e2) {
log(e2);
throw new RuntimeException(e2);
}
}
}
public static String getPluginId() {
return getDefault().getDescriptor().getUniqueIdentifier();
}
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$
}
}