Class JGitUtils
- java.lang.Object
-
- org.apache.maven.scm.provider.git.jgit.command.JGitUtils
-
public class JGitUtils extends java.lang.ObjectJGit utility functions.- Since:
- 1.9
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.LoggerLOGGER
-
Constructor Summary
Constructors Modifier Constructor Description privateJGitUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<ScmFile>addAllFiles(org.eclipse.jgit.api.Git git, ScmFileSet fileSet)Adds all files in the given fileSet to the repository.static voidcloseRepo(org.eclipse.jgit.api.Git git)Closes the repository wrapped by the passed git object.static org.eclipse.jgit.transport.CredentialsProvidergetCredentials(GitScmProviderRepository repository)Creates a credentials provider from the information passed in the repository.static java.util.List<ScmFile>getFilesInCommit(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit commit)Get a list of all files in the given commit.static java.util.List<ScmFile>getFilesInCommit(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit commit, java.io.File baseDir)Get a list of all files in the given commit.static org.eclipse.jgit.lib.ProgressMonitorgetMonitor()Construct a logging ProgressMonitor for all JGit operations.static java.util.List<org.eclipse.jgit.revwalk.RevCommit>getRevCommits(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevSort[] sortings, java.lang.String fromRev, java.lang.String toRev, java.util.Date fromDate, java.util.Date toDate, int maxLines)Get a list of commits between two revisions.private static java.util.List<ScmFile>getScmFilesForAllFileSetFilesContainedInRepoPath(java.io.File workingCopyDirectory, ScmFileSet fileSet, java.util.Set<java.lang.String> repoFilePaths, ScmFileStatus fileStatus)static ScmFileStatusgetScmFileStatus(org.eclipse.jgit.diff.DiffEntry.ChangeType changeType)Translate aFileStatusin the matchingScmFileStatus.static java.util.List<java.lang.String>getTags(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevCommit commit)Get a list of tags that has been set in the specified commit.static java.util.List<java.io.File>getWorkingCopyRelativePaths(java.io.File workingCopyDirectory, ScmFileSet fileSet)Convert each file in thefileSetto their relative file path to workingCopyDirectory and return them in a list.static booleanhasCommits(org.eclipse.jgit.lib.Repository repo)Does the Repository have any commits?static org.eclipse.jgit.api.GitopenRepo(java.io.File basedir)Opens a JGit repository in the current directory or a parent directory.static org.eclipse.jgit.transport.CredentialsProviderprepareSession(org.eclipse.jgit.api.Git git, GitScmProviderRepository repository)Prepares the in memory configuration of git to connect to the configured repository.static java.lang.Iterable<org.eclipse.jgit.transport.PushResult>push(org.eclipse.jgit.api.Git git, GitScmProviderRepository repo, org.eclipse.jgit.transport.RefSpec refSpec, java.util.Set<org.eclipse.jgit.transport.RemoteRefUpdate.Status> successfulStatuses, java.util.Optional<org.eclipse.jgit.api.TransportConfigCallback> transportConfigCallback)private static java.io.Filerelativize(java.io.File baseDir, java.io.File file)static java.util.List<ScmFile>removeAllFiles(org.eclipse.jgit.api.Git git, ScmFileSet fileSet)Remove all files in the given fileSet from the repository.static java.lang.StringtoNormalizedFilePath(java.io.File file)Converts the given file to a string only containing forward slashes.
-
-
-
Method Detail
-
openRepo
public static org.eclipse.jgit.api.Git openRepo(java.io.File basedir) throws java.io.IOExceptionOpens a JGit repository in the current directory or a parent directory.- Parameters:
basedir- the directory to start with- Throws:
java.io.IOException- if the repository cannot be opened
-
closeRepo
public static void closeRepo(org.eclipse.jgit.api.Git git)
Closes the repository wrapped by the passed git object.- Parameters:
git-
-
getMonitor
public static org.eclipse.jgit.lib.ProgressMonitor getMonitor()
Construct a logging ProgressMonitor for all JGit operations.- Returns:
- a ProgressMonitor for use
-
prepareSession
public static org.eclipse.jgit.transport.CredentialsProvider prepareSession(org.eclipse.jgit.api.Git git, GitScmProviderRepository repository)Prepares the in memory configuration of git to connect to the configured repository. It configures the following settings in memory:
- push url
- fetch url
- Parameters:
git- the instance to configure (only in memory, not saved)repository- the repo config to be used- Returns:
CredentialsProviderin case credential information is configured in the repository
-
getCredentials
public static org.eclipse.jgit.transport.CredentialsProvider getCredentials(GitScmProviderRepository repository)
Creates a credentials provider from the information passed in the repository. Current implementation supports:
- UserName/Password
- Parameters:
repository- the config to get the details from- Returns:
nullif there is not enough info to create a provider with
-
push
public static java.lang.Iterable<org.eclipse.jgit.transport.PushResult> push(org.eclipse.jgit.api.Git git, GitScmProviderRepository repo, org.eclipse.jgit.transport.RefSpec refSpec, java.util.Set<org.eclipse.jgit.transport.RemoteRefUpdate.Status> successfulStatuses, java.util.Optional<org.eclipse.jgit.api.TransportConfigCallback> transportConfigCallback) throws PushException- Throws:
PushException
-
hasCommits
public static boolean hasCommits(org.eclipse.jgit.lib.Repository repo)
Does the Repository have any commits?- Parameters:
repo-- Returns:
- false if there are no commits
-
getFilesInCommit
public static java.util.List<ScmFile> getFilesInCommit(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit commit) throws org.eclipse.jgit.errors.MissingObjectException, org.eclipse.jgit.errors.IncorrectObjectTypeException, org.eclipse.jgit.errors.CorruptObjectException, java.io.IOException
Get a list of all files in the given commit.- Parameters:
repository- the repocommit- the commit to get the files from- Returns:
- a list of files included in the commit
- Throws:
org.eclipse.jgit.errors.CorruptObjectExceptionorg.eclipse.jgit.errors.IncorrectObjectTypeExceptionjava.io.IOExceptionorg.eclipse.jgit.errors.MissingObjectException
-
getFilesInCommit
public static java.util.List<ScmFile> getFilesInCommit(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit commit, java.io.File baseDir) throws org.eclipse.jgit.errors.MissingObjectException, org.eclipse.jgit.errors.IncorrectObjectTypeException, org.eclipse.jgit.errors.CorruptObjectException, java.io.IOException
Get a list of all files in the given commit.- Parameters:
repository- the repocommit- the commit to get the files frombaseDir- the directory to which the returned files should be relative. May benullin case they should be relative to the working directory root.- Returns:
- a list of files included in the commit
- Throws:
org.eclipse.jgit.errors.CorruptObjectExceptionorg.eclipse.jgit.errors.IncorrectObjectTypeExceptionjava.io.IOExceptionorg.eclipse.jgit.errors.MissingObjectException
-
getScmFileStatus
public static ScmFileStatus getScmFileStatus(org.eclipse.jgit.diff.DiffEntry.ChangeType changeType)
Translate aFileStatusin the matchingScmFileStatus.- Parameters:
changeType-- Returns:
- the matching ScmFileStatus
-
addAllFiles
public static java.util.List<ScmFile> addAllFiles(org.eclipse.jgit.api.Git git, ScmFileSet fileSet) throws org.eclipse.jgit.api.errors.GitAPIException
Adds all files in the given fileSet to the repository.- Parameters:
git- the repo to add the files tofileSet- the set of files within the workspace, the files are added relative to the basedir of this fileset- Returns:
- a list of added files
- Throws:
org.eclipse.jgit.api.errors.GitAPIException
-
removeAllFiles
public static java.util.List<ScmFile> removeAllFiles(org.eclipse.jgit.api.Git git, ScmFileSet fileSet) throws org.eclipse.jgit.api.errors.GitAPIException
Remove all files in the given fileSet from the repository.- Parameters:
git- the repo to remove the files fromfileSet- the set of files within the workspace, the files are removed relative to the basedir of this fileset- Returns:
- a list of removed files
- Throws:
org.eclipse.jgit.api.errors.GitAPIException
-
getWorkingCopyRelativePaths
public static java.util.List<java.io.File> getWorkingCopyRelativePaths(java.io.File workingCopyDirectory, ScmFileSet fileSet)Convert each file in thefileSetto their relative file path to workingCopyDirectory and return them in a list.- Parameters:
workingCopyDirectory- the working copy root directoryfileSet- the file set to convert
-
toNormalizedFilePath
public static java.lang.String toNormalizedFilePath(java.io.File file)
Converts the given file to a string only containing forward slashes.- Parameters:
file-- Returns:
- the normalized file path
-
getScmFilesForAllFileSetFilesContainedInRepoPath
private static java.util.List<ScmFile> getScmFilesForAllFileSetFilesContainedInRepoPath(java.io.File workingCopyDirectory, ScmFileSet fileSet, java.util.Set<java.lang.String> repoFilePaths, ScmFileStatus fileStatus)
-
relativize
private static java.io.File relativize(java.io.File baseDir, java.io.File file)
-
getRevCommits
public static java.util.List<org.eclipse.jgit.revwalk.RevCommit> getRevCommits(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevSort[] sortings, java.lang.String fromRev, java.lang.String toRev, java.util.Date fromDate, java.util.Date toDate, int maxLines) throws java.io.IOException, org.eclipse.jgit.errors.MissingObjectException, org.eclipse.jgit.errors.IncorrectObjectTypeExceptionGet a list of commits between two revisions.- Parameters:
repo- the repository to work onsortings- sortingfromRev- start revisiontoRev- if null, falls back to headfromDate- from which date ontoDate- until which datemaxLines- max number of lines- Returns:
- a list of commits, might be empty, but never
null - Throws:
org.eclipse.jgit.errors.IncorrectObjectTypeExceptionjava.io.IOExceptionorg.eclipse.jgit.errors.MissingObjectException
-
getTags
public static java.util.List<java.lang.String> getTags(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevCommit commit) throws java.io.IOExceptionGet a list of tags that has been set in the specified commit.- Parameters:
repo- the repository to work oncommit- the commit for which we want the tags- Returns:
- a list of tags, might be empty, and never
null - Throws:
java.io.IOException
-
-