Browse Source

Further cleanup of exceptions in Git API

- Translate internal exceptions to corresponding API exception
- Do not catch GitAPI exceptions internally to an internal
exception. Just pass them to caller
- Mention thrown exceptions in javadoc

Change-Id: I9044cf86d2b0bcc8b63b7cc016e1bf0055a62053
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v2.0.0.201206130900-r
Robin Rosenberg 12 years ago
parent
commit
b61d35e848

+ 5
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java View File

* method twice on an instance. * method twice on an instance.
* *
* @return an {@link ApplyResult} object representing the command result * @return an {@link ApplyResult} object representing the command result
* @throws GitAPIException
* @throws PatchFormatException
* @throws PatchApplyException
*/ */
public ApplyResult call() throws GitAPIException {
public ApplyResult call() throws GitAPIException, PatchFormatException,
PatchApplyException {
checkCallable(); checkCallable();
ApplyResult r = new ApplyResult(); ApplyResult r = new ApplyResult();
try { try {

+ 13
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java View File

import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.MultipleParentsNotAllowedException; import org.eclipse.jgit.api.errors.MultipleParentsNotAllowedException;
import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.NoMessageException;
import org.eclipse.jgit.api.errors.UnmergedPathsException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.dircache.DirCacheCheckout; import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
* invocation of the command. Don't call this method twice on an instance. * invocation of the command. Don't call this method twice on an instance.
* *
* @return the result of the cherry-pick * @return the result of the cherry-pick
* @throws GitAPIException
* @throws WrongRepositoryStateException
* @throws ConcurrentRefUpdateException
* @throws UnmergedPathsException
* @throws NoMessageException
* @throws NoHeadException
*/ */
public CherryPickResult call() throws GitAPIException {
public CherryPickResult call() throws GitAPIException, NoMessageException,
UnmergedPathsException, ConcurrentRefUpdateException,
WrongRepositoryStateException, NoHeadException {
RevCommit newHead = null; RevCommit newHead = null;
List<Ref> cherryPickedRefs = new LinkedList<Ref>(); List<Ref> cherryPickedRefs = new LinkedList<Ref>();
checkCallable(); checkCallable();

+ 4
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java View File



import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;


* call to {@link #call()}) * call to {@link #call()})
* *
* @return a set of strings representing each file cleaned. * @return a set of strings representing each file cleaned.
* @throws GitAPIException
* @throws NoWorkTreeException
*/ */
public Set<String> call() throws GitAPIException {
public Set<String> call() throws NoWorkTreeException, GitAPIException {
Set<String> files = new TreeSet<String>(); Set<String> files = new TreeSet<String>();
try { try {
StatusCommand command = new StatusCommand(repo); StatusCommand command = new StatusCommand(repo);

+ 10
- 5
org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java View File

* Executes the {@code Clone} command. * Executes the {@code Clone} command.
* *
* @return the newly created {@code Git} object with associated repository * @return the newly created {@code Git} object with associated repository
* @throws InvalidRemoteException
* @throws org.eclipse.jgit.api.errors.TransportException
* @throws GitAPIException
*/ */
public Git call() throws GitAPIException {
public Git call() throws GitAPIException, InvalidRemoteException,
org.eclipse.jgit.api.errors.TransportException {
try { try {
URIish u = new URIish(uri); URIish u = new URIish(uri);
Repository repository = init(u); Repository repository = init(u);
return new Git(repository); return new Git(repository);
} catch (IOException ioe) { } catch (IOException ioe) {
throw new JGitInternalException(ioe.getMessage(), ioe); throw new JGitInternalException(ioe.getMessage(), ioe);
} catch (InvalidRemoteException e) {
throw new JGitInternalException(e.getMessage(), e);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new JGitInternalException(e.getMessage(), e);
throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote));
} }
} }


} }


private FetchResult fetch(Repository clonedRepo, URIish u) private FetchResult fetch(Repository clonedRepo, URIish u)
throws URISyntaxException, IOException, GitAPIException {
throws URISyntaxException,
org.eclipse.jgit.api.errors.TransportException, IOException,
GitAPIException {
// create the remote config and save it // create the remote config and save it
RemoteConfig config = new RemoteConfig(clonedRepo.getConfig(), remote); RemoteConfig config = new RemoteConfig(clonedRepo.getConfig(), remote);
config.addURI(u); config.addURI(u);

+ 1
- 2
org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java View File

JGitText.get().invalidRemote, remote), e); JGitText.get().invalidRemote, remote), e);
} catch (TransportException e) { } catch (TransportException e) {
throw new org.eclipse.jgit.api.errors.TransportException( throw new org.eclipse.jgit.api.errors.TransportException(
JGitText.get().exceptionCaughtDuringExecutionOfFetchCommand,
e);
e.getMessage(), e);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new InvalidRemoteException(MessageFormat.format( throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote)); JGitText.get().invalidRemote, remote));

+ 3
- 2
org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java View File

* for errors that occurs during transport * for errors that occurs during transport
*/ */
public Collection<Ref> call() throws GitAPIException, public Collection<Ref> call() throws GitAPIException,
InvalidRemoteException,
org.eclipse.jgit.api.errors.TransportException { org.eclipse.jgit.api.errors.TransportException {
checkCallable(); checkCallable();


JGitText.get().exceptionCaughtDuringExecutionOfLsRemoteCommand, JGitText.get().exceptionCaughtDuringExecutionOfLsRemoteCommand,
e); e);
} catch (TransportException e) { } catch (TransportException e) {
throw new org.eclipse.jgit.api.errors.TransportException(
JGitText.get().exceptionCaughtDuringExecutionOfLsRemoteCommand,
throw new org.eclipse.jgit.api.errors.TransportException(
e.getMessage(),
e); e);
} finally { } finally {
if (fc != null) if (fc != null)

+ 21
- 40
org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java View File



import org.eclipse.jgit.api.RebaseCommand.Operation; import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.errors.CanceledException; import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.DetachedHeadException; import org.eclipse.jgit.api.errors.DetachedHeadException;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidConfigurationException; import org.eclipse.jgit.api.errors.InvalidConfigurationException;
import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.NoMessageException;
import org.eclipse.jgit.api.errors.RefNotFoundException; import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException; import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
* command. Don't call this method twice on an instance. * command. Don't call this method twice on an instance.
* *
* @return the result of the pull * @return the result of the pull
* @throws WrongRepositoryStateException
* @throws InvalidConfigurationException
* @throws DetachedHeadException
* @throws InvalidRemoteException
* @throws CanceledException
* @throws RefNotFoundException
* @throws NoHeadException
* @throws org.eclipse.jgit.api.errors.TransportException
* @throws GitAPIException
*/ */
public PullResult call() throws GitAPIException, WrongRepositoryStateException,
InvalidConfigurationException, DetachedHeadException,
InvalidRemoteException, CanceledException, RefNotFoundException,
NoHeadException {
public PullResult call() throws GitAPIException,
WrongRepositoryStateException, InvalidConfigurationException,
DetachedHeadException, InvalidRemoteException, CanceledException,
RefNotFoundException, NoHeadException,
org.eclipse.jgit.api.errors.TransportException {
checkCallable(); checkCallable();


monitor.beginTask(JGitText.get().pullTaskName, 2); monitor.beginTask(JGitText.get().pullTaskName, 2);
PullResult result; PullResult result;
if (doRebase) { if (doRebase) {
RebaseCommand rebase = new RebaseCommand(repo); RebaseCommand rebase = new RebaseCommand(repo);
try {
RebaseResult rebaseRes = rebase.setUpstream(commitToMerge)
.setProgressMonitor(monitor).setOperation(
Operation.BEGIN).call();
result = new PullResult(fetchRes, remote, rebaseRes);
} catch (NoHeadException e) {
throw new JGitInternalException(e.getMessage(), e);
} catch (RefNotFoundException e) {
throw new JGitInternalException(e.getMessage(), e);
} catch (JGitInternalException e) {
throw new JGitInternalException(e.getMessage(), e);
} catch (GitAPIException e) {
throw new JGitInternalException(e.getMessage(), e);
}
RebaseResult rebaseRes = rebase.setUpstream(commitToMerge)
.setProgressMonitor(monitor).setOperation(Operation.BEGIN)
.call();
result = new PullResult(fetchRes, remote, rebaseRes);
} else { } else {
MergeCommand merge = new MergeCommand(repo); MergeCommand merge = new MergeCommand(repo);
String name = "branch \'" String name = "branch \'"
+ Repository.shortenRefName(remoteBranchName) + "\' of " + Repository.shortenRefName(remoteBranchName) + "\' of "
+ remoteUri; + remoteUri;
merge.include(name, commitToMerge); merge.include(name, commitToMerge);
MergeResult mergeRes;
try {
mergeRes = merge.call();
monitor.update(1);
result = new PullResult(fetchRes, remote, mergeRes);
} catch (NoHeadException e) {
throw new JGitInternalException(e.getMessage(), e);
} catch (ConcurrentRefUpdateException e) {
throw new JGitInternalException(e.getMessage(), e);
} catch (CheckoutConflictException e) {
throw new JGitInternalException(e.getMessage(), e);
} catch (InvalidMergeHeadsException e) {
throw new JGitInternalException(e.getMessage(), e);
} catch (WrongRepositoryStateException e) {
throw new JGitInternalException(e.getMessage(), e);
} catch (NoMessageException e) {
throw new JGitInternalException(e.getMessage(), e);
}
MergeResult mergeRes = merge.call();
monitor.update(1);
result = new PullResult(fetchRes, remote, mergeRes);
} }
monitor.endTask(); monitor.endTask();
return result; return result;

+ 10
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java View File

* @return an iteration over {@link PushResult} objects * @return an iteration over {@link PushResult} objects
* @throws InvalidRemoteException * @throws InvalidRemoteException
* when called with an invalid remote uri * when called with an invalid remote uri
* @throws org.eclipse.jgit.api.errors.TransportException
* when an error occurs with the transport
* @throws GitAPIException
*/ */
public Iterable<PushResult> call() throws GitAPIException, public Iterable<PushResult> call() throws GitAPIException,
InvalidRemoteException {
InvalidRemoteException,
org.eclipse.jgit.api.errors.TransportException {
checkCallable(); checkCallable();


ArrayList<PushResult> pushResults = new ArrayList<PushResult>(3); ArrayList<PushResult> pushResults = new ArrayList<PushResult>(3);
pushResults.add(result); pushResults.add(result);


} catch (TransportException e) { } catch (TransportException e) {
throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfPushCommand,
e);
throw new org.eclipse.jgit.api.errors.TransportException(
e.getMessage(), e);
} finally { } finally {
transport.close(); transport.close();
} }
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new InvalidRemoteException(MessageFormat.format( throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote)); JGitText.get().invalidRemote, remote));
} catch (TransportException e) {
throw new org.eclipse.jgit.api.errors.TransportException(
e.getMessage(), e);
} catch (NotSupportedException e) { } catch (NotSupportedException e) {
throw new JGitInternalException( throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfPushCommand, JGitText.get().exceptionCaughtDuringExecutionOfPushCommand,

+ 5
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java View File

* this method twice on an instance. * this method twice on an instance.
* *
* @return an object describing the result of this command * @return an object describing the result of this command
* @throws GitAPIException
* @throws WrongRepositoryStateException
* @throws NoHeadException
* @throws RefNotFoundException
*/ */
public RebaseResult call() throws GitAPIException, NoHeadException, public RebaseResult call() throws GitAPIException, NoHeadException,
RefNotFoundException {
RefNotFoundException, WrongRepositoryStateException {
RevCommit newHead = null; RevCommit newHead = null;
boolean lastStepWasForward = false; boolean lastStepWasForward = false;
checkCallable(); checkCallable();

+ 8
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/ReflogCommand.java View File

return this; return this;
} }


public Collection<ReflogEntry> call() throws GitAPIException {
/**
* Run the reflog command
*
* @throws GitAPIException
* @throws InvalidRefNameException
*/
public Collection<ReflogEntry> call() throws GitAPIException,
InvalidRefNameException {
checkCallable(); checkCallable();


try { try {

+ 1
- 0
org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java View File

* twice on an instance. * twice on an instance.
* *
* @return the Ref after reset * @return the Ref after reset
* @throws GitAPIException
*/ */
public Ref call() throws GitAPIException, CheckoutConflictException { public Ref call() throws GitAPIException, CheckoutConflictException {
checkCallable(); checkCallable();

+ 12
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java View File

import java.util.Map; import java.util.Map;


import org.eclipse.jgit.api.MergeResult.MergeStatus; import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.MultipleParentsNotAllowedException; import org.eclipse.jgit.api.errors.MultipleParentsNotAllowedException;
import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.NoMessageException;
import org.eclipse.jgit.api.errors.UnmergedPathsException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.dircache.DirCacheCheckout; import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
* returned. If a failure occurred during revert <code>null</code> * returned. If a failure occurred during revert <code>null</code>
* is returned. The list of successfully reverted {@link Ref}'s can * is returned. The list of successfully reverted {@link Ref}'s can
* be obtained by calling {@link #getRevertedRefs()} * be obtained by calling {@link #getRevertedRefs()}
* @throws GitAPIException
* @throws WrongRepositoryStateException
* @throws ConcurrentRefUpdateException
* @throws UnmergedPathsException
* @throws NoMessageException
*/ */
public RevCommit call() throws GitAPIException {
public RevCommit call() throws NoMessageException, UnmergedPathsException,
ConcurrentRefUpdateException, WrongRepositoryStateException,
GitAPIException {
RevCommit newHead = null; RevCommit newHead = null;
checkCallable(); checkCallable();



+ 4
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java View File

* Apply the changes in a stashed commit to the working directory and index * Apply the changes in a stashed commit to the working directory and index
* *
* @return id of stashed commit that was applied * @return id of stashed commit that was applied
* @throws GitAPIException
* @throws WrongRepositoryStateException
*/ */
public ObjectId call() throws GitAPIException {
public ObjectId call() throws GitAPIException,
WrongRepositoryStateException {
checkCallable(); checkCallable();


if (repo.getRepositoryState() != RepositoryState.SAFE) if (repo.getRepositoryState() != RepositoryState.SAFE)

+ 1
- 0
org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java View File

* and reset to the current HEAD commit. * and reset to the current HEAD commit.
* *
* @return stashed commit or null if no changes to stash * @return stashed commit or null if no changes to stash
* @throws GitAPIException
*/ */
public RevCommit call() throws GitAPIException { public RevCommit call() throws GitAPIException {
checkCallable(); checkCallable();

+ 1
- 0
org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java View File

* stash reference after the drop occurs * stash reference after the drop occurs
* *
* @return commit id of stash reference or null if no more stashed changes * @return commit id of stash reference or null if no more stashed changes
* @throws GitAPIException
*/ */
public ObjectId call() throws GitAPIException { public ObjectId call() throws GitAPIException {
checkCallable(); checkCallable();

+ 2
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java View File

super(repo); super(repo);
} }


public Collection<RevCommit> call() throws GitAPIException {
public Collection<RevCommit> call() throws GitAPIException,
InvalidRefNameException {
checkCallable(); checkCallable();


try { try {

+ 28
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java View File

import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;


import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidConfigurationException;
import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.NoMessageException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.dircache.DirCacheCheckout; import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.ConfigConstants;
return this; return this;
} }


public Collection<String> call() throws GitAPIException {
/**
* Execute the SubmoduleUpdateCommand command.
*
* @return a collection of updated submodule paths
* @throws ConcurrentRefUpdateException
* @throws CheckoutConflictException
* @throws InvalidMergeHeadsException
* @throws InvalidConfigurationException
* @throws NoHeadException
* @throws NoMessageException
* @throws RefNotFoundException
* @throws WrongRepositoryStateException
* @throws GitAPIException
*/
public Collection<String> call() throws InvalidConfigurationException,
NoHeadException, ConcurrentRefUpdateException,
CheckoutConflictException, InvalidMergeHeadsException,
WrongRepositoryStateException, NoMessageException, NoHeadException,
RefNotFoundException, GitAPIException {
checkCallable(); checkCallable();


try { try {
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e); throw new JGitInternalException(e.getMessage(), e);
} catch (ConfigInvalidException e) { } catch (ConfigInvalidException e) {
throw new JGitInternalException(e.getMessage(), e);
} catch (GitAPIException e) {
throw new JGitInternalException(e.getMessage(), e);
throw new InvalidConfigurationException(e.getMessage(), e);
} }
} }
} }

Loading…
Cancel
Save