blob: cfe1bf8fd293f265082b93b413d05ebafa65c510 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*******************************************************************************
* Copyright (c) 2011, 2013 Wind River Systems, Inc. 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:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.runtime.utils;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.tcf.te.runtime.activator.CoreBundleActivator;
/**
* Helper implementation to deal with status objects and throwable's.
*/
public final class StatusHelper {
/**
* Converts a throwable to an IStatus (OK, CANCEL, ERROR).
*
* @param error The throwable or <code>null</code>.
* @return The status.
*/
public static final IStatus getStatus(Throwable error) {
if (error == null) return Status.OK_STATUS;
int severity = IStatus.ERROR;
if (error instanceof CoreException && ((CoreException)error).getStatus() != null) {
return ((CoreException)error).getStatus();
}
else if (error instanceof OperationCanceledException) {
severity = IStatus.CANCEL;
}
String message = error.getLocalizedMessage();
if (message == null) message = error.getMessage();
message = unwrapErrorReport(message);
return new Status(severity, CoreBundleActivator.getUniqueIdentifier(), message != null ? message : error.toString(), error);
}
/**
* Unwrap a "TCF Error Report:" error text.
*
* @param error The error text or <code>null</code>.
* @return The unwrapped error text or the unmodified input parameter.
*/
public static final String unwrapErrorReport(String error) {
// Unwrap "TCF error report" errors
if (error != null && error.startsWith("TCF error report")) { //$NON-NLS-1$
error = error.substring(error.indexOf("Error text:") + 11, error.indexOf("Error code:")); //$NON-NLS-1$ //$NON-NLS-2$
error = error.trim();
}
return error;
}
}
|