allensoft.javacvs.client
Class WorkingDirectory

java.lang.Object
  |
  +--allensoft.javacvs.client.WorkingDirectory

public final class WorkingDirectory
extends java.lang.Object

Represents a working directory for a CVS client. A working directory contains a "CVS" sub directory that contains files such as "Entries", "Root" and "Repository". This class provides a high level view of these files and the entries that the working directory conatins. For efficiency purposes one cannot construct objects of this class directly but instead one uses the getWorkingDirectory static method to construct them. This allows a cache to be maintained so that the files are not constantly reopened and parsed every time they are needed.


Field Summary
protected  boolean m_bEntriesModified
          true if the entries have been modified and need to be written to disk.
 
Method Summary
 void addWorkingDirectoryListener(WorkingDirectoryListener l)
           
 boolean clearStaticDirectory()
          Clears the static directory flag for this working directory.
static void createWorkingDirectory(java.io.File directory, RepositoryLocation repository, java.lang.String sModule)
          Creates a new CVS working directory.
protected  void fireEntryAdded(Entry entry)
           
protected  void fireEntryRemoved(Entry entry)
           
protected  void fireReloadedEntries()
           
 java.lang.String getAbsoluteRepositoryPath()
          Gets the absolute repossitory path for this working directory in the repository on the server.
 java.lang.String getCheckinProgram()
           
 java.io.File getCVSFile(java.lang.String sName)
           
 java.io.File getDirectory()
          Gets the directory this working directory represents.
 DirectoryEntry[] getDirectoryEntries()
          Gets all the directory entries in this working directory.
 Entry[] getEntries()
          Gets all the entries in this working directory.
 java.io.File getEntriesFile()
          Gets the file object that represents the "Entries" file within this working directory.
 Entry getEntry(java.io.File file)
          Gets the Entry for the specified file.
 Entry getEntry(java.lang.String sName)
          Gets a Entry with the specified name.
 FileEntry[] getFileEntries()
          Gets all the file entries in this working directory without using recursion.
 FileEntry[] getFileEntries(boolean bRecursive)
          Gets all file entries in this working directory with optional recursion.
 FileEntry[] getFileEntries(FileEntryFilter filter, boolean bRecursive)
          Gets all file entries in this working directory that are accepted by the supplied filter.
 java.lang.String getModulePath()
          Gets the module path for this working directory.
 java.io.File getRepositoryFile()
          Gets the file object that represents the "Repository" file within this working directory.
 RepositoryLocation getRepositoryLocation()
          Gets the repository location for this working directory.
 java.io.File getRootFile()
          Gets the file object that represents the "Root" file within this working directory.
 java.lang.String getStickyTagSpec()
          Gets the sticky tag spec for this working directory.
 java.lang.String getUpdateProgram()
           
static WorkingDirectory getWorkingDirectory(DirectoryEntry entry)
          Gets the WorkingDirectory object for the specified directory.
static WorkingDirectory getWorkingDirectory(java.io.File directory)
          Gets the WorkingDirectory object for the specified directory.
static WorkingDirectory getWorkingDirectory(java.lang.String sDirectory)
          Gets the WorkingDirectory object for the specified directory.
 boolean hasFileEntries(FileEntryFilter filter, boolean bRecursive)
          Checks if this working firectory has any file entries that match the filter.
 int hashCode()
           
 boolean isStaticDirectory()
          Checks if this working directory is a static directory.
static boolean isWorkingDirectory(java.io.File directory)
          Tests whether a particular directory is a CVS working directory or not.
 void loadEntriesFile()
          Loads the entries file and parses it.
 void reloadEntriesFile()
          Reloads the Entries file if necessary and updates the cache of entries.
static void reloadEntriesFiles()
          Realoads all Entries files for all working directories currently cached.
 void removeEntry(java.lang.String sName)
           
 void removeWorkingDirectoryListener(WorkingDirectoryListener l)
           
 boolean setStaticDirectory()
           
 FileEntry updateFileEntry(java.lang.String name, java.lang.String sRevision)
          Updates the file entry in this working directory with the specified name and settings.
 void writeEntriesFile()
          Writes the "Entries" file for this working directory to the standard CVS/Entries file.
 void writeEntriesFile(java.io.File entriesFile)
          Writes the "Entries" file for this working directory to the supplied file.
 void writeEntriesFile(java.io.PrintWriter out)
          Writes the "Entries" file for this working directory to the supplied PrintWriter.
