comparison org.eclipse.equinox.common/src/org/eclipse/core/runtime/SafeRunner.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children bbe49769ec18
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.core.runtime.SafeRunner;
14
15 import org.eclipse.core.runtime.OperationCanceledException;
16 import org.eclipse.core.runtime.MultiStatus;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.core.runtime.CoreException;
20
21 import org.eclipse.core.internal.runtime.IRuntimeConstants;
22
23 import org.eclipse.core.runtime.ISafeRunnable;
24 import org.eclipse.core.runtime.Assert;
25
26 import java.lang.all;
27
28 /**
29 * Runs the given ISafeRunnable in a protected mode: exceptions
30 * thrown in the runnable are logged and passed to the runnable's
31 * exception handler. Such exceptions are not rethrown by this method.
32 * <p>
33 * This class can be used without OSGi running.
34 * </p>
35 * @since org.eclipse.equinox.common 3.2
36 */
37 public final class SafeRunner {
38
39 /**
40 * Runs the given runnable in a protected mode. Exceptions
41 * thrown in the runnable are logged and passed to the runnable's
42 * exception handler. Such exceptions are not rethrown by this method.
43 *
44 * @param code the runnable to run
45 */
46 public static void run(ISafeRunnable code) {
47 Assert.isNotNull(cast(Object)code);
48 try {
49 code.run();
50 } catch (Exception e) {
51 handleException(code, e);
52 // SWT not in D
53 // } catch (LinkageError e) {
54 // handleException(code, e);
55 }
56 }
57
58 private static void handleException(ISafeRunnable code, Exception e) {
59 if( null is cast(OperationCanceledException) e ){
60
61 // try to obtain the correct plug-in id for the bundle providing the safe runnable
62 // Activator activator = Activator.getDefault();
63 String pluginId = null;
64 // if (activator !is null)
65 // pluginId = activator.getBundleId(code);
66 if (pluginId is null)
67 pluginId = IRuntimeConstants.PI_COMMON;
68
69 String message = null;
70 // String message = NLS.bind(CommonMessages.meta_pluginProblems, pluginId);
71 IStatus status;
72 if ( auto ce = cast(CoreException) e ) {
73 status = new MultiStatus(pluginId, IRuntimeConstants.PLUGIN_ERROR, message, e);
74 (cast(MultiStatus) status).merge( ce.getStatus());
75 } else {
76 status = new Status(IStatus.ERROR, pluginId, IRuntimeConstants.PLUGIN_ERROR, message, e);
77 }
78 // Make sure user sees the exception: if the log is empty, log the exceptions on stderr
79 //if (!RuntimeLog.isEmpty())
80 // RuntimeLog.log(status);
81 //else
82 ExceptionPrintStackTrace(e);
83 }
84
85 code.handleException(e);
86 }
87 }