summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorIan Wetherbee2012-06-07 18:15:12 (EDT)
committer Ian Wetherbee2012-06-14 14:52:10 (EDT)
commit242716092f2e3786f8f23176c9d7e93e4900d03a (patch)
tree1560134ab410e470c0715b6e4df927d0a352ce21
parent90003519092c4be2f7806b171cd1c2d37a05f588 (diff)
downloadjgit-242716092f2e3786f8f23176c9d7e93e4900d03a.zip
jgit-242716092f2e3786f8f23176c9d7e93e4900d03a.tar.gz
jgit-242716092f2e3786f8f23176c9d7e93e4900d03a.tar.bz2
Add Transport URI constructor without a repositoryrefs/changes/60/6360/1
Let a Transport instance be opened with only a URI, for use in the upcoming publish-subscribe feature. Change-Id: I391c60c10d034b5c1c0ef19b1f24a9ba76b17bb5
-rw-r--r--org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpTransport.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java35
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java29
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java16
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 93392e2..be60802 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 bcc9589..aca9574 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 3793a0a..4f8f89d 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 90fdf4d..affccf9 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 71f5bcb..7adeeca 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 32fa580..e08efc4 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);
+ }
}