Java Code Examples for org.eclipse.core.runtime.IStatus#getException()

The following examples show how to use org.eclipse.core.runtime.IStatus#getException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RepositoryStatusHelper.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static void deeplyPrint(IStatus status, PrintStream strm, boolean stackTrace, int level)
{
	appendLevelString(strm, level);
	String msg = status.getMessage();
	strm.println(msg);
	Throwable cause = status.getException();
	if (cause != null)
	{
		strm.print("Caused by: "); //$NON-NLS-1$
		if (stackTrace || !(msg.equals(cause.getMessage()) || msg.equals(cause.toString())))
			deeplyPrint(cause, strm, stackTrace, level);
	}

	if (status.isMultiStatus())
	{
		IStatus[] children = status.getChildren();
		for (int i = 0; i < children.length; i++)
			deeplyPrint(children[i], strm, stackTrace, level + 1);
	}
}
 
Example 2
Source File: Slf4jLogListener.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void logging(IStatus status, String plugin){
	String message = "[" + plugin + "] " + status.getMessage();
	Throwable exception = status.getException();
	
	switch (status.getSeverity()) {
	case IStatus.ERROR:
		logger.error(message, exception);
		break;
	case IStatus.WARNING:
		logger.warn(message, exception);
		break;
	case IStatus.INFO:
		logger.info(message, exception);
		break;
	default:
		logger.debug(message, exception);
		break;
	}
	
}
 
Example 3
Source File: CloudSdkManager.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Installs a Cloud SDK, if the preferences are configured to auto-manage the SDK. Blocks callers
 * 1) if the managed SDK is being installed concurrently by others; and 2) until the installation
 * is complete.
 *
 * @param consoleStream stream to which the install output is written
 * @param monitor the progress monitor that can also be used to cancel the installation
 */
public IStatus installManagedSdk(MessageConsoleStream consoleStream, IProgressMonitor monitor) {
  if (CloudSdkPreferences.isAutoManaging()) {
    // We don't check if the Cloud SDK installed but always schedule the install job; such check
    // may pass while the SDK is being installed and in an incomplete state.
    // Mark installation failure as non-ERROR to avoid job failure reporting dialogs from the
    // overly helpful Eclipse UI ProgressManager
    CloudSdkInstallJob installJob = new CloudSdkInstallJob(
        consoleStream, modifyLock, IStatus.WARNING);

    IStatus result = runInstallJob(consoleStream, installJob, monitor);
    if (!result.isOK()) {
      // recast result as an IStatus.ERROR
      return new Status(
          IStatus.ERROR,
          result.getPlugin(),
          result.getCode(),
          result.getMessage(),
          result.getException());
    }
  }
  return Status.OK_STATUS;
}
 
Example 4
Source File: StatusUtil.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
public static IStatus merge(IStatus status, IStatus newStatus) {
  if (status == null) {
    return newStatus;
  } else {
    if (status instanceof MultiStatus) {
      ((MultiStatus) status).merge(newStatus);
      return status;
    } else {
      MultiStatus merged = new MultiStatus(status.getPlugin(), status.getCode(),
          status.getMessage(), status.getException());
      merged.merge(newStatus);
      return merged;
    }
  }
  
}
 
Example 5
Source File: TestingEnvironment.java    From dacapobench with Apache License 2.0 6 votes vote down vote up
/**
 * Handles a core exception thrown during a testing environment operation
 */
private void handleCoreException(CoreException e) {
  e.printStackTrace();
  IStatus status = e.getStatus();
  String message = e.getMessage();
  if (status.isMultiStatus()) {
    MultiStatus multiStatus = (MultiStatus) status;
    IStatus[] children = multiStatus.getChildren();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0, max = children.length; i < max; i++) {
      IStatus child = children[i];
      if (child != null) {
        buffer.append(child.getMessage());
        buffer.append(System.getProperty("line.separator"));//$NON-NLS-1$
        Throwable childException = child.getException();
        if (childException != null) {
          childException.printStackTrace();
        }
      }
    }
    message = buffer.toString();
  }
  Assert.isTrue(false, "Core exception in testing environment: " + message); //$NON-NLS-1$
}
 
