org.eclipse.jgit.lib
Class BaseRepositoryBuilder<B extends BaseRepositoryBuilder,R extends Repository>

java.lang.Object
  extended by org.eclipse.jgit.lib.BaseRepositoryBuilder<B,R>
Type Parameters:
B - type of the repository builder.
R - type of the repository that is constructed.
Direct Known Subclasses:
DfsRepositoryBuilder, FileRepositoryBuilder, RepositoryBuilder

public class BaseRepositoryBuilder<B extends BaseRepositoryBuilder,R extends Repository>
extends Object

Base builder to customize repository construction.

Repository implementations may subclass this builder in order to add custom repository detection methods.

See Also:
RepositoryBuilder, FileRepositoryBuilder

Constructor Summary
BaseRepositoryBuilder()
           
 
Method Summary
 B addAlternateObjectDirectories(Collection<File> inList)
          Add alternate object directories to the search list.
 B addAlternateObjectDirectories(File[] inList)
          Add alternate object directories to the search list.
 B addAlternateObjectDirectory(File other)
          Add an alternate object directory to the search list.
 B addCeilingDirectories(Collection<File> inList)
          Add ceiling directories to the search list.
 B addCeilingDirectories(File[] inList)
          Add ceiling directories to the search list.
 B addCeilingDirectory(File root)
          Add a ceiling directory to the search limit list.
 R build()
          Create a repository matching the configuration in this builder.
 B findGitDir()
          Configure GIT_DIR by searching up the file system.
 B findGitDir(File current)
          Configure GIT_DIR by searching up the file system.
 File[] getAlternateObjectDirectories()
           
protected  Config getConfig()
          Get the cached repository configuration, loading if not yet available.
 FS getFS()
           
 File getGitDir()
           
 File getIndexFile()
           
 File getObjectDirectory()
           
 File getWorkTree()
           
 boolean isBare()
           
 boolean isMustExist()
           
protected  Config loadConfig()
          Parse and load the repository specific configuration.
 B readEnvironment()
          Read standard Git environment variables and configure from those.
 B readEnvironment(SystemReader sr)
          Read standard Git environment variables and configure from those.
protected  void requireGitDirOrWorkTree()
          Require either gitDir or workTree to be set.
protected  FS safeFS()
           
protected  B self()
           
 B setBare()
          Force the repository to be treated as bare (have no working directory).
 B setFS(FS fs)
          Set the file system abstraction needed by this repository.
 B setGitDir(File gitDir)
          Set the Git directory storing the repository metadata.
 B setIndexFile(File indexFile)
          Set the local index file that is caching checked out file status.
 B setMustExist(boolean mustExist)
          Require the repository to exist before it can be opened.
 B setObjectDirectory(File objectDirectory)
          Set the directory storing the repository's objects.
 B setup()
          Guess and populate all parameters not already defined.
protected  void setupGitDir()
          Perform standard gitDir initialization.
protected  void setupInternals()
          Configure the internal implementation details of the repository.
protected  void setupWorkTree()
          Perform standard work-tree initialization.
 B setWorkTree(File workTree)
          Set the top level directory of the working files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseRepositoryBuilder

public BaseRepositoryBuilder()
Method Detail

setFS

public B setFS(FS fs)
Set the file system abstraction needed by this repository.

Parameters:
fs - the abstraction.
Returns:
this (for chaining calls).

getFS

public FS getFS()
Returns:
the file system abstraction, or null if not set.

setGitDir

public B setGitDir(File gitDir)
Set the Git directory storing the repository metadata.

The meta directory stores the objects, references, and meta files like MERGE_HEAD, or the index file. If null the path is assumed to be workTree/.git.

Parameters:
gitDir - GIT_DIR, the repository meta directory.
Returns:
this (for chaining calls).

getGitDir

public File getGitDir()
Returns:
the meta data directory; null if not set.

setObjectDirectory

public B setObjectDirectory(File objectDirectory)
Set the directory storing the repository's objects.

Parameters:
objectDirectory - GIT_OBJECT_DIRECTORY, the directory where the repository's object files are stored.
Returns:
this (for chaining calls).

getObjectDirectory

public File getObjectDirectory()
Returns:
the object directory; null if not set.

addAlternateObjectDirectory

public B addAlternateObjectDirectory(File other)
Add an alternate object directory to the search list.

This setting handles one alternate directory at a time, and is provided to support GIT_ALTERNATE_OBJECT_DIRECTORIES.

Parameters:
other - another objects directory to search after the standard one.
Returns:
this (for chaining calls).

addAlternateObjectDirectories

public B addAlternateObjectDirectories(Collection<File> inList)
Add alternate object directories to the search list.

This setting handles several alternate directories at once, and is provided to support GIT_ALTERNATE_OBJECT_DIRECTORIES.

Parameters:
inList - other object directories to search after the standard one. The collection's contents is copied to an internal list.
Returns:
this (for chaining calls).

addAlternateObjectDirectories

public B addAlternateObjectDirectories(File[] inList)
Add alternate object directories to the search list.

This setting handles several alternate directories at once, and is provided to support GIT_ALTERNATE_OBJECT_DIRECTORIES.

Parameters:
inList - other object directories to search after the standard one. The array's contents is copied to an internal list.
Returns:
this (for chaining calls).

getAlternateObjectDirectories

public File[] getAlternateObjectDirectories()
Returns:
ordered array of alternate directories; null if non were set.

setBare

public B setBare()
Force the repository to be treated as bare (have no working directory).

If bare the working directory aspects of the repository won't be configured, and will not be accessible.

Returns:
this (for chaining calls).

isBare

public boolean isBare()
Returns:
true if this repository was forced bare by setBare().

