com.caucho.env.repository
Class AbstractRepository

java.lang.Object
  extended by com.caucho.env.repository.AbstractRepository
All Implemented Interfaces:
Repository, RepositorySpi
Direct Known Subclasses:
ClusterRepository, FileRepository

public abstract class AbstractRepository
extends java.lang.Object
implements Repository, RepositorySpi


Constructor Summary
protected AbstractRepository()
           
 
Method Summary
protected  java.lang.String addArchive(GitCommitJar commit)
           
 java.lang.String addArchive(java.io.InputStream is)
          Adds a path to the repository.
 java.lang.String addArchive(Path path)
          Adds a path to the repository.
 java.lang.String addBlob(java.io.InputStream is, long length)
          Adds a stream to the repository.
abstract  java.lang.String addCommit(GitCommit commit)
          Adds a git commit to the repository
 void addListener(java.lang.String tag, RepositoryTagListener listener)
          Adds a tag listener
 java.lang.String addPath(Path path)
          Adds a path to the repository.
protected  RepositoryTagMap addTagData(java.lang.String tagName, java.lang.String contentHash, java.util.Map<java.lang.String,java.lang.String> commitMetaData)
          Creates a tag entry
 java.lang.String addTree(GitTree tree)
          Adds a git tree to the repository
 void checkForUpdate()
          Updates the repository
 void checkForUpdate(boolean isExact)
          Updates the repository
 java.lang.String commitArchive(CommitBuilder commit, java.io.InputStream is)
          Convenience method for adding the content of a jar.
 java.lang.String commitArchive(CommitBuilder commit, Path archivePath)
          Convenience method for adding the content of a jar.
 java.lang.String commitPath(CommitBuilder commit, Path directoryPath)
          Convenience method for adding a path/directory.
abstract  boolean exists(java.lang.String sha1)
          Returns true if the file exists.
abstract  void expandToPath(java.lang.String contentHash, Path path)
          Expands the repository to the filesystem.
protected  java.lang.String getCommitHash()
          Returns the tag commit hash
abstract  java.lang.String getRepositoryRootHash()
          Returns the sha1 stored at the gitTag
protected  java.lang.String getRepositoryTag()
          Returns the .git repository tag
 java.lang.String getTagContentHash(java.lang.String tag)
          Returns the tag root.
protected  java.lang.String getTagHash()
           
 java.util.Map<java.lang.String,RepositoryTagEntry> getTagMap()
          Returns the tag map.
protected  long getTagSequence()
           
abstract  GitType getType(java.lang.String sha1)
          Returns true if the file is a blob.
 void init()
          Initialize the repository
 boolean isBlob(java.lang.String sha1)
          Returns true if the file is a blob.
 boolean isCommit(java.lang.String sha1)
          Returns true if the file is a commit
 boolean isTree(java.lang.String sha1)
          Returns true if the file is a tree
protected  void loadLocalRoot()
           
abstract  java.io.InputStream openBlob(java.lang.String sha1)
          Opens a stream to a git blob
abstract  java.io.InputStream openRawGitFile(java.lang.String contentHash)
          Opens a stream to the raw git file.
abstract  boolean putTag(java.lang.String tag, java.lang.String contentHash, java.util.Map<java.lang.String,java.lang.String> commitMetaData)
          Adds a tag
abstract  GitCommit readCommit(java.lang.String commitHash)
          Reads a git commit from the repository
abstract  GitTree readTree(java.lang.String treeHash)
          Reads a git tree from the repository
 void removeListener(java.lang.String tag, RepositoryTagListener listener)
          Adds a tag listener
 boolean removeTag(CommitBuilder commit)
          Convenience method for adding the content of a jar.
abstract  boolean removeTag(java.lang.String tag, java.util.Map<java.lang.String,java.lang.String> commitMetaData)
          Removes a tag
protected  RepositoryTagMap removeTagData(java.lang.String tagName, java.util.Map<java.lang.String,java.lang.String> commitMetaData)
          Removes a tag entry
abstract  void setRepositoryRootHash(java.lang.String repositoryCommitHash)
          Writes the sha1 stored at the gitTag
protected  boolean setTagMap(RepositoryTagMap tagMap)
           
 void start()
          Start the repository
 void stop()
           
 java.lang.String toString()
           
protected  boolean update(java.lang.String sha1, boolean isNew)
          Updates based on a sha1 commit entry
protected  void updateLoad(java.lang.String sha1, boolean isNew)
           
protected  void updateRepositoryRoot(java.lang.String sha1, long sequence)
           
protected  void updateTagMap(java.lang.String sha1, boolean isNew)
           
 boolean validateHash(java.lang.String sha1)
          Validates a file, checking that it and its dependencies exist.
 void validateRawGitFile(java.lang.String contentHash)
          Removes a raw git file
