Class Git
- java.lang.Object
-
- com.mooltiverse.oss.nyx.services.git.Git
-
- All Implemented Interfaces:
GitLocalService
,GitRemoteService
,Service
public class Git extends Object implements GitLocalService, GitRemoteService
The entry point to the Git local and remote service. This is also the main entry point to retrieveRepository
instances
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.mooltiverse.oss.nyx.services.Service
Service.Feature
-
-
Field Summary
Fields Modifier and Type Field Description static String
PASSWORD_OPTION_NAME
The name of the option used to pass the password to this object instance.static String
REMOTES_OPTION_NAME
The name of the option used to pass the list of supported remotes to this object instance.static String
USER_OPTION_NAME
The name of the option used to pass the user name to this object instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Repository
clone(File directory, URI uri)
Returns a repository instance working in the given directory after cloning from the given URI.Repository
clone(File directory, URI uri, String user, String password)
Returns a repository instance working in the given directory after cloning from the given URI.Repository
clone(String directory, String uri)
Returns a repository instance working in the given directory after cloning from the given URI.Repository
clone(String directory, String uri, String user, String password)
Returns a repository instance working in the given directory after cloning from the given URI.String
getPassword()
Returns the password to be used when connecting to remote repositories.List<String>
getSupportedRemoteNames()
Returns the list of the remote repositories supported by this service.String
getUser()
Returns the user name to be used when connecting to remote repositories.static Git
instance()
Returns an instance using default options.static Git
instance(Map<String,String> options)
Returns an instance using the given options.Repository
open(File directory)
Returns a repository instance working in the given directory.Repository
open(String directory)
Returns a repository instance working in the given directory.void
setPassword(String password)
Sets the password to be used when connecting to remote repositories.void
setSupportedRemoteNames(List<String> remotes)
Sets the list of the remote repositories supported by this service.void
setUser(String user)
Sets the user name to be used when connecting to remote repositories.boolean
supports(Service.Feature feature)
Safely checks if the underlying implementation supports the given operation.
-
-
-
Field Detail
-
REMOTES_OPTION_NAME
public static final String REMOTES_OPTION_NAME
The name of the option used to pass the list of supported remotes to this object instance. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the service will not be able to perform some of its operations. Value: "REMOTES"- See Also:
- Constant Field Values
-
USER_OPTION_NAME
public static final String USER_OPTION_NAME
The name of the option used to pass the user name to this object instance. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the service will not be able to authenticate and perform any of the authentication protected operations. Value: "USER"- See Also:
- Constant Field Values
-
PASSWORD_OPTION_NAME
public static final String PASSWORD_OPTION_NAME
The name of the option used to pass the password to this object instance. This is the value of the key inside the options passed to get a new instance of this class. If this option is not passed the service will not be able to authenticate and perform any of the authentication protected operations. Value: "PASSWORD"- See Also:
- Constant Field Values
-
-
Method Detail
-
instance
public static Git instance()
Returns an instance using default options.- Returns:
- an instance using default options.
-
instance
public static Git instance(Map<String,String> options)
Returns an instance using the given options.- Parameters:
options
- the map of options for the requested service. It can't benull
. Valid options are documented as constants on this class.- Returns:
- an instance using the given options.
- Throws:
NullPointerException
- if the given options map isnull
IllegalArgumentException
- if some entries in the given options map are missing or illegal for some reason
-
clone
public Repository clone(File directory, URI uri) throws GitException
Returns a repository instance working in the given directory after cloning from the given URI. If the instance has some credentials set, those are used to perform the operation, otherwise anonymous access will be used.- Specified by:
clone
in interfaceGitLocalService
- Parameters:
directory
- the directory where the repository has to be cloned. It is created if it doesn't exist.uri
- the URI of the remote repository to clone.- Returns:
- the new repository object.
- Throws:
GitException
- in case the operation fails for some reason, including when authentication fails
-
clone
public Repository clone(File directory, URI uri, String user, String password) throws GitException
Returns a repository instance working in the given directory after cloning from the given URI.- Specified by:
clone
in interfaceGitLocalService
- Parameters:
directory
- the directory where the repository has to be cloned. It is created if it doesn't exist.uri
- the URI of the remote repository to clone.user
- the user name to use when credentials are required. If this andpassword
are bothnull
then no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.password
- the password to use when credentials are required. If this anduser
are bothnull
then no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.- Returns:
- the new repository object.
- Throws:
GitException
- in case the operation fails for some reason, including when authentication fails
-
clone
public Repository clone(String directory, String uri) throws GitException
Returns a repository instance working in the given directory after cloning from the given URI. If the instance has some credentials set, those are used to perform the operation, otherwise anonymous access will be used.- Specified by:
clone
in interfaceGitLocalService
- Parameters:
directory
- the directory where the repository has to be cloned. It is created if it doesn't exist.uri
- the URI of the remote repository to clone.- Returns:
- the new repository object.
- Throws:
GitException
- in case the operation fails for some reason, including when authentication fails
-
clone
public Repository clone(String directory, String uri, String user, String password) throws GitException
Returns a repository instance working in the given directory after cloning from the given URI.- Specified by:
clone
in interfaceGitLocalService
- Parameters:
directory
- the directory where the repository has to be cloned. It is created if it doesn't exist.uri
- the URI of the remote repository to clone.user
- the user name to use when credentials are required. If this andpassword
are bothnull
then no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.password
- the password to use when credentials are required. If this anduser
are bothnull
then no credentials is used. When using single token authentication (i.e. OAuth or Personal Access Tokens) this value may be the token or something other than a token, depending on the remote provider.- Returns:
- the new repository object.
- Throws:
GitException
- in case the operation fails for some reason, including when authentication fails
-
getSupportedRemoteNames
public List<String> getSupportedRemoteNames()
Returns the list of the remote repositories supported by this service. The names returned are simple names like those returned by agit remote
command.
The returned list is meant to be used as a filter so when it'snull
it means that any remote is supported.- Specified by:
getSupportedRemoteNames
in interfaceGitRemoteService
- Returns:
- the list of the remote repositories supported by this service. When
null
or empty any remote is supported by this service.
-
getUser
public String getUser()
Returns the user name to be used when connecting to remote repositories.- Specified by:
getUser
in interfaceGitRemoteService
- Returns:
- the user name to be used when connecting to remote repositories.
When
null
the remote repositories are meant to allow anonymous access and, in this case, also thepassword
isnull
.
-
getPassword
public String getPassword()
Returns the password to be used when connecting to remote repositories.- Specified by:
getPassword
in interfaceGitRemoteService
- Returns:
- the password to be used when connecting to remote repositories.
When
GitRemoteService.getUser()
returnsnull
this method also returnsnull
amd the remote repositories are meant to allow anonymous access.
-
open
public Repository open(File directory) throws IOException
Returns a repository instance working in the given directory.- Specified by:
open
in interfaceGitLocalService
- Parameters:
directory
- the directory where the repository is.- Returns:
- the new repository object.
- Throws:
IOException
- in case of any I/O issue accessing the repository
-
open
public Repository open(String directory) throws IOException
Returns a repository instance working in the given directory.- Specified by:
open
in interfaceGitLocalService
- Parameters:
directory
- the directory where the repository is.- Returns:
- the new repository object.
- Throws:
IOException
- in case of any I/O issue accessing the repository
-
setSupportedRemoteNames
public void setSupportedRemoteNames(List<String> remotes)
Sets the list of the remote repositories supported by this service. The names returned are simple names like those returned by agit remote
command.
The given list is meant to be used as a filter so when it'snull
it means that any remote is supported.- Parameters:
remotes
- the list of the remote repositories supported by this service. Whennull
or empty any remote is supported by this service.- Throws:
UnsupportedOperationException
- if the underlying implementation does notsupport
theService.Feature.GIT_REMOTE
feature.
-
setUser
public void setUser(String user)
Sets the user name to be used when connecting to remote repositories.- Parameters:
user
- the user name to be used when connecting to remote repositories. Whennull
the remote repositories are meant to allow anonymous access.- Throws:
UnsupportedOperationException
- if the underlying implementation does notsupport
theService.Feature.GIT_REMOTE
feature.
-
setPassword
public void setPassword(String password)
Sets the password to be used when connecting to remote repositories.- Parameters:
password
- the password to be used when connecting to remote repositories.- Throws:
UnsupportedOperationException
- if the underlying implementation does notsupport
theService.Feature.GIT_REMOTE
feature.
-
supports
public boolean supports(Service.Feature feature)
Safely checks if the underlying implementation supports the given operation. If this method returnstrue
then the underlying class will not raise anyUnsupportedOperationException
when invoking the specific methods.
-
-