Class GitRepositoryHelper
java.lang.Object
org.craftercms.studio.api.v2.utils.GitRepositoryHelper
- All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean
public class GitRepositoryHelper
extends Object
implements org.springframework.beans.factory.DisposableBean
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addGitIgnoreFiles
(String siteId) boolean
Build the global repository as part of system startup and caches itbuildRepoPath
(GitRepositories repoType) Builds repository pathbuildRepoPath
(GitRepositories repoType, String siteId) Builds repository pathboolean
buildSiteRepo
(String siteId) void
checkoutBranch
(org.eclipse.jgit.lib.Repository repository, String sourceBranch, String targetBranch, boolean create) Checkout a branch, optionally creating it if it doesn't existcommitFiles
(org.eclipse.jgit.lib.Repository repo, String site, String comment, org.eclipse.jgit.lib.PersonIdent user, String... paths) Commit files to a site SANDBOX git repository (or GLOBAL if site is empty)boolean
copyContentFromBlueprint
(String blueprintLocation, String site) org.eclipse.jgit.lib.Repository
createGitRepository
(Path path) boolean
boolean
createPublishedRepository
(String siteId, String sandboxBranch) Create a site published git repository from scratchboolean
createSandboxRepository
(String site, String sandboxBranch) Create a site sandbox git repository from scratchboolean
createSiteCloneRemoteGitRepo
(String siteId, String sandboxBranch, String remoteName, String remoteUrl, String remoteBranch, boolean singleBranch, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey, boolean createAsOrphan, String creator) boolean
deleteSiteGitRepo
(String site) void
destroy()
org.eclipse.jgit.lib.PersonIdent
getAuthorIdent
(String author) Return the author identity as a jgit PersonIdentorg.eclipse.jgit.lib.PersonIdent
getAuthorIdent
(User user) Return the author identity as a jgit PersonIdentgetCommitMessage
(String commitMessageKey) org.eclipse.jgit.lib.PersonIdent
Return the current user identity as a jgit PersonIdentorg.eclipse.jgit.diff.DiffEntry
getDiffEntry
(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.lib.ObjectId commitId, String gitPath) Get the diff entry for a given commit and path.getFilesInCommit
(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit commit) getGitPath
(String path) String[]
getGitPaths
(String... paths) Returns the key to use when locking Git operations for a site's published repoprotected String
getRepoCacheKey
(String siteId, GitRepositories type) org.eclipse.jgit.lib.Repository
getRepository
(String siteId, GitRepositories gitRepository) org.eclipse.jgit.lib.Repository
getRepository
(String siteId, GitRepositories repoType, String sandboxBranch) getSandboxRepoLockKey
(String site) Returns the key to use when locking Git operations for a site's sandbox repogetSandboxRepoLockKey
(String site, boolean ifSiteEmptyUseGlobalRepoLockKey) Returns the key to use when locking Git operations for a site's sandbox or global repoorg.eclipse.jgit.revwalk.RevTree
getTreeForCommit
(org.eclipse.jgit.lib.Repository repository, String commitId) org.eclipse.jgit.revwalk.RevTree
getTreeForCommit
(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.lib.ObjectId commitId) org.eclipse.jgit.revwalk.RevTree
getTreeForLastCommit
(org.eclipse.jgit.lib.Repository repository) boolean
isRemoteValid
(org.eclipse.jgit.api.Git git, String remote, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey) org.eclipse.jgit.lib.Repository
openRepository
(Path repositoryPath) Opens a git repositoryboolean
performInitialCommit
(String site, String message, String sandboxBranch, String creator) Perform an initial commit after large changes to a site.boolean
replaceParameters
(String siteId, Map<String, String> parameters) protected boolean
replaceSiteNameVariable
(String site, Path path) void
setAuthConfiguratorFactory
(org.craftercms.commons.git.utils.AuthConfiguratorFactory authConfiguratorFactory) void
setAuthenticationForCommand
(org.eclipse.jgit.api.TransportCommand<?, ?> gitCommand, String authenticationType, String username, String password, String token, String privateKey, Path tempKey, boolean decrypt) void
setEncryptor
(org.craftercms.commons.crypto.TextEncryptor encryptor) void
setGeneralLockService
(GeneralLockService generalLockService) void
void
setGitCliEnabled
(boolean gitCliEnabled) void
setRetryingRepositoryOperationFacade
(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade) void
setSecurityService
(SecurityService securityService) void
setStudioConfiguration
(StudioConfiguration studioConfiguration) void
setUserServiceInternal
(UserServiceInternal userServiceInternal) boolean
boolean
writeFile
(org.eclipse.jgit.lib.Repository repo, String site, String path, InputStream content)
-
Field Details
-
CONFIG_KEY_RESOURCE
- See Also:
-
CONFIG_KEY_FOLDER
- See Also:
-
-
Constructor Details
-
GitRepositoryHelper
public GitRepositoryHelper()
-
-
Method Details
-
destroy
- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- Throws:
Exception
-
getRepoCacheKey
-
getRepository
-
getRepository
public org.eclipse.jgit.lib.Repository getRepository(String siteId, GitRepositories repoType, String sandboxBranch) -
buildSiteRepo
-
buildRepoPath
Builds repository path- Parameters:
repoType
- repository type- Returns:
- repository path
-
buildRepoPath
Builds repository path- Parameters:
repoType
- repository typesiteId
- site Id (if empty it is global repository)- Returns:
- repository path
-
openRepository
Opens a git repository- Parameters:
repositoryPath
- path to repository to open (including .git)- Returns:
- repository object if successful
- Throws:
IOException
- IO error
-
isRemoteValid
public boolean isRemoteValid(org.eclipse.jgit.api.Git git, String remote, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey) throws org.craftercms.commons.crypto.CryptoException, IOException, ServiceLayerException, org.eclipse.jgit.api.errors.GitAPIException - Throws:
org.craftercms.commons.crypto.CryptoException
IOException
ServiceLayerException
org.eclipse.jgit.api.errors.GitAPIException
-
setAuthenticationForCommand
public void setAuthenticationForCommand(org.eclipse.jgit.api.TransportCommand<?, ?> gitCommand, String authenticationType, String username, String password, String token, String privateKey, Path tempKey, boolean decrypt) throws org.craftercms.commons.crypto.CryptoException, ServiceLayerException, IOException- Throws:
org.craftercms.commons.crypto.CryptoException
ServiceLayerException
IOException
-
getGitPath
-
getGitPaths
-
getAuthorIdent
Return the author identity as a jgit PersonIdent- Parameters:
user
- author- Returns:
- author user as a PersonIdent
-
getTreeForCommit
public org.eclipse.jgit.revwalk.RevTree getTreeForCommit(org.eclipse.jgit.lib.Repository repository, String commitId) throws IOException - Throws:
IOException
-
getTreeForCommit
public org.eclipse.jgit.revwalk.RevTree getTreeForCommit(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.lib.ObjectId commitId) throws IOException - Throws:
IOException
-
getTreeForLastCommit
public org.eclipse.jgit.revwalk.RevTree getTreeForLastCommit(org.eclipse.jgit.lib.Repository repository) throws IOException - Throws:
IOException
-
getDiffEntry
public org.eclipse.jgit.diff.DiffEntry getDiffEntry(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.lib.ObjectId commitId, String gitPath) throws NoChangesForPathException, IOException, org.eclipse.jgit.api.errors.GitAPIException Get the diff entry for a given commit and path. The result value corresponds to the diff found for the given path between the given commit and its (first) parent (or empty tree for initial commits).- Parameters:
repository
- the repositorycommitId
- the commit IDgitPath
- the git path of the content item- Returns:
- the diff entry
- Throws:
NoChangesForPathException
IOException
org.eclipse.jgit.api.errors.GitAPIException
-
getFilesInCommit
-
createSandboxRepository
Create a site sandbox git repository from scratch- Parameters:
site
- site to createsandboxBranch
- sandbox branch name- Returns:
- true if successful, false otherwise
-
createPublishedRepository
Create a site published git repository from scratch- Parameters:
siteId
- site to createsandboxBranch
- sandbox branch name- Returns:
- true if successful, false otherwise
-
createGitRepository
-
getCommitMessage
-
copyContentFromBlueprint
-
updateSiteNameConfigVar
-
replaceSiteNameVariable
-
replaceParameters
-
addGitIgnoreFiles
-
performInitialCommit
public boolean performInitialCommit(String site, String message, String sandboxBranch, String creator) Perform an initial commit after large changes to a site. Will not work against the global config repo.- Parameters:
site
- site identifiermessage
- commit messagesandboxBranch
- sandbox branch namecreator
- site creator- Returns:
- true if successful, false otherwise
-
createSiteCloneRemoteGitRepo
public boolean createSiteCloneRemoteGitRepo(String siteId, String sandboxBranch, String remoteName, String remoteUrl, String remoteBranch, boolean singleBranch, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey, boolean createAsOrphan, String creator) throws InvalidRemoteRepositoryException, InvalidRemoteRepositoryCredentialsException, RemoteRepositoryNotFoundException, ServiceLayerException -
buildGlobalRepo
Build the global repository as part of system startup and caches it- Returns:
- true if successful, false otherwise
- Throws:
IOException
- IO error
-
createGlobalRepo
public boolean createGlobalRepo() -
deleteSiteGitRepo
-
writeFile
public boolean writeFile(org.eclipse.jgit.lib.Repository repo, String site, String path, InputStream content) -
addFiles
-
commitFiles
public String commitFiles(org.eclipse.jgit.lib.Repository repo, String site, String comment, org.eclipse.jgit.lib.PersonIdent user, String... paths) Commit files to a site SANDBOX git repository (or GLOBAL if site is empty)- Parameters:
repo
- the repositorysite
- the sitecomment
- the commit messageuser
- author of the commitpaths
- the paths to commit- Returns:
- commit id
-
getCurrentUserIdent
public org.eclipse.jgit.lib.PersonIdent getCurrentUserIdent() throws ServiceLayerException, UserNotFoundExceptionReturn the current user identity as a jgit PersonIdent- Returns:
- current user as a PersonIdent
- Throws:
ServiceLayerException
- general service errorUserNotFoundException
- user not found
-
getAuthorIdent
public org.eclipse.jgit.lib.PersonIdent getAuthorIdent(String author) throws ServiceLayerException, UserNotFoundException Return the author identity as a jgit PersonIdent- Parameters:
author
- author- Returns:
- author user as a PersonIdent
- Throws:
ServiceLayerException
- general service errorUserNotFoundException
- user not found error
-
getSandboxRepoLockKey
Returns the key to use when locking Git operations for a site's sandbox repo- Parameters:
site
- the site name- Returns:
- the lock key to use with the lock service
-
getSandboxRepoLockKey
Returns the key to use when locking Git operations for a site's sandbox or global repo- Parameters:
site
- the site nameifSiteEmptyUseGlobalRepoLockKey
- `true` to use global repo lock key if site empty- Returns:
- the lock key to use with the lock service
-
getPublishedRepoLockKey
Returns the key to use when locking Git operations for a site's published repo- Parameters:
site
- the site name- Returns:
- the lock key to use with the lock service
-
getStudioConfiguration
-
setStudioConfiguration
-
setEncryptor
public void setEncryptor(org.craftercms.commons.crypto.TextEncryptor encryptor) -
getSecurityService
-
setSecurityService
-
getUserServiceInternal
-
setUserServiceInternal
-
getGeneralLockService
-
setGeneralLockService
-
getRetryingRepositoryOperationFacade
-
setRetryingRepositoryOperationFacade
public void setRetryingRepositoryOperationFacade(RetryingRepositoryOperationFacade retryingRepositoryOperationFacade) -
setAuthConfiguratorFactory
public void setAuthConfiguratorFactory(org.craftercms.commons.git.utils.AuthConfiguratorFactory authConfiguratorFactory) -
setGitCli
-
setGitCliEnabled
public void setGitCliEnabled(boolean gitCliEnabled) -
checkoutBranch
public void checkoutBranch(org.eclipse.jgit.lib.Repository repository, String sourceBranch, String targetBranch, boolean create) throws org.eclipse.jgit.api.errors.GitAPIException Checkout a branch, optionally creating it if it doesn't exist- Parameters:
repository
- the repositorysourceBranch
- starting point of the branch to checkouttargetBranch
- the branch to checkoutcreate
- if the branch should be created if it doesn't exist- Throws:
org.eclipse.jgit.api.errors.GitAPIException
- if an error occurs
-