01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.testplugin;
11:
12: import java.io.File;
13: import java.io.IOException;
14: import java.net.URL;
15:
16: import org.eclipse.core.runtime.CoreException;
17: import org.eclipse.core.runtime.FileLocator;
18: import org.eclipse.core.runtime.IPath;
19: import org.eclipse.core.runtime.IStatus;
20: import org.eclipse.core.runtime.MultiStatus;
21: import org.eclipse.core.runtime.Plugin;
22: import org.eclipse.core.runtime.Status;
23:
24: import org.eclipse.core.resources.IWorkspace;
25: import org.eclipse.core.resources.IWorkspaceDescription;
26: import org.eclipse.core.resources.ResourcesPlugin;
27:
28: public class JavaTestPlugin extends Plugin {
29:
30: private static JavaTestPlugin fgDefault;
31:
32: public JavaTestPlugin() {
33: fgDefault = this ;
34: }
35:
36: public static JavaTestPlugin getDefault() {
37: return fgDefault;
38: }
39:
40: public static IWorkspace getWorkspace() {
41: return ResourcesPlugin.getWorkspace();
42: }
43:
44: public static void enableAutobuild(boolean enable)
45: throws CoreException {
46: // disable auto build
47: IWorkspace workspace = JavaTestPlugin.getWorkspace();
48: IWorkspaceDescription desc = workspace.getDescription();
49: desc.setAutoBuilding(enable);
50: workspace.setDescription(desc);
51: }
52:
53: public File getFileInPlugin(IPath path) throws CoreException {
54: try {
55: URL installURL = new URL(getBundle().getEntry("/"), path
56: .toString());
57: URL localURL = FileLocator.toFileURL(installURL);
58: return new File(localURL.getFile());
59: } catch (IOException e) {
60: throw new CoreException(new Status(IStatus.ERROR,
61: getPluginId(), IStatus.ERROR, e.getMessage(), e));
62: }
63: }
64:
65: public static String getPluginId() {
66: return "org.eclipse.jdt.ui.tests";
67: }
68:
69: public static void log(IStatus status) {
70: getDefault().getLog().log(status);
71: }
72:
73: public static void logErrorMessage(String message) {
74: log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR,
75: message, null));
76: }
77:
78: public static void logErrorStatus(String message, IStatus status) {
79: if (status == null) {
80: logErrorMessage(message);
81: return;
82: }
83: MultiStatus multi = new MultiStatus(getPluginId(),
84: IStatus.ERROR, message, null);
85: multi.add(status);
86: log(multi);
87: }
88:
89: public static void log(Throwable e) {
90: log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, e
91: .getMessage(), e)); //$NON-NLS-1$
92: }
93:
94: }
|