static void writeEntriesFiles()
          Writes all "Entries" files that need to be written because entries have been modified in some working directories.
 void writeRepositoryFile()
           
 void writeRepositoryFile(java.io.File rootFile)
           
 void writeRepositoryFile(java.io.PrintWriter out)
          Writes the "Repository" file to the supplied PrintWriter.
 void writeRootFile()
           
 void writeRootFile(java.io.File rootFile)
           
 void writeRootFile(java.io.PrintWriter out)
          Writes the "Root" file to the supplied PrintWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_bEntriesModified

protected boolean m_bEntriesModified
true if the entries have been modified and need to be written to disk.
Method Detail

addWorkingDirectoryListener

public void addWorkingDirectoryListener(WorkingDirectoryListener l)

removeWorkingDirectoryListener

public void removeWorkingDirectoryListener(WorkingDirectoryListener l)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getWorkingDirectory

public static WorkingDirectory getWorkingDirectory(java.io.File directory)
                                            throws java.io.IOException,
                                                   CVSException
Gets the WorkingDirectory object for the specified directory.

getWorkingDirectory

public static WorkingDirectory getWorkingDirectory(DirectoryEntry entry)
                                            throws java.io.IOException,
                                                   CVSException
Gets the WorkingDirectory object for the specified directory.

getWorkingDirectory

public static WorkingDirectory getWorkingDirectory(java.lang.String sDirectory)
                                            throws java.io.IOException,
                                                   CVSException
Gets the WorkingDirectory object for the specified directory.

isWorkingDirectory

public static boolean isWorkingDirectory(java.io.File directory)
Tests whether a particular directory is a CVS working directory or not. This is done by checking for the presence of a "CVS" subdirectory and the "Entries", "Repository" and "Root" files within that directory.

createWorkingDirectory

public static void createWorkingDirectory(java.io.File directory,
                                          RepositoryLocation repository,
                                          java.lang.String sModule)
                                   throws java.io.IOException
Creates a new CVS working directory. This involves creating the "CVS" subdirectory and the "Entries", "Repository" and "Root" files within that directory.

getRepositoryLocation

public RepositoryLocation getRepositoryLocation()
Gets the repository location for this working directory.

getModulePath

public java.lang.String getModulePath()
Gets the module path for this working directory. The module path is the path relative to the repository path on the server that this working directory corresponds to.

getAbsoluteRepositoryPath

public java.lang.String getAbsoluteRepositoryPath()
Gets the absolute repossitory path for this working directory in the repository on the server. This is made up of the repository path and the module path.

getEntry

public Entry getEntry(java.io.File file)
Gets the Entry for the specified file. The file should be within the working directory.
Returns:
the Entry or null if there isn't one.

getEntry

public Entry getEntry(java.lang.String sName)
Gets a Entry with the specified name.
Returns:
the Entry or null if there isn't one.

hasFileEntries

public boolean hasFileEntries(FileEntryFilter filter,
                              boolean bRecursive)
                       throws java.io.IOException,
                              CVSException
Checks if this working firectory has any file entries that match the filter.

getFileEntries

public FileEntry[] getFileEntries(FileEntryFilter filter,
                                  boolean bRecursive)
                           throws java.io.IOException,
                                  CVSException
Gets all file entries in this working directory that are accepted by the supplied filter. If bRecursive is true then it will recursively scan directory entries in this working directory, otherwise it only scans this working directory.

getFileEntries

public FileEntry[] getFileEntries(boolean bRecursive)
                           throws java.io.IOException,
                                  CVSException
Gets all file entries in this working directory with optional recursion.

getFileEntries

public FileEntry[] getFileEntries()
Gets all the file entries in this working directory without using recursion.

getDirectoryEntries

public DirectoryEntry[] getDirectoryEntries()
Gets all the directory entries in this working directory.

getEntries

public Entry[] getEntries()
Gets all the entries in this working directory.

loadEntriesFile

public void loadEntriesFile()
                     throws java.io.IOException,
                            InvalidEntryFormatException,
                            InvalidKeywordSubstitutionModeException
