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