Top Description Inners Constructors Methods
org.eclipse.jgit.transport

public abstract Class TransportProtocol

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.transport.TestProtocol
Imports
java.util.Collections, .EnumSet, .Set, org.eclipse.jgit.errors.NotSupportedException, .TransportException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.Repository

Describes a way to connect to another Git repository.

Implementations of this class are typically immutable singletons held by static class members, for example:

package com.example.my_transport;

class MyTransport extends Transport {
	public static final TransportProtocol PROTO = new TransportProtocol() {
		public String getName() {
			return "My Protocol";
		}
	};
}

Applications may register additional protocols for use by JGit by calling org.eclipse.jgit.transport.Transport#register(TransportProtocol). Because that API holds onto the protocol object by a WeakReference, applications must ensure their own ClassLoader retains the TransportProtocol for the life of the application. Using a static singleton pattern as above will ensure the protocol is valid so long as the ClassLoader that defines it remains valid.

Applications may automatically register additional protocols by filling in the names of their TransportProtocol defining classes using the services file META-INF/services/org.eclipse.jgit.transport.Transport. For each class name listed in the services file, any static fields of type TransportProtocol will be automatically registered. For the above example the string com.example.my_transport.MyTransport should be listed in the file, as that is the name of the class that defines the static PROTO singleton.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
TransportProtocol.URIishField

Fields within a URIish that a transport uses.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this protocol can handle this URI; false otherwise.
canHandle
(URIish
address of the Git repository; never null.
uri
)

Determine if this protocol can handle a particular URI.

public boolean

Returns:

true if this protocol can handle this URI; false otherwise.
canHandle
(URIish
address of the Git repository; never null.
uri
,
Repository
the local repository that will communicate with the other Git repository. May be null if the caller is only asking about a specific URI and does not have a local Repository.
local
,
String
name of the remote, if the remote as configured in local; otherwise null.
remoteName
)

Determine if this protocol can handle a particular URI.

public int

Returns:

the default port if the protocol supports a port, else -1.
getDefaultPort
()

Get the default port if the protocol supports a port, else -1.

public abstract String

Returns:

text name of the protocol suitable for display to a user.
getName
()

Get text name of the protocol suitable for display to a user.

public Set<TransportProtocol.URIishField>

Returns:

immutable set of URIishFields that may be filled in.
getOptionalFields
()

Get immutable set of URIishFields that may be filled in.

public Set<TransportProtocol.URIishField>

Returns:

immutable set of URIishFields that must be filled in.
getRequiredFields
()

Get immutable set of URIishFields that must be filled in.

public Set<String>

Returns:

immutable set of schemes supported by this protocol.
getSchemes
()

Get immutable set of schemes supported by this protocol.

public abstract Transport

Returns:

the transport.
open
(URIish
address of the Git repository.
uri
,
Repository
the local repository that will communicate with the other Git repository.
local
,
String
name of the remote, if the remote as configured in local; otherwise null.
remoteName
)

Open a Transport instance to the other repository.

public Transport

Returns:

new Transport
open
(URIish uri)

Open a new transport instance to the remote repository.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

TransportProtocolback to summary
public TransportProtocol()

Method Detail

canHandleback to summary
public boolean canHandle(URIish uri)

Determine if this protocol can handle a particular URI.

Implementations should try to avoid looking at the local filesystem, but may look at implementation specific configuration options in the remote block of local.getConfig() using remoteName if the name is non-null.

The default implementation of this method matches the scheme against getSchemes(), required fields against getRequiredFields(), and optional fields against getOptionalFields(), returning true only if all of the fields match the specification.

Parameters
uri:URIish

address of the Git repository; never null.

Returns:boolean

true if this protocol can handle this URI; false otherwise.

canHandleback to summary
public boolean canHandle(URIish uri, Repository local, String remoteName)

Determine if this protocol can handle a particular URI.

Implementations should try to avoid looking at the local filesystem, but may look at implementation specific configuration options in the remote block of local.getConfig() using remoteName if the name is non-null.

