1 /*******************************************************************************
2 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
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 *******************************************************************************/
10 package org
.eclipse
.egit
.core
.op
;
12 import java
.lang
.reflect
.InvocationTargetException
;
13 import java
.util
.Collection
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.egit
.core
.CoreText
;
18 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
19 import org
.eclipse
.jgit
.errors
.NotSupportedException
;
20 import org
.eclipse
.jgit
.errors
.TransportException
;
21 import org
.eclipse
.jgit
.lib
.Ref
;
22 import org
.eclipse
.jgit
.lib
.Repository
;
23 import org
.eclipse
.jgit
.transport
.Connection
;
24 import org
.eclipse
.jgit
.transport
.Transport
;
25 import org
.eclipse
.jgit
.transport
.URIish
;
28 * Operation of listing remote repository advertised refs.
30 public class ListRemoteOperation
implements IRunnableWithProgress
{
31 private final Repository localDb
;
33 private final URIish uri
;
35 private Map
<String
, Ref
> remoteRefsMap
;
38 * Create listing operation for specified local repository (needed by
39 * transport) and remote repository URI.
42 * local repository (needed for transport) where fetch would
45 * URI of remote repository to list.
47 public ListRemoteOperation(final Repository localDb
, final URIish uri
) {
48 this.localDb
= localDb
;
53 * @return collection of refs advertised by remote side.
54 * @throws IllegalStateException
55 * if error occurred during earlier remote refs listing.
57 public Collection
<Ref
> getRemoteRefs() {
59 return remoteRefsMap
.values();
64 * remote ref name to search for.
65 * @return ref with specified refName or null if not found.
66 * @throws IllegalStateException
67 * if error occurred during earlier remote refs listing.
69 public Ref
getRemoteRef(final String refName
) {
71 return remoteRefsMap
.get(refName
);
74 public void run(IProgressMonitor pm
) throws InvocationTargetException
,
75 InterruptedException
{
76 Transport transport
= null;
77 Connection connection
= null;
79 transport
= Transport
.open(localDb
, uri
);
82 pm
.beginTask(CoreText
.ListRemoteOperation_title
,
83 IProgressMonitor
.UNKNOWN
);
84 connection
= transport
.openFetch();
85 remoteRefsMap
= connection
.getRefsMap();
86 } catch (NotSupportedException e
) {
87 throw new InvocationTargetException(e
);
88 } catch (TransportException e
) {
89 throw new InvocationTargetException(e
);
91 if (connection
!= null)
93 if (transport
!= null)
100 private void checkState() {
101 if (remoteRefsMap
== null)
102 throw new IllegalStateException(
103 "Error occurred during remote repo listing, no refs available");