Class GitSession

  • All Implemented Interfaces:
    adams.core.CleanUpHandler, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.SizeOfHandler, Serializable

    public class GitSession
    extends adams.core.logging.CustomLoggingLevelObject
    implements adams.core.CleanUpHandler
    Manages the repositories during a session.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Map<File,​Object> m_Controlled
      the file repo/false relation.
      protected Map<org.eclipse.jgit.transport.URIish,​char[]> m_Passwords
      for keeping track of passwords per ssh key.
      protected Map<File,​org.eclipse.jgit.api.Git> m_Repos
      the git repos.
      protected static GitSession m_Singleton
      the singleton.
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected GitSession()
      Initializes the session object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addRepo​(org.eclipse.jgit.api.Git git)
      Adds the git repo.
      void cleanUp()
      Cleans up data structures, frees up memory.
      char[] getPassword​(org.eclipse.jgit.transport.URIish uri)
      Returns the password for the ssh key.
      char[] getPasswordOrPrompt​(org.eclipse.jgit.transport.URIish uri)
      Returns the password for the ssh key and prompts the user if not yet stored.
      static GitSession getSingleton()
      Returns the session singleton.
      org.eclipse.jgit.transport.sshd.SshdSessionFactory getSshdSessionFactory()
      Returns a sshd session factory that will prompt the user for a password for each ssh key in use.
      boolean isWithinRepo​(File path)
      Checks whether the dir/file is inside a git-managed directory sub-tree.
      org.eclipse.jgit.api.Git repoFor​(File path)
      Returns the repo for the specified dir/file.
      Collection<org.eclipse.jgit.api.Git> repos()
      Returns the currently managed repos.
      void setPassword​(org.eclipse.jgit.transport.URIish uri, char[] password)
      Sets the password for the ssh key.
      • Methods inherited from class adams.core.logging.CustomLoggingLevelObject

        setLoggingLevel
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel
    • Field Detail

      • m_Repos

        protected Map<File,​org.eclipse.jgit.api.Git> m_Repos
        the git repos.
      • m_Controlled

        protected Map<File,​Object> m_Controlled
        the file repo/false relation.
      • m_Singleton

        protected static GitSession m_Singleton
        the singleton.
      • m_Passwords

        protected Map<org.eclipse.jgit.transport.URIish,​char[]> m_Passwords
        for keeping track of passwords per ssh key.
    • Constructor Detail

      • GitSession

        protected GitSession()
        Initializes the session object.
    • Method Detail

      • addRepo

        public void addRepo​(org.eclipse.jgit.api.Git git)
        Adds the git repo.
        Parameters:
        git - the repo to add
      • repos

        public Collection<org.eclipse.jgit.api.Git> repos()
        Returns the currently managed repos.
        Returns:
        the repos
      • repoFor

        public org.eclipse.jgit.api.Git repoFor​(File path)
        Returns the repo for the specified dir/file.
        Parameters:
        path - the dir/file to get the repo for
        Returns:
        the repo, null if no repo (yet) available
      • isWithinRepo

        public boolean isWithinRepo​(File path)
        Checks whether the dir/file is inside a git-managed directory sub-tree. Automatically calls addRepo(Git) when it is within a git-controlled sub-tree.
        Parameters:
        path - the dir/file to check
        Returns:
        true if under control
        See Also:
        addRepo(Git)
      • getPassword

        public char[] getPassword​(org.eclipse.jgit.transport.URIish uri)
        Returns the password for the ssh key.
        Parameters:
        uri - the URI of the ssh key
        Returns:
        the password or null if none stored yet
      • getPasswordOrPrompt

        public char[] getPasswordOrPrompt​(org.eclipse.jgit.transport.URIish uri)
        Returns the password for the ssh key and prompts the user if not yet stored.
        Parameters:
        uri - the URI of the ssh key
        Returns:
        the key or null if none stored yet
      • getSshdSessionFactory

        public org.eclipse.jgit.transport.sshd.SshdSessionFactory getSshdSessionFactory()
        Returns a sshd session factory that will prompt the user for a password for each ssh key in use.
        Returns:
        the factory
      • setPassword

        public void setPassword​(org.eclipse.jgit.transport.URIish uri,
                                char[] password)
        Sets the password for the ssh key.
        Parameters:
        uri - the URI of the ssh key
        password - the password for the key
      • cleanUp

        public void cleanUp()
        Cleans up data structures, frees up memory.
        Specified by:
        cleanUp in interface adams.core.CleanUpHandler
      • getSingleton

        public static GitSession getSingleton()
        Returns the session singleton.
        Returns:
        the singleton