1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others.
3 * Copyright (c) 2003, 2006 Subclipse project and others.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * See LICENSE for the full license text, also available.
8 *******************************************************************************/
10 package org
.spearce
.egit
.core
;
12 import java
.io
.IOException
;
13 import java
.lang
.reflect
.InvocationTargetException
;
15 import org
.eclipse
.core
.resources
.IResource
;
16 import org
.eclipse
.core
.runtime
.*;
17 import org
.eclipse
.team
.core
.TeamException
;
18 import org
.eclipse
.team
.core
.TeamStatus
;
21 * A checked exception representing a failure in the Git plugin.
23 * Git exceptions contain a status object describing the cause of the exception.
28 public class GitException
extends TeamException
{
30 private static final long serialVersionUID
= 1L;
33 * Constructs a new Git exception
40 public GitException(int severity
, int code
, String message
, Throwable e
) {
41 super(new TeamStatus(severity
, Activator
.getPluginId(), code
, message
,
46 * Constructs a new Git exception
52 public GitException(int severity
, int code
, String message
) {
53 this(severity
, code
, message
, null);
57 * Constructs a new Git exception
62 public GitException(String message
, Throwable e
) {
63 this(IStatus
.ERROR
, UNABLE
, message
, e
);
67 * Constructs a new Git exception
71 public GitException(String message
) {
76 * Constructs a new Git exception
80 public GitException(IStatus status
) {
85 * Transform this exception into a CoreException
87 * @return the new CoreException
89 public CoreException
toCoreException() {
90 IStatus status
= getStatus();
91 return new CoreException(new Status(status
.getSeverity(), status
92 .getPlugin(), 0, status
.getMessage(), this));
96 * Static helper method for creating a Git exception
101 * @return the created exception
103 public static GitException
wrapException(IResource resource
,
104 String message
, CoreException e
) {
105 return new GitException(IStatus
.ERROR
, e
.getStatus().getCode(),
110 * Static helper method for creating a Git exception
113 * @return the created exception
115 public static GitException
wrapException(Exception e
) {
117 if (e
instanceof InvocationTargetException
) {
118 Throwable target
= ((InvocationTargetException
) e
)
119 .getTargetException();
120 if (target
instanceof GitException
) {
121 return (GitException
) target
;
126 return new GitException(IStatus
.ERROR
, UNABLE
,
127 t
.getMessage() != null ? t
.getMessage() : "", t
); //$NON-NLS-1$
131 * Static helper method for creating a Git exception
134 * @return the created exception
136 public static GitException
wrapException(CoreException e
) {
137 IStatus status
= e
.getStatus();
138 if (!status
.isMultiStatus()) {
139 status
= new TeamStatus(status
.getSeverity(), Activator
140 .getPluginId(), status
.getCode(), status
.getMessage(), e
,
143 return new GitException(status
);
147 * Static helper method for creating a Git exception
150 * @return the created exception
152 public static GitException
wrapException(IOException e
) {
153 return new GitException(IStatus
.ERROR
, IO_FAILED
, e
.getMessage(), e
);
157 * Static helper method for creating a Git exception
160 * @return the created exception
162 public static GitException
wrapException(TeamException e
) {
163 if (e
instanceof GitException
)
164 return (GitException
) e
;
166 return new GitException(e
.getStatus());