The default implementation of this method matches the scheme against getSchemes(), required fields against getRequiredFields(), and optional fields against getOptionalFields(), returning true only if all of the fields match the specification.

Parameters
uri:URIish

address of the Git repository; never null.

local:Repository

the local repository that will communicate with the other Git repository. May be null if the caller is only asking about a specific URI and does not have a local Repository.

remoteName:String

name of the remote, if the remote as configured in local; otherwise null.

Returns:boolean

true if this protocol can handle this URI; false otherwise.

getDefaultPortback to summary
public int getDefaultPort()

Get the default port if the protocol supports a port, else -1.

Returns:int

the default port if the protocol supports a port, else -1.

getNameback to summary
public abstract String getName()

Get text name of the protocol suitable for display to a user.

Returns:String

text name of the protocol suitable for display to a user.

getOptionalFieldsback to summary
public Set<TransportProtocol.URIishField> getOptionalFields()

Get immutable set of URIishFields that may be filled in.

Returns:Set<TransportProtocol.URIishField>

immutable set of URIishFields that may be filled in.

getRequiredFieldsback to summary
public Set<TransportProtocol.URIishField> getRequiredFields()

Get immutable set of URIishFields that must be filled in.

Returns:Set<TransportProtocol.URIishField>

immutable set of URIishFields that must be filled in.

getSchemesback to summary
public Set<String> getSchemes()

Get immutable set of schemes supported by this protocol.

Returns:Set<String>

immutable set of schemes supported by this protocol.

openback to summary
public abstract Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException, TransportException

Open a Transport instance to the other repository.

Implementations should avoid making remote connections until an operation on the returned Transport is invoked, however they may fail fast here if they know a connection is impossible, such as when using the local filesystem and the target path does not exist.

Implementations may access implementation-specific configuration options within local.getConfig() using the remote block named by the remoteName, if the name is non-null.

Parameters
uri:URIish

address of the Git repository.

local:Repository

the local repository that will communicate with the other Git repository.

remoteName:String

name of the remote, if the remote as configured in local; otherwise null.

Returns:Transport

the transport.

Exceptions
NotSupportedException:
this protocol does not support the URI.
TransportException:
the transport cannot open this URI.
openback to summary
public Transport open(URIish uri) throws NotSupportedException, TransportException

Open a new transport instance to the remote repository. Use default configuration instead of reading from configuration files.

Parameters
uri:URIish

a org.eclipse.jgit.transport.URIish object.

Returns:Transport

new Transport

Exceptions
NotSupportedException:
this protocol does not support the URI.
TransportException:
the transport cannot open this URI.
org.eclipse.jgit.transport back to summary

public final Enum TransportProtocol.URIishField

extends Enum<TransportProtocol.URIishField>
Class Inheritance

Fields within a URIish that a transport uses.

Field Summary

Modifier and TypeField and Description
public static final TransportProtocol.URIishField
HOST

the host field

public static final TransportProtocol.URIishField
PASS

the pass (aka password) field

public static final TransportProtocol.URIishField
PATH

the path field

public static final TransportProtocol.URIishField
PORT

the port field

public static final TransportProtocol.URIishField
USER

the user field

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static TransportProtocol.URIishField
public static TransportProtocol.URIishField[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

HOSTback to summary
public static final TransportProtocol.URIishField HOST

the host field

PASSback to summary
public static final TransportProtocol.URIishField PASS

the pass (aka password) field

PATHback to summary
public static final TransportProtocol.URIishField PATH

the path field

PORTback to summary
public static final TransportProtocol.URIishField PORT

the port field

USERback to summary
public static final TransportProtocol.URIishField USER

the user field

Constructor Detail

URIishFieldback to summary
private URIishField()

Method Detail

valueOfback to summary
public static TransportProtocol.URIishField valueOf(String name)
valuesback to summary
public static TransportProtocol.URIishField[] values()