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 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *******************************************************************************/
11 package org
.eclipse
.egit
.core
;
13 import java
.io
.IOException
;
14 import java
.lang
.reflect
.InvocationTargetException
;
16 import org
.eclipse
.core
.resources
.IResource
;
17 import org
.eclipse
.core
.runtime
.*;
18 import org
.eclipse
.team
.core
.TeamException
;
19 import org
.eclipse
.team
.core
.TeamStatus
;
22 * A checked exception representing a failure in the Git plugin.
24 * Git exceptions contain a status object describing the cause of the exception.
29 public class GitException
extends TeamException
{
31 private static final long serialVersionUID
= 1L;
34 * Constructs a new Git exception
41 public GitException(int severity
, int code
, String message
, Throwable e
) {
42 super(new TeamStatus(severity
, Activator
.getPluginId(), code
, message
,
47 * Constructs a new Git exception
53 public GitException(int severity
, int code
, String message
) {
54 this(severity
, code
, message
, null);
58 * Constructs a new Git exception
63 public GitException(String message
, Throwable e
) {
64 this(IStatus
.ERROR
, UNABLE
, message
, e
);
68 * Constructs a new Git exception
72 public GitException(String message
) {
77 * Constructs a new Git exception
81 public GitException(IStatus status
) {
86 * Transform this exception into a CoreException
88 * @return the new CoreException
90 public CoreException
toCoreException() {
91 IStatus status
= getStatus();
92 return new CoreException(new Status(status
.getSeverity(), status
93 .getPlugin(), 0, status
.getMessage(), this));
97 * Static helper method for creating a Git exception
102 * @return the created exception
104 public static GitException
wrapException(IResource resource
,
105 String message
, CoreException e
) {
106 return new GitException(IStatus
.ERROR
, e
.getStatus().getCode(),
111 * Static helper method for creating a Git exception
114 * @return the created exception
116 public static GitException
wrapException(Exception e
) {
118 if (e
instanceof InvocationTargetException
) {
119 Throwable target
= ((InvocationTargetException
) e
)
120 .getTargetException();
121 if (target
instanceof GitException
) {
122 return (GitException
) target
;
127 return new GitException(IStatus
.ERROR
, UNABLE
,
128 t
.getMessage() != null ? t
.getMessage() : "", t
); //$NON-NLS-1$
132 * Static helper method for creating a Git exception
135 * @return the created exception
137 public static GitException
wrapException(CoreException e
) {
138 IStatus status
= e
.getStatus();
139 if (!status
.isMultiStatus()) {
140 status
= new TeamStatus(status
.getSeverity(), Activator
141 .getPluginId(), status
.getCode(), status
.getMessage(), e
,
144 return new GitException(status
);
148 * Static helper method for creating a Git exception
151 * @return the created exception
153 public static GitException
wrapException(IOException e
) {
154 return new GitException(IStatus
.ERROR
, IO_FAILED
, e
.getMessage(), e
);
158 * Static helper method for creating a Git exception
161 * @return the created exception
163 public static GitException
wrapException(TeamException e
) {
164 if (e
instanceof GitException
)
165 return (GitException
) e
;
167 return new GitException(e
.getStatus());