Class 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.FileBasedWorkflowRepositoryMXBean
    Extension of FileBasedWorkflowRepository, that adds an observer of a git repository. The setBranch(String) branch in setOriginURI(String) is pulled for changes. The changes are applyed online. The interval setCheckIntervalMSec(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 class  GitWorkflowRepository.GitWorkflowRepositoryException
      Used for runtime exception in this class.
      • Nested classes/interfaces inherited from class org.copperengine.core.wfrepo.AbstractWorkflowRepository

        org.copperengine.core.wfrepo.AbstractWorkflowRepository.VolatileState
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_BRANCH
      Default name "master".
      static java.lang.String ORIGIN
      Used as remote name: "origin".
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void deleteGitRepositoryDir()
      Deletes the whole tree in getGitRepositoryDir().
      java.io.File getGitRepositoryDir()  
      java.lang.String getOriginUri()  
      boolean isUp()  
      void setBranch​(java.lang.String branch)
      Changes the used branch and refreshes the the local repository clone.
      void setCheckIntervalMSec​(int checkIntervalMSec)
      Defines the poll interval for changes in a branch.
      void setCredentials​(java.lang.String username, char[] password)
      Sets the credentials used in next clone
      void setGitRepositoryDir​(java.io.File gitRepositoryDir)
      Define the directory, where the local git clone is created expected to exists.
      void setGitRepositoryDir​(java.lang.String gitRepositoryDir)
      void setOriginURI​(java.lang.String originUri)
      The current originUri is changed
      void shutdown()
      Shuts down the repository poll activities on git repository and files.
      void start()
      Starts the repository poll activities and refreshes the the local repository clone.
      protected void updateLocalGitRepositories()
      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
      • Methods inherited from interface org.copperengine.core.common.WorkflowRepository

        createWorkflowFactory, createWorkflowFactory, findLatestMajorVersion, findLatestMinorVersion, getClassInfo, resolveClass
      • Methods inherited from interface org.copperengine.management.WorkflowRepositoryMXBean

        getDescription, getWorkflowInfo, getWorkflowRepoSize, getWorkflows, queryWorkflowsSubset
    • Constructor Detail

      • GitWorkflowRepository

        public GitWorkflowRepository()
    • Method Detail

      • setGitRepositoryDir

        public void setGitRepositoryDir​(java.io.File gitRepositoryDir)
                                 throws java.io.IOException,
                                        org.eclipse.jgit.api.errors.GitAPIException
        Define 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 refresh
        java.io.IOException - on exception on directory deletion
      • 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
      • setOriginURI

        public void setOriginURI​(java.lang.String originUri)
                          throws java.io.IOException,
                                 org.eclipse.jgit.api.errors.GitAPIException
        The current originUri is changed. * If the GitWorkflowRepository isUp() isUp the a refesh incl. directory deletion is performed.
        Parameters:
        originUri - new origin URI
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException - on exception in refresh
        java.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 - selfexplaining
        password - selfexplaining
      • setBranch

        public void setBranch​(java.lang.String branch)
                       throws java.io.IOException,
                              org.eclipse.jgit.api.errors.GitAPIException
        Changes the used branch and refreshes the the local repository clone.
        Parameters:
        branch - new branch
        Throws:
        org.eclipse.jgit.api.errors.GitAPIException - on exception in refresh
        java.io.IOException - on exception in refresh
      • setCheckIntervalMSec

        public void setCheckIntervalMSec​(int checkIntervalMSec)
        Defines the poll interval for changes in a branch.
        Overrides:
        setCheckIntervalMSec in class org.copperengine.core.wfrepo.FileBasedWorkflowRepository
        Parameters:
        checkIntervalMSec - also given to FileBasedWorkflowRepository as the underlying file pol
      • start

        public void start()
        Starts the repository poll activities and refreshes the the local repository clone.
        Specified by:
        start in interface org.copperengine.core.common.WorkflowRepository
        Overrides:
        start in class org.copperengine.core.wfrepo.FileBasedWorkflowRepository
        Throws:
        java.lang.IllegalStateException - if another start already was executed
        GitWorkflowRepository.GitWorkflowRepositoryException - on exception in refresh
      • shutdown

        public void shutdown()
        Shuts down the repository poll activities on git repository and files.
        Specified by:
        shutdown in interface org.copperengine.core.common.WorkflowRepository
        Overrides:
        shutdown in class org.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.GitAPIException
        Updates 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 exception
        org.eclipse.jgit.api.errors.GitAPIException - in case of exception in git calls
      • deleteGitRepositoryDir

        protected void deleteGitRepositoryDir()
                                       throws java.io.IOException
        Deletes the whole tree in getGitRepositoryDir().
        Throws:
        java.io.IOException - if exception in deleting is thrown.