Example 6
Source File: BugzillaExecutor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static String getNotFoundError(CoreException ce) {
    IStatus status = ce.getStatus();
    Throwable t = status.getException();
    if(t instanceof UnknownHostException ||
       // XXX maybe a different msg ?     
       t instanceof SocketTimeoutException || 
       t instanceof NoRouteToHostException ||
       t instanceof ConnectException) 
    {
        Bugzilla.LOG.log(Level.FINER, null, t);
        return NbBundle.getMessage(BugzillaExecutor.class, "MSG_HOST_NOT_FOUND");                   // NOI18N
    }
    String msg = getMessage(ce);
    if(msg != null) {
        msg = msg.trim().toLowerCase();
        if(HTTP_ERROR_NOT_FOUND.equals(msg)) {
            Bugzilla.LOG.log(Level.FINER, "returned error message [{0}]", msg);                     // NOI18N
            return NbBundle.getMessage(BugzillaExecutor.class, "MSG_HOST_NOT_FOUND");               // NOI18N
        }
    }
    return null;
}
 
Example 7
Source File: EclipseUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static StatusException statusToStatusException3(IStatus status) throws StatusException {
	if(status.isOK() || status.getSeverity() == IStatus.CANCEL) {
		return null;
	}
	
	Severity severity = toStatusLevel(status).toSeverity();
	return new StatusException(severity, status.getMessage(), status.getException());
}
 
Example 8
Source File: LogHelper.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Implements logging of an IStatus object, recursively as needed.
 */
private static void doLog(IStatus status) {
	if (status.isOK())
		return;
	Throwable t = status.getException();
	if (status.getSeverity() == IStatus.ERROR) {
		logger.error(status.getMessage(), t);
	} else if (status.getSeverity() == IStatus.WARNING) {
		logger.warn(status.getMessage(), t);
	} else {
		logger.info(status.getMessage(), t);
	}

	int stackCode = t instanceof CoreException ? 1 : 0;
	// ensure a substatus inside a CoreException is properly logged
	if (stackCode == 1) {
		IStatus coreStatus = ((CoreException) t).getStatus();
		if (coreStatus != null) {
			doLog(coreStatus);
		}
	}

	if (status.isMultiStatus()) {
		IStatus[] children = status.getChildren();
		for (int i = 0; i < children.length; i++) {
			doLog(children[i]);
		}
	}
}
 
Example 9
Source File: LogHelper.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public static void log(IStatus status) {
	if (logger != null) {
		doLog(status);
	} else {
		System.out.println(status.getMessage());
		if (status.getException() != null)
			status.getException().printStackTrace();
	}
}
 
Example 10
Source File: ServletStatusHandler.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public boolean handleRequest(HttpServletRequest request, HttpServletResponse response, IStatus error) throws ServletException {
	int httpCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
	ServerStatus serverStatus;
	if (error instanceof ServerStatus) {
		serverStatus = (ServerStatus) error;
		httpCode = serverStatus.getHttpCode();
	} else {
		serverStatus = new ServerStatus(error, httpCode);
	}
	response.setCharacterEncoding("UTF-8");
	//TODO change check for a generic property
	if ("TIAM".equals(PreferenceHelper.getString(ServerConstants.CONFIG_AUTH_NAME, null))) {
		if (httpCode == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
			httpCode = 599;
		}
		if (httpCode == HttpServletResponse.SC_NOT_FOUND) {
			httpCode = HttpServletResponse.SC_GONE;
		}
	}
	response.setStatus(httpCode);
	response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
	response.setContentType(ProtocolConstants.CONTENT_TYPE_JSON);
	try {
		response.getWriter().print(serverStatus.toJSON().toString());
	} catch (IOException ioe) {
		//just throw a servlet exception
		throw new ServletException(error.getMessage(), error.getException());
	}
	return true;
}
 
Example 11
Source File: RepositoryStatusHelper.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static CoreException wrap(IStatus status)
{
	CoreException e = new CoreException(status);
	Throwable t = status.getException();
	if (t != null)
		e.initCause(t);
	return e;
}
 
Example 12
Source File: DebugUtil.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Extracts an error message that can be presented to the user from an exception
 * when trying to execute GDB via CDT tooling.
 *
 * @param e exception thrown when trying to exceute GDB
 * @return error message that can be presented to user
 */
/* package */ static String getMessageFromGdbExecutionException(CoreException e) {
	final IStatus status = e.getStatus();
	final String statusMessage = status.getMessage();
	final Throwable statusException = status.getException();
	if (statusException != null) {
		String exceptionMessage = statusException.getLocalizedMessage();
		return NLS.bind(Messages.RustDebugTabGroup_gdbErrorMsg, statusMessage, exceptionMessage);
	}
	// else
	return statusMessage;
}
 
Example 13
Source File: PreviewTranslationHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 得到 ConverterViewModel 对象
 * @param file
 *            需要预览翻译的文件
 * @return
 * @throws ExecutionException
 *             ;
 */
