Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2012-01-08 21:08:08 +0000
committerKevin Sawicki2012-01-09 01:15:05 +0000
commit0f15d656f26d48516eee661bacfd7e9750b35ab3 (patch)
tree58fecab8e588f27c8cb89ccfcfea6a05b69bc1b8
parent0806c803a9d549b1c44691dd63ebeb49b3e01ffe (diff)
downloadjgit-0f15d656f26d48516eee661bacfd7e9750b35ab3.tar.gz
jgit-0f15d656f26d48516eee661bacfd7e9750b35ab3.tar.xz
jgit-0f15d656f26d48516eee661bacfd7e9750b35ab3.zip
Narrow exceptions declared by LsRemoteCommand
API commands either throw GitAPIException or JGitInternalException. Also add missing javadoc and reduce nesting of catch blocks. Change-Id: I9a3b302e1b3f373ee11a977a0e3d6213bfbd3cdf Signed-off-by: Matthias Sohn <matthias.sohn@sap.com> Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java87
1 files changed, 47 insertions, 40 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java
index f158596143..4a0a8a6464 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.api;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.ArrayList;
@@ -50,10 +51,9 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.jgit.JGitText;
+import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.JGitInternalException;
-import org.eclipse.jgit.errors.NotSupportedException;
-import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -128,56 +128,63 @@ public class LsRemoteCommand extends
this.uploadPack = uploadPack;
}
- public Collection<Ref> call() throws Exception {
+ /**
+ * Executes the {@code LsRemote} command with all the options and parameters
+ * collected by the setter methods (e.g. {@link #setHeads(boolean)}) of this
+ * class. Each instance of this class should only be used for one invocation
+ * of the command. Don't call this method twice on an instance.
+ *
+ * @return a collection of references in the remote repository
+ * @throws InvalidRemoteException
+ * when called with an invalid remote uri
+ * @throws JGitInternalException
+ * a low-level exception of JGit has occurred. The original
+ * exception can be retrieved by calling
+ * {@link Exception#getCause()}.
+ */
+ public Collection<Ref> call() throws GitAPIException,
+ JGitInternalException {
checkCallable();
+ Transport transport = null;
+ FetchConnection fc = null;
try {
- Transport transport = Transport.open(repo, remote);
+ transport = Transport.open(repo, remote);
transport.setOptionUploadPack(uploadPack);
configure(transport);
-
- try {
- Collection<RefSpec> refSpecs = new ArrayList<RefSpec>(1);
- if (tags)
- refSpecs.add(new RefSpec(
- "refs/tags/*:refs/remotes/origin/tags/*"));
- if (heads)
- refSpecs.add(new RefSpec(
- "refs/heads/*:refs/remotes/origin/*"));
- Collection<Ref> refs;
- Map<String, Ref> refmap = new HashMap<String, Ref>();
- FetchConnection fc = transport.openFetch();
- try {
- refs = fc.getRefs();
- if (refSpecs.isEmpty())
- for (Ref r : refs)
+ Collection<RefSpec> refSpecs = new ArrayList<RefSpec>(1);
+ if (tags)
+ refSpecs.add(new RefSpec(
+ "refs/tags/*:refs/remotes/origin/tags/*"));
+ if (heads)
+ refSpecs.add(new RefSpec("refs/heads/*:refs/remotes/origin/*"));
+ Collection<Ref> refs;
+ Map<String, Ref> refmap = new HashMap<String, Ref>();
+ fc = transport.openFetch();
+ refs = fc.getRefs();
+ if (refSpecs.isEmpty())
+ for (Ref r : refs)
+ refmap.put(r.getName(), r);
+ else
+ for (Ref r : refs)
+ for (RefSpec rs : refSpecs)
+ if (rs.matchSource(r)) {
refmap.put(r.getName(), r);
- else
- for (Ref r : refs)
- for (RefSpec rs : refSpecs)
- if (rs.matchSource(r)) {
- refmap.put(r.getName(), r);
- break;
- }
- } finally {
- fc.close();
- }
- return refmap.values();
-
- } catch (TransportException e) {
- throw new JGitInternalException(
- JGitText.get().exceptionCaughtDuringExecutionOfLsRemoteCommand,
- e);
- } finally {
- transport.close();
- }
+ break;
+ }
+ return refmap.values();
} catch (URISyntaxException e) {
throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote));
- } catch (NotSupportedException e) {
+ } catch (IOException e) {
throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfLsRemoteCommand,
e);
+ } finally {
+ if (fc != null)
+ fc.close();
+ if (transport != null)
+ transport.close();
}
}

Back to the top