setMustExist

public B setMustExist(boolean mustExist)
Require the repository to exist before it can be opened.

Parameters:
mustExist - true if it must exist; false if it can be missing and created after being built.
Returns:
this (for chaining calls).

isMustExist

public boolean isMustExist()
Returns:
true if the repository must exist before being opened.

setWorkTree

public B setWorkTree(File workTree)
Set the top level directory of the working files.

Parameters:
workTree - GIT_WORK_TREE, the working directory of the checkout.
Returns:
this (for chaining calls).

getWorkTree

public File getWorkTree()
Returns:
the work tree directory, or null if not set.

setIndexFile

public B setIndexFile(File indexFile)
Set the local index file that is caching checked out file status.

The location of the index file tracking the status information for each checked out file in workTree. This may be null to assume the default gitDiir/index.

Parameters:
indexFile - GIT_INDEX_FILE, the index file location.
Returns:
this (for chaining calls).

getIndexFile

public File getIndexFile()
Returns:
the index file location, or null if not set.

readEnvironment

public B readEnvironment()
Read standard Git environment variables and configure from those.

This method tries to read the standard Git environment variables, such as GIT_DIR and GIT_WORK_TREE to configure this builder instance. If an environment variable is set, it overrides the value already set in this builder.

Returns:
this (for chaining calls).

readEnvironment

public B readEnvironment(SystemReader sr)
Read standard Git environment variables and configure from those.

This method tries to read the standard Git environment variables, such as GIT_DIR and GIT_WORK_TREE to configure this builder instance. If a property is already set in the builder, the environment variable is not used.

Parameters:
sr - the SystemReader abstraction to access the environment.
Returns:
this (for chaining calls).

addCeilingDirectory

public B addCeilingDirectory(File root)
Add a ceiling directory to the search limit list.

This setting handles one ceiling directory at a time, and is provided to support GIT_CEILING_DIRECTORIES.

Parameters:
root - a path to stop searching at; its parent will not be searched.
Returns:
this (for chaining calls).

addCeilingDirectories

public B addCeilingDirectories(Collection<File> inList)
Add ceiling directories to the search list.

This setting handles several ceiling directories at once, and is provided to support GIT_CEILING_DIRECTORIES.

Parameters:
inList - directory paths to stop searching at. The collection's contents is copied to an internal list.
Returns:
this (for chaining calls).

addCeilingDirectories

public B addCeilingDirectories(File[] inList)
Add ceiling directories to the search list.

This setting handles several ceiling directories at once, and is provided to support GIT_CEILING_DIRECTORIES.

Parameters:
inList - directory paths to stop searching at. The array's contents is copied to an internal list.
Returns:
this (for chaining calls).

findGitDir

public B findGitDir()
Configure GIT_DIR by searching up the file system.

Starts from the current working directory of the JVM and scans up through the directory tree until a Git repository is found. Success can be determined by checking for getGitDir() != null.

The search can be limited to specific spaces of the local filesystem by addCeilingDirectory(File), or inheriting the list through a prior call to readEnvironment().

Returns:
this (for chaining calls).

findGitDir

public B findGitDir(File current)
Configure GIT_DIR by searching up the file system.

Starts from the supplied directory path and scans up through the parent directory tree until a Git repository is found. Success can be determined by checking for getGitDir() != null.

The search can be limited to specific spaces of the local filesystem by addCeilingDirectory(File), or inheriting the list through a prior call to readEnvironment().

Parameters:
current - directory to begin searching in.
Returns:
this (for chaining calls).

setup

public B setup()
                                      throws IllegalArgumentException,
                                             IOException
Guess and populate all parameters not already defined.

If an option was not set, the setup method will try to default the option based on other options. If insufficient information is available, an exception is thrown to the caller.

Returns:
this
Throws:
IllegalArgumentException - insufficient parameters were set, or some parameters are incompatible with one another.
IOException - the repository could not be accessed to configure the rest of the builder's parameters.

build

public R build()
                           throws IOException
Create a repository matching the configuration in this builder.

If an option was not set, the build method will try to default the option based on other options. If insufficient information is available, an exception is thrown to the caller.

Returns:
a repository matching this configuration.
Throws:
IllegalArgumentException - insufficient parameters were set.
IOException - the repository could not be accessed to configure the rest of the builder's parameters.

requireGitDirOrWorkTree

protected void requireGitDirOrWorkTree()
Require either gitDir or workTree to be set.


setupGitDir

protected void setupGitDir()
                    throws IOException
Perform standard gitDir initialization.

Throws:
IOException - the repository could not be accessed

setupWorkTree

protected void setupWorkTree()
                      throws IOException
Perform standard work-tree initialization.

This is a method typically invoked inside of setup(), near the end after the repository has been identified and its configuration is available for inspection.

Throws:
IOException - the repository configuration could not be read.

setupInternals

protected void setupInternals()
                       throws IOException
Configure the internal implementation details of the repository.

Throws:
IOException - the repository could not be accessed

getConfig

protected Config getConfig()
                    throws IOException
Get the cached repository configuration, loading if not yet available.

Returns:
the configuration of the repository.
Throws:
IOException - the configuration is not available, or is badly formed.

loadConfig

protected Config loadConfig()
                     throws IOException
Parse and load the repository specific configuration.

The default implementation reads gitDir/config, or returns an empty configuration if gitDir was not set.

Returns:
the repository's configuration.
Throws:
IOException - the configuration is not available.

safeFS

protected FS safeFS()
Returns:
the configured FS, or FS.DETECTED.

self

protected final B self()
Returns:
this


Copyright © 2012. All Rights Reserved.