protected  GitType validateRawHash(java.lang.String hash)
           
abstract  void writeBlobToStream(java.lang.String blobHash, java.io.OutputStream os)
          Writes the contents to a stream.
abstract  void writeRawGitFile(java.lang.String contentHash, java.io.InputStream is)
          Writes a raw git file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.caucho.env.repository.RepositorySpi
addBlob
 

Constructor Detail

AbstractRepository

protected AbstractRepository()
Method Detail

init

public void init()
Initialize the repository


start

public void start()
Start the repository


stop

public void stop()

getRepositoryTag

protected java.lang.String getRepositoryTag()
Returns the .git repository tag


checkForUpdate

public final void checkForUpdate()
Updates the repository


checkForUpdate

public void checkForUpdate(boolean isExact)
Updates the repository

Specified by:
checkForUpdate in interface RepositorySpi

loadLocalRoot

protected void loadLocalRoot()

update

protected boolean update(java.lang.String sha1,
                         boolean isNew)
Updates based on a sha1 commit entry


getTagHash

protected java.lang.String getTagHash()

getTagSequence

protected long getTagSequence()

updateLoad

protected void updateLoad(java.lang.String sha1,
                          boolean isNew)

updateTagMap

protected void updateTagMap(java.lang.String sha1,
                            boolean isNew)

getCommitHash

protected java.lang.String getCommitHash()
Returns the tag commit hash


getTagMap

public java.util.Map<java.lang.String,RepositoryTagEntry> getTagMap()
Returns the tag map.

Specified by:
getTagMap in interface Repository
Specified by:
getTagMap in interface RepositorySpi

getTagContentHash

public java.lang.String getTagContentHash(java.lang.String tag)
Returns the tag root.

Specified by:
getTagContentHash in interface Repository
Specified by:
getTagContentHash in interface RepositorySpi

putTag

public abstract boolean putTag(java.lang.String tag,
                               java.lang.String contentHash,
                               java.util.Map<java.lang.String,java.lang.String> commitMetaData)
Adds a tag

Specified by:
putTag in interface RepositorySpi
Parameters:
tagName - the symbolic tag for the repository
contentHash - the hash of the tag's content
commitMessage - the commit message for the tag update
commitMetaData - additional commit attributes

removeTag

public abstract boolean removeTag(java.lang.String tag,
                                  java.util.Map<java.lang.String,java.lang.String> commitMetaData)
Removes a tag

Specified by:
removeTag in interface RepositorySpi
Parameters:
tagName - the symbolic tag for the repository
commitMessage - user's message for the commit
commitMetaData - additional commit meta-data

commitArchive

public java.lang.String commitArchive(CommitBuilder commit,
                                      Path archivePath)
Convenience method for adding the content of a jar.

Specified by:
commitArchive in interface Repository

commitArchive

public java.lang.String commitArchive(CommitBuilder commit,
                                      java.io.InputStream is)
Convenience method for adding the content of a jar.

Specified by:
commitArchive in interface Repository

commitPath

public java.lang.String commitPath(CommitBuilder commit,
                                   Path directoryPath)
Convenience method for adding a path/directory.

Specified by:
commitPath in interface Repository

removeTag

public boolean removeTag(CommitBuilder commit)
Convenience method for adding the content of a jar.

Specified by:
removeTag in interface Repository

addTagData

protected RepositoryTagMap addTagData(java.lang.String tagName,
                                      java.lang.String contentHash,
                                      java.util.Map<java.lang.String,java.lang.String> commitMetaData)
Creates a tag entry

Parameters:
tagName - the symbolic tag for the repository
contentHash - the hash of the tag's content
commitMessage - user's message for the commit
commitMetaData - additional attributes for the commit

removeTagData

protected RepositoryTagMap removeTagData(java.lang.String tagName,
                                         java.util.Map<java.lang.String,java.lang.String> commitMetaData)
Removes a tag entry

Parameters:
tag - the symbolic tag for the repository
user - the user adding a tag.
server - the server adding a tag.
message - user's message for the commit
version - symbolic version name for the commit

setTagMap

protected boolean setTagMap(RepositoryTagMap tagMap)

updateRepositoryRoot

protected void updateRepositoryRoot(java.lang.String sha1,
                                    long sequence)

addListener

public void addListener(java.lang.String tag,
                        RepositoryTagListener listener)
Adds a tag listener

Specified by:
addListener in interface Repository
Specified by:
addListener in interface RepositorySpi

removeListener

public void removeListener(java.lang.String tag,
                           RepositoryTagListener listener)
Adds a tag listener

Specified by:
removeListener in interface Repository
Specified by:
removeListener in interface RepositorySpi

getRepositoryRootHash

