diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/prov/core/helpers/LogHelper.java')
-rw-r--r-- | bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/prov/core/helpers/LogHelper.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/prov/core/helpers/LogHelper.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/prov/core/helpers/LogHelper.java new file mode 100644 index 000000000..140a4fa1f --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/prov/core/helpers/LogHelper.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.prov.core.helpers; + +import java.util.ArrayList; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.prov.core.Activator; +import org.eclipse.osgi.framework.log.FrameworkLog; +import org.eclipse.osgi.framework.log.FrameworkLogEntry; + +public class LogHelper { + + public static void log(IStatus status) { + FrameworkLog log = Activator.getFrameworkLog(); + if (log != null) { + log.log(getLog(status)); + } else { + System.out.println(status.getMessage()); + if (status.getException() != null) + status.getException().printStackTrace(); + } + } + + /** + * Copied from PlatformLogWriter in core runtime. + */ + private static FrameworkLogEntry getLog(IStatus status) { + Throwable t = status.getException(); + ArrayList childlist = new ArrayList(); + + 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) { + childlist.add(getLog(coreStatus)); + } + } + + if (status.isMultiStatus()) { + IStatus[] children = status.getChildren(); + for (int i = 0; i < children.length; i++) { + childlist.add(getLog(children[i])); + } + } + + FrameworkLogEntry[] children = (FrameworkLogEntry[]) (childlist.size() == 0 ? null : childlist.toArray(new FrameworkLogEntry[childlist.size()])); + + return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(), status.getCode(), status.getMessage(), stackCode, t, children); + } +} |