Loads the entries file and parses it. Entries are inserted into the cache for later retrieval by methids such as getEntry.

updateFileEntry

public FileEntry updateFileEntry(java.lang.String name,
                                 java.lang.String sRevision)
                          throws CVSException
Updates the file entry in this working directory with the specified name and settings. If an entry by that name does not exist then a new file entry is added to this working directory with the specified settings.

removeEntry

public void removeEntry(java.lang.String sName)

isStaticDirectory

public boolean isStaticDirectory()
Checks if this working directory is a static directory. This is determined by checking for the presence of the Entries.Static file in the CVS subdirectory. A static directory implies that additional files shouldn't be checked out unless explicitly requested.

setStaticDirectory

public boolean setStaticDirectory()
                           throws java.io.IOException

clearStaticDirectory

public boolean clearStaticDirectory()
Clears the static directory flag for this working directory.

getStickyTagSpec

public java.lang.String getStickyTagSpec()
                                  throws java.io.IOException
Gets the sticky tag spec for this working directory. This is set by a Set-sticky response from the server and the tag spec is stored in the CVS/Tag file.
Returns:
the sticky tag spec for this working directory or null if one has not been set.

getCheckinProgram

public java.lang.String getCheckinProgram()
                                   throws java.io.IOException

getUpdateProgram

public java.lang.String getUpdateProgram()
                                  throws java.io.IOException

reloadEntriesFile

public void reloadEntriesFile()
                       throws java.io.IOException,
                              InvalidEntryFormatException,
                              InvalidKeywordSubstitutionModeException
Reloads the Entries file if necessary and updates the cache of entries. This is the same as calling loadEntriesFile() but only loads if the file has been modified.

reloadEntriesFiles

public static void reloadEntriesFiles()
                               throws java.io.IOException,
                                      InvalidEntryFormatException,
                                      InvalidKeywordSubstitutionModeException
Realoads all Entries files for all working directories currently cached. This method should be called periodically in case an Entries file has been modified externally to this API (for example, by the CVS command line client program that the user may have launched manually). The CVSClient calls this evrytime before a request is performed so there is no need to call it to ensure correct operation of requests.

writeEntriesFile

public void writeEntriesFile(java.io.PrintWriter out)
Writes the "Entries" file for this working directory to the supplied PrintWriter.

writeEntriesFile

public void writeEntriesFile(java.io.File entriesFile)
                      throws java.io.IOException
Writes the "Entries" file for this working directory to the supplied file.

writeEntriesFile

public void writeEntriesFile()
                      throws java.io.IOException
Writes the "Entries" file for this working directory to the standard CVS/Entries file. This should be called when changes are made to entries in this working directory.

writeEntriesFiles

public static void writeEntriesFiles()
                              throws java.io.IOException
Writes all "Entries" files that need to be written because entries have been modified in some working directories.

writeRootFile

public void writeRootFile(java.io.PrintWriter out)
Writes the "Root" file to the supplied PrintWriter.

writeRootFile

public void writeRootFile(java.io.File rootFile)
                   throws java.io.IOException

writeRootFile

public void writeRootFile()
                   throws java.io.IOException

writeRepositoryFile

public void writeRepositoryFile(java.io.PrintWriter out)
Writes the "Repository" file to the supplied PrintWriter.

writeRepositoryFile

public void writeRepositoryFile(java.io.File rootFile)
                         throws java.io.IOException

writeRepositoryFile

public void writeRepositoryFile()
                         throws java.io.IOException

getDirectory

public java.io.File getDirectory()
Gets the directory this working directory represents.

getCVSFile

public java.io.File getCVSFile(java.lang.String sName)

getEntriesFile

public java.io.File getEntriesFile()
Gets the file object that represents the "Entries" file within this working directory.

getRootFile

public java.io.File getRootFile()
Gets the file object that represents the "Root" file within this working directory.

getRepositoryFile

public java.io.File getRepositoryFile()
Gets the file object that represents the "Repository" file within this working directory.

fireReloadedEntries

protected void fireReloadedEntries()

fireEntryAdded

protected void fireEntryAdded(Entry entry)

fireEntryRemoved

protected void fireEntryRemoved(Entry entry)