private ConverterViewModel getConverterViewModel(IFile file) throws ExecutionException {
	Object adapter = Platform.getAdapterManager().getAdapter(file, IConversionItem.class);
	if (adapter instanceof IConversionItem) {
		IConversionItem item = (IConversionItem) adapter;
		ConverterViewModel converterViewModel = new ConverterViewModel(Activator.getContext(),
				Converter.DIRECTION_REVERSE); // 逆向转换
		converterViewModel.setConversionItem(item);
		try {
			ConversionResource resource = new ConversionResource(Converter.DIRECTION_REVERSE, item);
			String xliffpath = resource.getXliffPath();
			String targetPath = resource.getPreviewPath();

			ConversionConfigBean configBean = converterViewModel.getConfigBean();
			configBean.setSource(xliffpath);
			configBean.setTarget(targetPath);
			configBean.setTargetEncoding("UTF-8");
			configBean.setPreviewMode(true); // 设为预览翻译模式

			final IStatus status = converterViewModel.validateXliffFile(ConverterUtil.toLocalPath(xliffpath),
					new XLFHandler(), null); // 注:验证的过程中,会为文件类型和骨架文件的路径赋值。
			if (status != null && status.isOK()) {
				return converterViewModel;
			} else {
				Display.getDefault().syncExec(new Runnable() {

					public void run() {
						MessageDialog.openInformation(shell,
								Messages.getString("handler.PreviewTranslationHandler.msgTitle"),
								status.getMessage());
					}
				});
				throw new ExecutionException(status.getMessage(), status.getException());
			}
		} catch (CoreException e) {
			throw new ExecutionException(e.getMessage(), e);
		}
	}
	return null;
}
 
Example 14
Source File: FlexWarStagingDelegateTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static String getStatusAsString(IStatus status) {
  String stringStatus = status.getSeverity() + ": " + status.getMessage();
  if (status.getException() != null) {
    stringStatus += "\n==== start of IStatus exception stack trace ====\n";
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter, true);
    status.getException().printStackTrace(printWriter);
    stringStatus += stringWriter.toString();
    stringStatus += "==== end of IStatus exception stack trace ====";
  }
  return stringStatus;
}
 
Example 15
Source File: OpenTraceStressTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static String handleErrorStatus(MultiStatus status) {

        // Build a string with all the children status messages, exception
        // messages and stack traces
        StringBuilder sb = new StringBuilder();
        for (IStatus childStatus : status.getChildren()) {
            StringBuilder childSb = new StringBuilder();
            if (!childStatus.getMessage().isEmpty()) {
                childSb.append(childStatus.getMessage() + '\n');
            }

            Throwable childException = childStatus.getException();
            if (childException != null) {
                String reason = childException.getMessage();
                // Some system exceptions have no message
                if (reason == null) {
                    reason = childException.toString();
                }

                String stackMessage = getExceptionStackMessage(childException);
                if (stackMessage == null) {
                    stackMessage = reason;
                }

                childSb.append(stackMessage);
            }

            if (childSb.length() > 0) {
                childSb.insert(0, '\n');
                sb.append(childSb.toString());
            }
        }
        return sb.toString();
    }
 
Example 16
Source File: SimpleLogListener.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private String convert(IStatus status) {
	StringBuilder s = new StringBuilder(status.getMessage());
	if (status.getException() != null) {
		String stackTrace = Throwables.getStackTraceAsString(status.getException());
		s.append("\n");
		s.append(stackTrace);
	}
	return s.toString();
}
 
Example 17
Source File: PreviewTranslationHandler.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 得到 ConverterViewModel 对象
 * @param file
 *            需要预览翻译的文件
 * @return
 * @throws ExecutionException
 *             ;
 */