public abstract java.lang.String getRepositoryRootHash()
Returns the sha1 stored at the gitTag

Specified by:
getRepositoryRootHash in interface RepositorySpi
Returns:
the hash of the .git Commit for the current repository root.

setRepositoryRootHash

public abstract void setRepositoryRootHash(java.lang.String repositoryCommitHash)
Writes the sha1 stored at the gitTag

Specified by:
setRepositoryRootHash in interface RepositorySpi
Parameters:
repositoryCommitHash - the hash of the new .git Commit for the repository.

exists

public abstract boolean exists(java.lang.String sha1)
Returns true if the file exists.

Specified by:
exists in interface RepositorySpi

getType

public abstract GitType getType(java.lang.String sha1)
Returns true if the file is a blob.

Specified by:
getType in interface RepositorySpi

isBlob

public final boolean isBlob(java.lang.String sha1)
Returns true if the file is a blob.

Specified by:
isBlob in interface RepositorySpi

isTree

public final boolean isTree(java.lang.String sha1)
Returns true if the file is a tree

Specified by:
isTree in interface RepositorySpi

isCommit

public final boolean isCommit(java.lang.String sha1)
Returns true if the file is a commit

Specified by:
isCommit in interface RepositorySpi

validateHash

public boolean validateHash(java.lang.String sha1)
                     throws java.io.IOException
Validates a file, checking that it and its dependencies exist.

Specified by:
validateHash in interface RepositorySpi
Throws:
java.io.IOException

validateRawHash

protected GitType validateRawHash(java.lang.String hash)

addPath

public java.lang.String addPath(Path path)
Adds a path to the repository. If the path is a directory, adds the contents recursively.

Specified by:
addPath in interface RepositorySpi

addArchive

public java.lang.String addArchive(Path path)
Adds a path to the repository. If the path is a directory, adds the contents recursively.

Specified by:
addArchive in interface RepositorySpi

addArchive

public java.lang.String addArchive(java.io.InputStream is)
Adds a path to the repository. If the path is a directory, adds the contents recursively.


addArchive

protected java.lang.String addArchive(GitCommitJar commit)
                               throws java.io.IOException
Throws:
java.io.IOException

addBlob

public java.lang.String addBlob(java.io.InputStream is,
                                long length)
                         throws java.io.IOException
Adds a stream to the repository.

Specified by:
addBlob in interface RepositorySpi
Parameters:
is - the blob's input stream
length - the blob's length
Throws:
java.io.IOException

openBlob

public abstract java.io.InputStream openBlob(java.lang.String sha1)
                                      throws java.io.IOException
Opens a stream to a git blob

Specified by:
openBlob in interface RepositorySpi
Throws:
java.io.IOException

readTree

public abstract GitTree readTree(java.lang.String treeHash)
                          throws java.io.IOException
Reads a git tree from the repository

Specified by:
readTree in interface RepositorySpi
Throws:
java.io.IOException

addTree

public java.lang.String addTree(GitTree tree)
                         throws java.io.IOException
Adds a git tree to the repository

Specified by:
addTree in interface RepositorySpi
Throws:
java.io.IOException

readCommit

public abstract GitCommit readCommit(java.lang.String commitHash)
                              throws java.io.IOException
Reads a git commit from the repository

Specified by:
readCommit in interface RepositorySpi
Throws:
java.io.IOException

addCommit

public abstract java.lang.String addCommit(GitCommit commit)
                                    throws java.io.IOException
Adds a git commit to the repository

Specified by:
addCommit in interface RepositorySpi
Throws:
java.io.IOException

openRawGitFile

public abstract java.io.InputStream openRawGitFile(java.lang.String contentHash)
                                            throws java.io.IOException
Opens a stream to the raw git file.

Specified by:
openRawGitFile in interface RepositorySpi
Throws:
java.io.IOException

writeRawGitFile

public abstract void writeRawGitFile(java.lang.String contentHash,
                                     java.io.InputStream is)
                              throws java.io.IOException
Writes a raw git file

Specified by:
writeRawGitFile in interface RepositorySpi
Throws:
java.io.IOException

validateRawGitFile

public void validateRawGitFile(java.lang.String contentHash)
Removes a raw git file

Specified by:
validateRawGitFile in interface RepositorySpi

writeBlobToStream

public abstract void writeBlobToStream(java.lang.String blobHash,
                                       java.io.OutputStream os)
Writes the contents to a stream.

Specified by:
writeBlobToStream in interface RepositorySpi
Parameters:
blobHash - the hash of the source blob
os - the OutputStream to write to

expandToPath

public abstract void expandToPath(java.lang.String contentHash,
                                  Path path)
Expands the repository to the filesystem.

Specified by:
expandToPath in interface RepositorySpi

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object