diff options
author | Ian Wetherbee <wetherbeei@google.com> | 2012-06-07 15:15:12 -0700 |
---|---|---|
committer | Ian Wetherbee <wetherbeei@google.com> | 2012-06-14 11:52:10 -0700 |
commit | 242716092f2e3786f8f23176c9d7e93e4900d03a (patch) | |
tree | 1560134ab410e470c0715b6e4df927d0a352ce21 /org.eclipse.jgit | |
parent | 90003519092c4be2f7806b171cd1c2d37a05f588 (diff) | |
download | jgit-242716092f2e3786f8f23176c9d7e93e4900d03a.tar.gz jgit-242716092f2e3786f8f23176c9d7e93e4900d03a.zip |
Add Transport URI constructor without a repository
Let a Transport instance be opened with only a URI, for use in the
upcoming publish-subscribe feature.
Change-Id: I391c60c10d034b5c1c0ef19b1f24a9ba76b17bb5
Diffstat (limited to 'org.eclipse.jgit')
6 files changed, 91 insertions, 0 deletions
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index 93392e2026..be60802285 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -450,6 +450,7 @@ transportExceptionEmptyRef=Empty ref: {0} transportExceptionInvalid=Invalid {0} {1}:{2} transportExceptionMissingAssumed=Missing assumed {0} transportExceptionReadRef=read {0} +transportNeedsRepository=Transport needs repository transportProtoAmazonS3=Amazon S3 transportProtoBundleFile=Git Bundle File transportProtoFTP=FTP diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index bcc9589da3..aca9574a5b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -510,6 +510,7 @@ public class JGitText extends TranslationBundle { /***/ public String transportExceptionInvalid; /***/ public String transportExceptionMissingAssumed; /***/ public String transportExceptionReadRef; + /***/ public String transportNeedsRepository; /***/ public String transportProtoAmazonS3; /***/ public String transportProtoBundleFile; /***/ public String transportProtoFTP; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpTransport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpTransport.java index 3793a0abfb..4f8f89df9b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpTransport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpTransport.java @@ -66,4 +66,13 @@ public abstract class HttpTransport extends Transport { protected HttpTransport(Repository local, URIish uri) { super(local, uri); } + + /** + * Create a minimal HTTP transport instance not tied to a single repository. + * + * @param uri + */ + protected HttpTransport(URIish uri) { + super(uri); + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java index 90fdf4d9d8..affccf947a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -557,6 +557,29 @@ public abstract class Transport { } /** + * Open a new transport with no local repository. + * + * @param uri + * @return new Transport instance + * @throws NotSupportedException + * @throws TransportException + */ + public static Transport open(URIish uri) throws NotSupportedException, TransportException { + for (WeakReference<TransportProtocol> ref : protocols) { + TransportProtocol proto = ref.get(); + if (proto == null) { + protocols.remove(ref); + continue; + } + + if (proto.canHandle(uri, null, null)) + return proto.open(uri); + } + + throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri)); + } + + /** * Convert push remote refs update specification from {@link RefSpec} form * to {@link RemoteRefUpdate}. Conversion expands wildcards by matching * source part to local refs. expectedOldObjectId in RemoteRefUpdate is @@ -746,6 +769,18 @@ public abstract class Transport { } /** + * Create a minimal transport instance not tied to a single repository. + * + * @param uri + */ + protected Transport(final URIish uri) { + this.uri = uri; + this.local = null; + this.checkFetchedObjects = true; + this.credentialsProvider = CredentialsProvider.getDefault(); + } + + /** * Get the URI this transport connects to. * <p> * Each transport instance connects to at most one URI at any point in time. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java index 71f5bcb51e..7adeeca50c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -167,6 +167,10 @@ public class TransportHttp extends HttpTransport implements WalkTransport, throws NotSupportedException { return new TransportHttp(local, uri); } + + public Transport open(URIish uri) throws NotSupportedException { + return new TransportHttp(uri); + } }; static final TransportProtocol PROTO_FTP = new TransportProtocol() { @@ -224,6 +228,10 @@ public class TransportHttp extends HttpTransport implements WalkTransport, postBuffer = rc.getInt("http", "postbuffer", 1 * 1024 * 1024); //$NON-NLS-1$ //$NON-NLS-2$ sslVerify = rc.getBoolean("http", "sslVerify", true); } + + private HttpConfig() { + this(new Config()); + } } private final URL baseUrl; @@ -255,6 +263,27 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } /** + * Create a minimal HTTP transport with default configuration values. + * + * @param uri + * @throws NotSupportedException + */ + TransportHttp(final URIish uri) throws NotSupportedException { + super(uri); + try { + String uriString = uri.toString(); + if (!uriString.endsWith("/")) //$NON-NLS-1$ + uriString += "/"; //$NON-NLS-1$ + baseUrl = new URL(uriString); + objectsUrl = new URL(baseUrl, "objects/"); //$NON-NLS-1$ + } catch (MalformedURLException e) { + throw new NotSupportedException(MessageFormat.format(JGitText.get().invalidURL, uri), e); + } + http = new HttpConfig(); + proxySelector = ProxySelector.getDefault(); + } + + /** * Toggle whether or not smart HTTP transport should be used. * <p> * This flag exists primarily to support backwards compatibility testing diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java index 32fa58046e..e08efc4eaf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java @@ -49,6 +49,7 @@ import java.util.Set; import org.eclipse.jgit.errors.NotSupportedException; import org.eclipse.jgit.errors.TransportException; +import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.Repository; /** @@ -253,4 +254,19 @@ public abstract class TransportProtocol { public abstract Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException, TransportException; + + /** + * Open a new transport instance to the remote repository. Use default + * configuration instead of reading from configuration files. + * + * @param uri + * @return new Transport + * @throws NotSupportedException + * @throws TransportException + */ + public Transport open(URIish uri) + throws NotSupportedException, TransportException { + throw new NotSupportedException(JGitText + .get().transportNeedsRepository); + } } |