Browse Source

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
stable-2.1
Ian Wetherbee 13 years ago
parent
commit
242716092f
  1. 1
      org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
  2. 1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
  3. 9
      org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpTransport.java
  4. 35
      org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
  5. 29
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
  6. 16
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportProtocol.java

1
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

1
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;

9
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);
}
}

35
org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java

@ -556,6 +556,29 @@ public abstract class Transport {
throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri));
}
/**
* 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
@ -745,6 +768,18 @@ public abstract class Transport {
this.credentialsProvider = CredentialsProvider.getDefault();
}
/**
* 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>

29
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;
@ -254,6 +262,27 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
proxySelector = ProxySelector.getDefault();
}
/**
* 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>

16
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);
}
}

Loading…
Cancel
Save