Package com.simplicite.util.tools
Class GitTool
- java.lang.Object
-
- com.simplicite.util.tools.GitTool
-
public class GitTool extends java.lang.Object
Git toolbox
This class only provides static variables and methods
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
HEAD
Head revisionstatic java.lang.String
MASTER
Master branch namestatic java.lang.String
ORIGIN
Originstatic java.lang.String
POM_FOOTER
POM file footerstatic java.lang.String
POM_HEADER
POM file header
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addRemote(java.io.File dir, java.lang.String name, java.lang.String uri)
Add remotestatic void
checkout(ObjectDB mdl, java.lang.String commitId)
Checkout commit ID in module's repository worktreestatic void
checkout(ObjectDB mdl, java.lang.String branch, boolean create, java.lang.String remoteBranch)
Checkout a branch in module's repository worktreestatic void
checkout(java.io.File dir, java.lang.String commitId)
Checkout a commit ID in the repository worktree.static void
checkout(java.io.File dir, java.lang.String branch, boolean create, java.lang.String remoteBranch)
Checkout a branch in the repository worktree.static void
clone(java.io.File dir, java.lang.String uri, java.lang.String username, java.lang.String password, java.lang.String remote, java.lang.String branch)
Clone an existing repositorystatic java.lang.String
commitModule(ObjectDB mdl, java.lang.String msg)
Deprecated.Use commitModule with addtional format parameterstatic java.lang.String
commitModule(ObjectDB mdl, java.lang.String format, java.lang.String msg)
Commit selected modulestatic org.eclipse.jgit.api.Git
create(java.io.File dir)
Create a new repositorystatic java.lang.String
delete(ObjectDB mdl)
Move the module's directory to the recylebin if it exists (or simply delete it if move is not sucessful)static java.lang.String
dumpCommit(org.eclipse.jgit.lib.Repository rep, org.eclipse.jgit.lib.ObjectId commitId)
Dump commit informationstatic java.lang.String
dumpModuleCommit(ObjectDB mdl, org.eclipse.jgit.lib.ObjectId commitId)
Dump module's commit for specified row IDstatic void
fetch(java.io.File dir, java.lang.String username, java.lang.String password, java.lang.String remote)
Fetch from remotestatic org.json.JSONArray
getAllCommits(org.eclipse.jgit.lib.Repository rep, int n)
Get last commits informationstatic org.json.JSONArray
getAllModuleCommits(ObjectDB mdl, int n)
Get modules's last commits information for modulestatic java.util.List<java.lang.String>
getBranchNames(ObjectDB mdl, boolean local, boolean remote)
Get branch names from an existing repositorystatic java.util.List<java.lang.String>
getBranchNames(java.io.File dir, boolean local, boolean remote)
Get branch names from an existing repositorystatic java.util.List<java.lang.String>
getBranchNames(org.eclipse.jgit.api.Git git, boolean local, boolean remote)
Get branch names from an existing repositorystatic java.lang.String
getCurrentBranchName(ObjectDB mdl)
Get current branch name from an existing repositorystatic java.lang.String
getCurrentBranchName(java.io.File dir)
Get current branch name from an existing repositorystatic org.json.JSONArray
getDiff(org.eclipse.jgit.lib.Repository rep, org.eclipse.jgit.revwalk.RevCommit oldCommit, org.eclipse.jgit.revwalk.RevCommit newCommit)
Get diff entries of 2 revisionsstatic org.json.JSONArray
getLastCommitDiff(org.eclipse.jgit.lib.Repository rep)
Get last commit's diff entriesstatic java.util.List<java.lang.String>
getLocalBranchNames(ObjectDB mdl)
Get local branch names from an existing repositorystatic java.util.List<java.lang.String>
getLocalBranchNames(java.io.File dir)
Get local branch names from an existing repositorystatic java.util.List<java.lang.String>
getLocalBranchNames(org.eclipse.jgit.api.Git git)
Get local branch names from an existing repositorystatic java.io.InputStream
getModuleZIP(ObjectDB mdl)
Get clean ZIP stream from a modulestatic java.io.InputStream
getModuleZIP(java.io.File dir)
Get clean ZIP stream from a checkout directorystatic java.io.InputStream
getModuleZIP(java.lang.String name)
Get clean ZIP stream from a module namestatic java.lang.String
getPrevCommitId(ObjectDB mdl, java.lang.String commitId)
Get previous module's commit ID for specified commit IDstatic java.lang.String
getPrevCommitId(org.eclipse.jgit.lib.Repository rep, java.lang.String commitId)
Get previous commit ID for specified commit IDstatic java.lang.String
getRawDiff(ObjectDB mdl, java.lang.String commitId)
Get raw diff for specified commit IDstatic java.lang.String
getRawDiff(org.eclipse.jgit.lib.Repository rep, java.lang.String commitId)
Get raw diff for specified commit IDstatic java.lang.String
getRawDiff(org.eclipse.jgit.lib.Repository rep, org.eclipse.jgit.revwalk.RevCommit oldCommit, org.eclipse.jgit.revwalk.RevCommit newCommit)
Get raw diff of 2 revisionsstatic java.util.List<java.lang.String>
getRemoteBranchNames(ObjectDB mdl)
Get remote branch names from an existing repositorystatic java.util.List<java.lang.String>
getRemoteBranchNames(java.io.File dir)
Get remote branch names from an existing repositorystatic java.util.List<java.lang.String>
getRemoteBranchNames(org.eclipse.jgit.api.Git git)
Get remote branch names from an existing repositorystatic java.util.List<java.lang.String>
getRemoteNames(ObjectDB mdl)
Get remote names from an existing repositorystatic java.util.List<java.lang.String>
getRemoteNames(java.io.File dir)
Get remote names from an existing repositorystatic java.util.List<java.lang.String>
getRemoteNames(org.eclipse.jgit.api.Git git)
Get remote names from an existing repositorystatic java.io.File
getRepositoryDir(ObjectDB mdl)
Get repository directory file for specified namestatic java.io.File
getRepositoryDir(java.lang.String name)
Get repository directory file for specified namestatic java.util.List<java.lang.String>
getTags(ObjectDB mdl, java.lang.String commitId)
Get all tags for a commit IDstatic java.util.List<java.lang.String>
getTags(java.io.File dir, java.lang.String commitId)
Get all tags for a commit IDstatic Message
importModule(Grant g, java.io.File dir, org.json.JSONArray diffs)
Import module from repository checkoutstatic Message
importModule(ObjectDB mdl)
Import module from repository checkoutstatic java.lang.String
lsremote(java.lang.String uri, java.lang.String username, java.lang.String password)
Get list of remote repository refsstatic boolean
merge(java.io.File dir, java.lang.String remote)
Mergestatic java.lang.String
projectPOM(ObjectDB mdl)
Generate a project-level POM file content for specified module and its child modulesstatic boolean
pull(java.io.File dir, java.lang.String username, java.lang.String password, java.lang.String remote)
Pull from remotestatic void
push(java.io.File dir, java.lang.String username, java.lang.String password, java.lang.String remote)
Push to remotestatic void
removeRemote(java.io.File dir, java.lang.String name)
Remove remotestatic boolean
repositoryExists(ObjectDB mdl)
Check whether a repository exists for specified namestatic boolean
repositoryExists(java.lang.String name)
Check whether a repository exists for specified namestatic void
tag(ObjectDB mdl, java.lang.String tag, java.lang.String commitId)
Tag module's commitstatic void
tag(java.io.File dir, java.lang.String tag, java.lang.String commitId)
Tag commit
-
-
-
Field Detail
-
ORIGIN
public static final java.lang.String ORIGIN
Origin- See Also:
- Constant Field Values
-
MASTER
public static final java.lang.String MASTER
Master branch name- See Also:
- Constant Field Values
-
HEAD
public static final java.lang.String HEAD
Head revision- See Also:
- Constant Field Values
-
POM_HEADER
public static final java.lang.String POM_HEADER
POM file header- See Also:
- Constant Field Values
-
POM_FOOTER
public static final java.lang.String POM_FOOTER
POM file footer- See Also:
- Constant Field Values
-
-
Method Detail
-
getRepositoryDir
public static java.io.File getRepositoryDir(java.lang.String name)
Get repository directory file for specified name- Parameters:
name
- Repository name- Returns:
- Repository directory file
-
getRepositoryDir
public static java.io.File getRepositoryDir(ObjectDB mdl)
Get repository directory file for specified name- Parameters:
mdl
- Module- Returns:
- Repository directory file
-
repositoryExists
public static boolean repositoryExists(java.lang.String name)
Check whether a repository exists for specified name- Parameters:
name
- Repository name- Returns:
- True if repository exists
-
repositoryExists
public static boolean repositoryExists(ObjectDB mdl)
Check whether a repository exists for specified name- Parameters:
mdl
- Module- Returns:
- True if repository exists
-
lsremote
public static java.lang.String lsremote(java.lang.String uri, java.lang.String username, java.lang.String password) throws GitException
Get list of remote repository refs- Parameters:
uri
- Repository URIusername
- Optional usernamepassword
- Optional password- Returns:
- List of remote repository refs
- Throws:
GitException
-
create
public static org.eclipse.jgit.api.Git create(java.io.File dir) throws GitException
Create a new repository- Parameters:
dir
- Directory- Returns:
- Git
- Throws:
GitException
-
clone
public static void clone(java.io.File dir, java.lang.String uri, java.lang.String username, java.lang.String password, java.lang.String remote, java.lang.String branch) throws GitException
Clone an existing repository- Parameters:
dir
- Directory to clone touri
- Repository URIusername
- Optional usernamepassword
- Optional passwordremote
- Optional remote (defaults to "origin")branch
- Optional branch (defaults to "master")- Throws:
GitException
-
delete
public static java.lang.String delete(ObjectDB mdl) throws GitException
Move the module's directory to the recylebin if it exists (or simply delete it if move is not sucessful)- Parameters:
mdl
-- Returns:
- Message telling wether the move/deletion was successful or not
- Throws:
GitException
-
getCurrentBranchName
public static java.lang.String getCurrentBranchName(java.io.File dir) throws GitException
Get current branch name from an existing repository- Parameters:
dir
- Directory- Returns:
- Current branch name
- Throws:
GitException
-
getCurrentBranchName
public static java.lang.String getCurrentBranchName(ObjectDB mdl) throws GitException
Get current branch name from an existing repository- Parameters:
mdl
- Module- Returns:
- Current branch name
- Throws:
GitException
-
getLocalBranchNames
public static java.util.List<java.lang.String> getLocalBranchNames(java.io.File dir) throws GitException
Get local branch names from an existing repository- Parameters:
dir
- Directory- Returns:
- List of branch names (
[branch name]
]) - Throws:
GitException
-
getRemoteBranchNames
public static java.util.List<java.lang.String> getRemoteBranchNames(java.io.File dir) throws GitException
Get remote branch names from an existing repository- Parameters:
dir
- Directory- Returns:
- List of remote branch names (
[remote name]/[branch name]
]) - Throws:
GitException
-
getBranchNames
public static java.util.List<java.lang.String> getBranchNames(java.io.File dir, boolean local, boolean remote) throws GitException
Get branch names from an existing repository- Parameters:
dir
- Directorylocal
- Local branches?remote
- Remote branches?- Returns:
- List of branch names (
[branch name]
for local branches,[remote name]/[branch name]
] for remote branches names) - Throws:
GitException
-
getLocalBranchNames
public static java.util.List<java.lang.String> getLocalBranchNames(org.eclipse.jgit.api.Git git) throws GitException
Get local branch names from an existing repository- Parameters:
git
- Git- Returns:
- List of branch names (
[branch name]
]) - Throws:
GitException
-
getRemoteBranchNames
public static java.util.List<java.lang.String> getRemoteBranchNames(org.eclipse.jgit.api.Git git) throws GitException
Get remote branch names from an existing repository- Parameters:
git
- Git- Returns:
- List of remote branch names (
[remote name]/[branch name]
]) - Throws:
GitException
-
getBranchNames
public static java.util.List<java.lang.String> getBranchNames(org.eclipse.jgit.api.Git git, boolean local, boolean remote) throws GitException
Get branch names from an existing repository- Parameters:
git
- Gitlocal
- Local branches?remote
- Remote branches?- Returns:
- List of branch names (
[branch name]
for local branches,[remote name]/[branch name]
] for remote branches names) - Throws:
GitException
-
getLocalBranchNames
public static java.util.List<java.lang.String> getLocalBranchNames(ObjectDB mdl) throws GitException
Get local branch names from an existing repository- Parameters:
mdl
- Module- Returns:
- List of branch names (
[branch name]
]) - Throws:
GitException
-
getRemoteBranchNames
public static java.util.List<java.lang.String> getRemoteBranchNames(ObjectDB mdl) throws GitException
Get remote branch names from an existing repository- Parameters:
mdl
- Module- Returns:
- List of remote branch names (
[remote name]/[branch name]
]) - Throws:
GitException
-
getBranchNames
public static java.util.List<java.lang.String> getBranchNames(ObjectDB mdl, boolean local, boolean remote) throws GitException
Get branch names from an existing repository- Parameters:
mdl
- Modulelocal
- Local branches?remote
- Remote branches?- Returns:
- List of branch names (
[branch name]
for local branches,[remote name]/[branch name]
] for remote branches names) - Throws:
GitException
-
getRemoteNames
public static java.util.List<java.lang.String> getRemoteNames(java.io.File dir) throws GitException
Get remote names from an existing repository- Parameters:
dir
- Directory- Returns:
- List of remote names
- Throws:
GitException
-
getRemoteNames
public static java.util.List<java.lang.String> getRemoteNames(ObjectDB mdl) throws GitException
Get remote names from an existing repository- Parameters:
mdl
- Module- Returns:
- List of remote names
- Throws:
GitException
-
getRemoteNames
public static java.util.List<java.lang.String> getRemoteNames(org.eclipse.jgit.api.Git git) throws GitException
Get remote names from an existing repository- Parameters:
git
- Git- Returns:
- RLis of remote names
- Throws:
GitException
-
addRemote
public static void addRemote(java.io.File dir, java.lang.String name, java.lang.String uri) throws GitException
Add remote- Parameters:
dir
- Directoryname
- Remote nameuri
- URI- Throws:
GitException
-
removeRemote
public static void removeRemote(java.io.File dir, java.lang.String name) throws GitException
Remove remote- Parameters:
dir
- Directoryname
- Remote name- Throws:
GitException
-
pull
public static boolean pull(java.io.File dir, java.lang.String username, java.lang.String password, java.lang.String remote) throws GitException
Pull from remote- Parameters:
dir
- Directoryusername
- Optional usernamepassword
- Optional passwordremote
- Remote name (defaults to "origin")- Returns:
- True if pull is successful
- Throws:
GitException
-
fetch
public static void fetch(java.io.File dir, java.lang.String username, java.lang.String password, java.lang.String remote) throws GitException
Fetch from remote- Parameters:
dir
- Directoryusername
- Optional usernamepassword
- Optional passwordremote
- Remote name (defaults to "origin")- Throws:
GitException
-
merge
public static boolean merge(java.io.File dir, java.lang.String remote) throws GitException
Merge- Parameters:
dir
- Directory- Returns:
- True if merge is sucessful
- Throws:
GitException
-
push
public static void push(java.io.File dir, java.lang.String username, java.lang.String password, java.lang.String remote) throws GitException
Push to remote- Parameters:
dir
- Directoryusername
- Optional usernamepassword
- Optional passwordremote
- Remote name (defaults to "origin")- Throws:
GitException
-
checkout
public static void checkout(ObjectDB mdl, java.lang.String commitId) throws GitException
Checkout commit ID in module's repository worktree- Parameters:
mdl
- ModulecommitId
- Commit ID (defaults to "HEAD")- Throws:
GitException
-
checkout
public static void checkout(java.io.File dir, java.lang.String commitId) throws GitException
Checkout a commit ID in the repository worktree.- Parameters:
dir
- DirectorycommitId
- Commit ID (defaults to "HEAD")- Throws:
GitException
-
checkout
public static void checkout(ObjectDB mdl, java.lang.String branch, boolean create, java.lang.String remoteBranch) throws GitException
Checkout a branch in module's repository worktree- Parameters:
mdl
- Modulebranch
- Local branch name (defaults to "master")create
- Create branch?remoteBranch
- Name of a remote branch <remote name, e.g. origin>/<remote branch name> to track- Throws:
GitException
-
checkout
public static void checkout(java.io.File dir, java.lang.String branch, boolean create, java.lang.String remoteBranch) throws GitException
Checkout a branch in the repository worktree.- Parameters:
dir
- Directorybranch
- Local branch name (defaults to "master")create
- Create branch?remoteBranch
- Name of a remote branch <remote name, e.g. origin>/<remote branch name> to track- Throws:
GitException
-
tag
public static void tag(ObjectDB mdl, java.lang.String tag, java.lang.String commitId) throws GitException
Tag module's commit- Parameters:
mdl
- Moduletag
- TagcommitId
- Commit ID (null means last commit)- Throws:
GitException
-
tag
public static void tag(java.io.File dir, java.lang.String tag, java.lang.String commitId) throws GitException
Tag commit- Parameters:
dir
- Directorytag
- TagcommitId
- Commit ID (null means last commit)- Throws:
GitException
-
getTags
public static java.util.List<java.lang.String> getTags(ObjectDB mdl, java.lang.String commitId) throws GitException
Get all tags for a commit ID- Parameters:
mdl
- ModulecommitId
- Commit ID (null means last commit)- Returns:
- List of tags
- Throws:
GitException
-
getTags
public static java.util.List<java.lang.String> getTags(java.io.File dir, java.lang.String commitId) throws GitException
Get all tags for a commit ID- Parameters:
dir
- DirectorycommitId
- Commit ID (null means last commit)- Returns:
- List of tags
- Throws:
GitException
-
getPrevCommitId
public static java.lang.String getPrevCommitId(org.eclipse.jgit.lib.Repository rep, java.lang.String commitId) throws GitException
Get previous commit ID for specified commit ID- Parameters:
rep
- RepositorycommitId
- Commit ID- Returns:
- Previous commit ID
- Throws:
GitException
-
getPrevCommitId
public static java.lang.String getPrevCommitId(ObjectDB mdl, java.lang.String commitId) throws GitException
Get previous module's commit ID for specified commit ID- Parameters:
mdl
- ModulecommitId
- Commit ID- Returns:
- Previous module's commit ID
- Throws:
GitException
-
getDiff
public static org.json.JSONArray getDiff(org.eclipse.jgit.lib.Repository rep, org.eclipse.jgit.revwalk.RevCommit oldCommit, org.eclipse.jgit.revwalk.RevCommit newCommit) throws GitException
Get diff entries of 2 revisions- Parameters:
rep
- RepositoryoldCommit
- Old commitnewCommit
- New commit- Returns:
- Diff entries as JSON array
- Throws:
GitException
-
getRawDiff
public static java.lang.String getRawDiff(org.eclipse.jgit.lib.Repository rep, org.eclipse.jgit.revwalk.RevCommit oldCommit, org.eclipse.jgit.revwalk.RevCommit newCommit) throws GitException
Get raw diff of 2 revisions- Parameters:
rep
- RepositoryoldCommit
- Old commitnewCommit
- New commit- Returns:
- Raw diff
- Throws:
GitException
-
getRawDiff
public static java.lang.String getRawDiff(org.eclipse.jgit.lib.Repository rep, java.lang.String commitId) throws GitException
Get raw diff for specified commit ID- Parameters:
rep
- RepositorycommitId
- Commit ID- Returns:
- Raw diff
- Throws:
GitException
-
getRawDiff
public static java.lang.String getRawDiff(ObjectDB mdl, java.lang.String commitId) throws GitException
Get raw diff for specified commit ID- Parameters:
mdl
- ModulecommitId
- Commit ID- Returns:
- Raw diff
- Throws:
GitException
-
getLastCommitDiff
public static org.json.JSONArray getLastCommitDiff(org.eclipse.jgit.lib.Repository rep) throws GitException
Get last commit's diff entries- Parameters:
rep
- Repository- Returns:
- Last commit's diff entries as JSON array
- Throws:
GitException
-
getAllCommits
public static org.json.JSONArray getAllCommits(org.eclipse.jgit.lib.Repository rep, int n) throws GitException
Get last commits information- Parameters:
rep
- Repositoryn
- Depth- Returns:
- Last commits information as JSON array
- Throws:
GitException
-
getAllModuleCommits
public static org.json.JSONArray getAllModuleCommits(ObjectDB mdl, int n) throws GitException
Get modules's last commits information for module- Parameters:
mdl
- Modulen
- Depth- Returns:
- Modules's last commits information as JSON array
- Throws:
GitException
-
dumpCommit
public static java.lang.String dumpCommit(org.eclipse.jgit.lib.Repository rep, org.eclipse.jgit.lib.ObjectId commitId) throws GitException
Dump commit information- Parameters:
rep
- RepositorycommitId
- Commit ID (null means last commit)- Returns:
- Commit information as string
- Throws:
GitException
-
dumpModuleCommit
public static java.lang.String dumpModuleCommit(ObjectDB mdl, org.eclipse.jgit.lib.ObjectId commitId) throws GitException
Dump module's commit for specified row ID- Parameters:
mdl
- ModulecommitId
- Commit ID (null means last commit)- Returns:
- Commit dump
- Throws:
GitException
-
projectPOM
public static java.lang.String projectPOM(ObjectDB mdl) throws PlatformException
Generate a project-level POM file content for specified module and its child modules- Parameters:
mdl
- Module object- Returns:
- POM file content
- Throws:
PlatformException
-
commitModule
@Deprecated public static java.lang.String commitModule(ObjectDB mdl, java.lang.String msg) throws PlatformException
Deprecated.Use commitModule with addtional format parameter- Throws:
PlatformException
-
commitModule
public static java.lang.String commitModule(ObjectDB mdl, java.lang.String format, java.lang.String msg) throws PlatformException
Commit selected module- Parameters:
mdl
- Module objectformat
- Format (one of Integration_FORMAT_*)msg
- Message- Returns:
- Commit ID
- Throws:
PlatformException
-
getModuleZIP
public static java.io.InputStream getModuleZIP(ObjectDB mdl) throws GitException
Get clean ZIP stream from a module- Parameters:
mdl
- Module- Returns:
- ZIP stream
- Throws:
GitException
-
getModuleZIP
public static java.io.InputStream getModuleZIP(java.lang.String name) throws GitException
Get clean ZIP stream from a module name- Parameters:
name
- Module name- Returns:
- ZIP stream
- Throws:
GitException
-
getModuleZIP
public static java.io.InputStream getModuleZIP(java.io.File dir) throws GitException
Get clean ZIP stream from a checkout directory- Parameters:
dir
- Checkout directory- Returns:
- ZIP stream
- Throws:
GitException
-
importModule
public static Message importModule(ObjectDB mdl) throws PlatformException
Import module from repository checkout- Parameters:
mdl
- Module- Returns:
- Message
- Throws:
PlatformException
-
importModule
public static Message importModule(Grant g, java.io.File dir, org.json.JSONArray diffs) throws PlatformException
Import module from repository checkout- Parameters:
g
- Grantdir
- Repository directory- Returns:
- Message
- Throws:
PlatformException
-
-