Correct reference to EPL in source headers
[egit/chris.git] / org.eclipse.egit.core / src / org / eclipse / egit / core / GitException.java
blob02c7bc7e53f7342a7d1a07dbf568662d3eb10161
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;
21 /**
22 * A checked exception representing a failure in the Git plugin.
23 * <p>
24 * Git exceptions contain a status object describing the cause of the exception.
25 * </p>
27 * @see IStatus
29 public class GitException extends TeamException {
31 private static final long serialVersionUID = 1L;
33 /**
34 * Constructs a new Git exception
36 * @param severity
37 * @param code
38 * @param message
39 * @param e
41 public GitException(int severity, int code, String message, Throwable e) {
42 super(new TeamStatus(severity, Activator.getPluginId(), code, message,
43 e, null));
46 /**
47 * Constructs a new Git exception
49 * @param severity
50 * @param code
51 * @param message
53 public GitException(int severity, int code, String message) {
54 this(severity, code, message, null);
57 /**
58 * Constructs a new Git exception
60 * @param message
61 * @param e
63 public GitException(String message, Throwable e) {
64 this(IStatus.ERROR, UNABLE, message, e);
67 /**
68 * Constructs a new Git exception
70 * @param message
72 public GitException(String message) {
73 this(message, null);
76 /**
77 * Constructs a new Git exception
79 * @param status
81 public GitException(IStatus status) {
82 super(status);
85 /**
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));
96 /**
97 * Static helper method for creating a Git exception
99 * @param resource
100 * @param message
101 * @param e
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(),
107 message, e);
111 * Static helper method for creating a Git exception
113 * @param e
114 * @return the created exception
116 public static GitException wrapException(Exception e) {
117 Throwable t = e;
118 if (e instanceof InvocationTargetException) {
119 Throwable target = ((InvocationTargetException) e)
120 .getTargetException();
121 if (target instanceof GitException) {
122 return (GitException) target;
124 t = 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
134 * @param e
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,
142 null);
144 return new GitException(status);
148 * Static helper method for creating a Git exception
150 * @param e
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
160 * @param e
161 * @return the created exception
163 public static GitException wrapException(TeamException e) {
164 if (e instanceof GitException)
165 return (GitException) e;
166 else
167 return new GitException(e.getStatus());