Class FileResolver<C>

  • Type Parameters:
    C - type of connection
    All Implemented Interfaces:
    RepositoryResolver<C>

    public class FileResolver<C>
    extends java.lang.Object
    implements RepositoryResolver<C>
    Default resolver serving from the local filesystem.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean exportAll  
      private java.util.Collection<java.io.File> exportBase  
      private java.util.Map<java.lang.String,​Repository> exports  
    • Constructor Summary

      Constructors 
      Constructor Description
      FileResolver()
      Initialize an empty file based resolver.
      FileResolver​(java.io.File basePath, boolean exportAll)
      Create a new resolver for the given path.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void exportDirectory​(java.io.File dir)
      Recursively export all Git repositories within a directory.
      void exportRepository​(java.lang.String name, Repository db)
      Add a single repository to the set that is exported by this daemon.
      boolean isExportAll()
      Whether git-daemon-export-ok is required to export a repository
      protected boolean isExportOk​(C req, java.lang.String repositoryName, Repository db)
      Check if this repository can be served.
      private static boolean isUnreasonableName​(java.lang.String name)  
      private static java.lang.String nameWithDotGit​(java.lang.String name)  
      Repository open​(C req, java.lang.String name)
      Locate and open a reference to a Repository.
      void setExportAll​(boolean export)
      Set whether or not to export all repositories.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • exportAll

        private volatile boolean exportAll
      • exports

        private final java.util.Map<java.lang.String,​Repository> exports
      • exportBase

        private final java.util.Collection<java.io.File> exportBase
    • Constructor Detail

      • FileResolver

        public FileResolver()
        Initialize an empty file based resolver.
      • FileResolver

        public FileResolver​(java.io.File basePath,
                            boolean exportAll)
        Create a new resolver for the given path.
        Parameters:
        basePath - the base path all repositories are rooted under.
        exportAll - if true, exports all repositories, ignoring the check for the git-daemon-export-ok files.
    • Method Detail

      • open

        public Repository open​(C req,
                               java.lang.String name)
                        throws RepositoryNotFoundException,
                               ServiceNotEnabledException
        Locate and open a reference to a Repository.

        The caller is responsible for closing the returned Repository.

        Specified by:
        open in interface RepositoryResolver<C>
        Parameters:
        req - the current request, may be used to inspect session state including cookies or user authentication.
        name - name of the repository, as parsed out of the URL.
        Returns:
        the opened repository instance, never null.
        Throws:
        RepositoryNotFoundException - the repository does not exist or the name is incorrectly formatted as a repository name.
        ServiceNotEnabledException - the repository may exist, but HTTP access is not allowed on the target repository, for the current user.
      • isExportAll

        public boolean isExportAll()
        Whether git-daemon-export-ok is required to export a repository
        Returns:
        false if git-daemon-export-ok is required to export a repository; true if git-daemon-export-ok is ignored.
        See Also:
        setExportAll(boolean)
      • setExportAll

        public void setExportAll​(boolean export)
        Set whether or not to export all repositories.

        If false (the default), repositories must have a git-daemon-export-ok file to be accessed through this daemon.

        If true, all repositories are available through the daemon, whether or not git-daemon-export-ok exists.

        Parameters:
        export - a boolean.
      • exportRepository

        public void exportRepository​(java.lang.String name,
                                     Repository db)
        Add a single repository to the set that is exported by this daemon.

        The existence (or lack-thereof) of git-daemon-export-ok is ignored by this method. The repository is always published.

        Parameters:
        name - name the repository will be published under.
        db - the repository instance.
      • exportDirectory

        public void exportDirectory​(java.io.File dir)
        Recursively export all Git repositories within a directory.
        Parameters:
        dir - the directory to export. This directory must not itself be a git repository, but any directory below it which has a file named git-daemon-export-ok will be published.
      • isExportOk

        protected boolean isExportOk​(C req,
                                     java.lang.String repositoryName,
                                     Repository db)
                              throws java.io.IOException
        Check if this repository can be served.

        The default implementation of this method returns true only if either isExportAll() is true, or the git-daemon-export-ok file is present in the repository's directory.

        Parameters:
        req - the current HTTP request.
        repositoryName - name of the repository, as present in the URL.
        db - the opened repository instance.
        Returns:
        true if the repository is accessible; false if not.
        Throws:
        java.io.IOException - the repository could not be accessed, the caller will claim the repository does not exist.
      • nameWithDotGit

        private static java.lang.String nameWithDotGit​(java.lang.String name)
      • isUnreasonableName

        private static boolean isUnreasonableName​(java.lang.String name)