Package org.copperengine.ext.wfrepo.git
Class GitWorkflowRepository
- java.lang.Object
-
- org.copperengine.core.wfrepo.AbstractWorkflowRepository
-
- org.copperengine.core.wfrepo.FileBasedWorkflowRepository
-
- org.copperengine.ext.wfrepo.git.GitWorkflowRepository
-
- All Implemented Interfaces:
org.copperengine.core.common.WorkflowRepository,org.copperengine.management.FileBasedWorkflowRepositoryMXBean,org.copperengine.management.WorkflowRepositoryMXBean
public class GitWorkflowRepository extends org.copperengine.core.wfrepo.FileBasedWorkflowRepository implements org.copperengine.core.common.WorkflowRepository, org.copperengine.management.FileBasedWorkflowRepositoryMXBeanExtension ofFileBasedWorkflowRepository, that adds an observer of a git repository. ThesetBranch(String)branch insetOriginURI(String)is pulled for changes. The changes are applyed online. The intervalsetCheckIntervalMSec(int)is also used in the FileBasedWorkflowRepository. This class enables a lightweight CI/CD pipeline using git repositories only for changes in workflows. Changes outside the workflows are not in scope of this pipeline.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGitWorkflowRepository.GitWorkflowRepositoryExceptionUsed for runtime exception in this class.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_BRANCHDefault name "master".static java.lang.StringORIGINUsed as remote name: "origin".
-
Constructor Summary
Constructors Constructor Description GitWorkflowRepository()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddeleteGitRepositoryDir()Deletes the whole tree ingetGitRepositoryDir().java.lang.StringgetBranch()java.io.FilegetGitRepositoryDir()java.lang.StringgetOriginUri()booleanisUp()voidsetBranch(java.lang.String branch)Changes the used branch and refreshes the the local repository clone.voidsetCheckIntervalMSec(int checkIntervalMSec)Defines the poll interval for changes in a branch.voidsetCredentials(java.lang.String username, char[] password)Sets the credentials used in next clonevoidsetGitRepositoryDir(java.io.File gitRepositoryDir)Define the directory, where the local git clone is created expected to exists.voidsetGitRepositoryDir(java.lang.String gitRepositoryDir)Delegates tosetGitRepositoryDir(java.io.File).voidsetOriginURI(java.lang.String originUri)The current originUri is changed.voidshutdown()Shuts down the repository poll activities on git repository and files.voidstart()Starts the repository poll activities and refreshes the the local repository clone.protected voidupdateLocalGitRepositories()Updates the used local repository, either with gut-pull or with git-checkout force with git pull.-
Methods inherited from class org.copperengine.core.wfrepo.FileBasedWorkflowRepository
addCompilerOptionsProvider, addSourceArchiveUrl, addSourceDir, getClassLoader, getCompilerOptionsProviders, getDescription, getLastBuildResults, getSourceArchiveUrls, getSourceDirs, getTargetDir, getVolatileState, setCompilerOptions, setCompilerOptionsProviders, setLoadNonWorkflowClasses, setPreprocessors, setSourceArchiveUrls, setSourceDirs, setSourceDirs, setTargetDir
-
Methods inherited from class org.copperengine.core.wfrepo.AbstractWorkflowRepository
checkConstraints, createAliasName, createClassLoader, createWorkflowClassInfoMap, createWorkflowFactory, createWorkflowFactory, findLatestMajorVersion, findLatestMinorVersion, getClassInfo, getWorkflowInfo, getWorkflowRepoSize, getWorkflows, instrumentWorkflows, queryWorkflowsSubset, resolveClass
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.copperengine.management.FileBasedWorkflowRepositoryMXBean
getLastBuildResults, getSourceArchiveUrls, getSourceDirs
-
-
-
-
Field Detail
-
ORIGIN
public static final java.lang.String ORIGIN
Used as remote name: "origin". Not changed.- See Also:
- Constant Field Values
-
DEFAULT_BRANCH
public static final java.lang.String DEFAULT_BRANCH
Default name "master". Changeable withsetBranch(String)- See Also:
- Constant Field Values
-
-
Method Detail
-
setGitRepositoryDir
public void setGitRepositoryDir(java.io.File gitRepositoryDir) throws java.io.IOException, org.eclipse.jgit.api.errors.GitAPIExceptionDefine the directory, where the local git clone is created expected to exists.If the GitWorkflowRepository
isUp()isUp the a refesh incl. directory deletion is performed.- Parameters:
gitRepositoryDir- the new or same location of local git clone- Throws:
org.eclipse.jgit.api.errors.GitAPIException- on exception in refreshjava.io.IOException- on exception on directory deletion
-
setGitRepositoryDir
public void setGitRepositoryDir(java.lang.String gitRepositoryDir) throws java.io.IOException, org.eclipse.jgit.api.errors.GitAPIExceptionDelegates tosetGitRepositoryDir(java.io.File).- Parameters:
gitRepositoryDir- seesetGitRepositoryDir(java.io.File).- Throws:
java.io.IOException- seesetGitRepositoryDir(java.io.File).org.eclipse.jgit.api.errors.GitAPIException- seesetGitRepositoryDir(java.io.File).
-
getGitRepositoryDir
public java.io.File getGitRepositoryDir()
- Returns:
- a new file object for the current directory of the local repository clone
-
getOriginUri
public java.lang.String getOriginUri()
- Returns:
- the current originURI
-
getBranch
public java.lang.String getBranch()
- Returns:
- the current branch
-
setOriginURI
public void setOriginURI(java.lang.String originUri) throws java.io.IOException, org.eclipse.jgit.api.errors.GitAPIExceptionThe current originUri is changed. * If the GitWorkflowRepositoryisUp()isUp the a refesh incl. directory deletion is performed.- Parameters:
originUri- new origin URI- Throws:
org.eclipse.jgit.api.errors.GitAPIException- on exception in refreshjava.io.IOException- on exception on directory deletion
-
setCredentials
public void setCredentials(java.lang.String username, char[] password)Sets the credentials used in next clone- Parameters:
username- selfexplainingpassword- selfexplaining
-
setBranch
public void setBranch(java.lang.String branch) throws java.io.IOException, org.eclipse.jgit.api.errors.GitAPIExceptionChanges the used branch and refreshes the the local repository clone.- Parameters:
branch- new branch- Throws:
org.eclipse.jgit.api.errors.GitAPIException- on exception in refreshjava.io.IOException- on exception in refresh
-
setCheckIntervalMSec
public void setCheckIntervalMSec(int checkIntervalMSec)
Defines the poll interval for changes in a branch.- Overrides:
setCheckIntervalMSecin classorg.copperengine.core.wfrepo.FileBasedWorkflowRepository- Parameters:
checkIntervalMSec- also given toFileBasedWorkflowRepositoryas the underlying file pol
-
start
public void start()
Starts the repository poll activities and refreshes the the local repository clone.- Specified by:
startin interfaceorg.copperengine.core.common.WorkflowRepository- Overrides:
startin classorg.copperengine.core.wfrepo.FileBasedWorkflowRepository- Throws:
java.lang.IllegalStateException- if another start already was executedGitWorkflowRepository.GitWorkflowRepositoryException- on exception in refresh
-
shutdown
public void shutdown()
Shuts down the repository poll activities on git repository and files.- Specified by:
shutdownin interfaceorg.copperengine.core.common.WorkflowRepository- Overrides:
shutdownin classorg.copperengine.core.wfrepo.FileBasedWorkflowRepository
-
isUp
public boolean isUp()
- Returns:
- true, if repository start was sucessful and no shutdown was requested.
-
updateLocalGitRepositories
protected void updateLocalGitRepositories() throws java.io.IOException, org.eclipse.jgit.api.errors.GitAPIExceptionUpdates the used local repository, either with gut-pull or with git-checkout force with git pull.- Throws:
java.io.IOException- in case of git open exceptionorg.eclipse.jgit.api.errors.GitAPIException- in case of exception in git calls
-
deleteGitRepositoryDir
protected void deleteGitRepositoryDir() throws java.io.IOExceptionDeletes the whole tree ingetGitRepositoryDir().- Throws:
java.io.IOException- if exception in deleting is thrown.
-
-