private ConverterViewModel getConverterViewModel(IFile file) throws ExecutionException {
	Object adapter = Platform.getAdapterManager().getAdapter(file, IConversionItem.class);
	if (adapter instanceof IConversionItem) {
		IConversionItem item = (IConversionItem) adapter;
		ConverterViewModel converterViewModel = new ConverterViewModel(Activator.getContext(),
				Converter.DIRECTION_REVERSE); // 逆向转换
		converterViewModel.setConversionItem(item);
		try {
			ConversionResource resource = new ConversionResource(Converter.DIRECTION_REVERSE, item);
			String xliffpath = resource.getXliffPath();
			String targetPath = resource.getPreviewPath();

			ConversionConfigBean configBean = converterViewModel.getConfigBean();
			configBean.setSource(xliffpath);
			configBean.setTarget(targetPath);
			configBean.setTargetEncoding("UTF-8");
			configBean.setPreviewMode(true); // 设为预览翻译模式

			final IStatus status = converterViewModel.validateXliffFile(ConverterUtil.toLocalPath(xliffpath),
					new XLFHandler(), null); // 注:验证的过程中,会为文件类型和骨架文件的路径赋值。
			if (status != null && status.isOK()) {
				return converterViewModel;
			} else {
				Display.getDefault().syncExec(new Runnable() {

					public void run() {
						MessageDialog.openInformation(shell,
								Messages.getString("handler.PreviewTranslationHandler.msgTitle"),
								status.getMessage());
					}
				});
				throw new ExecutionException(status.getMessage(), status.getException());
			}
		} catch (CoreException e) {
			throw new ExecutionException(e.getMessage(), e);
		}
	}
	return null;
}
 
Example 18
Source File: PreviewTranslationHandler.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 得到 ConverterViewModel 对象
 * @param file
 *            需要预览翻译的文件
 * @return
 * @throws ExecutionException
 *             ;
 */
private ConverterViewModel getConverterViewModel(IFile file) throws ExecutionException {
	Object adapter = Platform.getAdapterManager().getAdapter(file, IConversionItem.class);
	if (adapter instanceof IConversionItem) {
		IConversionItem item = (IConversionItem) adapter;
		ConverterViewModel converterViewModel = new ConverterViewModel(Activator.getContext(),
				Converter.DIRECTION_REVERSE); // 逆向转换
		converterViewModel.setConversionItem(item);
		try {
			ConversionResource resource = new ConversionResource(Converter.DIRECTION_REVERSE, item);
			String xliffpath = resource.getXliffPath();
			String targetPath = resource.getPreviewPath();

			ConversionConfigBean configBean = converterViewModel.getConfigBean();
			configBean.setSource(xliffpath);
			configBean.setTarget(targetPath);
			configBean.setTargetEncoding("UTF-8");
			configBean.setPreviewMode(true); // 设为预览翻译模式

			IStatus status = converterViewModel.validateXliffFile(ConverterUtil.toLocalPath(xliffpath),
					new XLFHandler(), null); // 注:验证的过程中,会为文件类型和骨架文件的路径赋值。
			if (status != null && status.isOK()) {
				return converterViewModel;
			} else {
				throw new ExecutionException(status.getMessage(), status.getException());
			}
		} catch (CoreException e) {
			throw new ExecutionException(e.getMessage(), e);
		}
	}
	return null;
}
 
Example 19
Source File: ServerStatus.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
public ServerStatus(IStatus status, int httpCode) {
	super(status.getSeverity(), status.getPlugin(), status.getCode(), status.getMessage(), status.getException());
	this.httpCode = httpCode;
}
 
Example 20
Source File: StatusUtil.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Log a status to the corresponding log-level; does nothing if
 * {@link Status#isOK()}
 * 
 * @param prependMessage              an optional message to prepend the status
 *                                    message
 * @param log
 * @param status
 * @param includeExceptionIfAvailable
 * @param logDebugIfOk                log to level debug if the status is ok
 */
public static void logStatus(String prependMessage, @NonNull Logger log, @NonNull IStatus status,
		boolean includeExceptionIfAvailable, boolean logDebugIfOk) {
	if (status.isOK() && !logDebugIfOk) {
		return;
	}

	StringBuilder sb = new StringBuilder();
	if (status.isMultiStatus()) {
		sb.append("[MULTISTATUS] ");
	}
	if (prependMessage != null) {
		sb.append(prependMessage + " ");
	}
	sb.append("(c" + status.getCode() + "/s" + status.getSeverity() + ") ");
	sb.append(status.getMessage());
	String message = sb.toString();

	boolean includeException = (includeExceptionIfAvailable && status.getException() != null);

	int severity = status.getSeverity();
	switch (severity) {
	case Status.ERROR:
		if (includeException) {
			log.error(message, status.getException());
		} else {
			log.error(message);
		}
		break;
	case Status.WARNING:
		if (includeException) {
			log.warn(message, status.getException());
		} else {
			log.warn(message);
		}
		break;
	case Status.INFO:
	case Status.CANCEL:
		if (includeException) {
			log.info(message, status.getException());
		} else {
			log.info(message);
		}
		break;
	case Status.OK:
		log.debug(message);
		break;
	default:
		break;
	}

	if (status.isMultiStatus()) {
		Arrays.asList(status.getChildren()).stream().forEach(c -> logStatus(prependMessage, log, c, true, false));
	}
}