Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

allensoft.javacvs.client
Class WorkingDirectory  view WorkingDirectory download WorkingDirectory.java

java.lang.Object
  extended byallensoft.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
private static java.util.Map g_WorkingDirectories
          The hash map of all entries files that have been loaded.
private  boolean m_bEntriesModified
          true if the entries have been modified and need to be written to disk.
private  java.io.File m_Directory
          The directory that this working directory represents.
private  java.util.Map m_Entries
          The cache of all entries in this working directory.
private  java.beans.PropertyChangeListener m_FileEntryListener
          Listener that listens to proiperty changes for FileEntries in this working directory.
private  java.util.ArrayList m_Listeners
          The list of event listeners for events that this WorkingDirectory fires.
private  long m_nEntriesFileLastModificationTime
          The last modified timestamp of the Entries file.
private  RepositoryLocation m_RepositoryLocation
          The repository location for this working directory.
private  java.lang.String m_sModulePath
          The module path for this working directory relative to the root of the repository path.
 
Constructor Summary
private WorkingDirectory(java.io.File directory)
           
 
Method Summary
(package private)  void addDirectoryEntry(java.lang.String sName)
           
 void addWorkingDirectoryListener(allensoft.javacvs.client.event.WorkingDirectoryListener l)
           
(package private)  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.
private  void fireEntryAdded(Entry entry)
           
private  void fireEntryRemoved(Entry entry)
           
private  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()
           
(package private)  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.
 DirectoryEntry[] getDirectoryEntries(boolean bRecursive)
          Gets all file entries in this working directory with optional recursion.
 DirectoryEntry[] getDirectoryEntries(DirectoryEntryFilter filter, boolean bRecursive)
          Gets all file entries in this working directory that are accepted by the supplied filter.
 Entry[] getEntries()
          Gets all the entries in this working directory.
 void getEntries(java.util.Collection entries, EntryFilter filter, boolean bRecursive)
          Gets the entries that the filter accepts and adds them to the supplied collection.
 Entry[] getEntries(EntryFilter filter, boolean bRecursive)
           
private  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.
private  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.
private  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 hasEntries(EntryFilter filter, boolean bRecursive)
          Checks if this working directory has any entries that match the filter.
 int hashCode()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
 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.
private  void loadEntriesFile()
          Loads the entries file and parses it.
(package private)  void readBaserevFile(java.util.List files, java.util.List revisions)
          Reads the current Baserev file in the CVS directory to determine the names and revisions of files being edited in this working directory.
private static java.lang.String readSingleLineFile(java.io.File file)
          Reads the first line from the supplied file and returns it as a string.
private  void reloadEntriesFile()
          Reloads the Entries file if necessary and updates the cache of entries.
(package private)  void removeEntry(java.lang.String sName)
           
 void removeWorkingDirectoryListener(allensoft.javacvs.client.event.WorkingDirectoryListener l)
           
(package private)  boolean setStaticDirectory()
           
static void synchWithFileSystem()
          Realoads all Entries files for all working directories currently cached.
(package private)  FileEntry updateFileEntry(java.lang.String name, java.lang.String sRevision)
          Updates the file entry in this working directory with the specified name and settings.
(package private)  void writeBaserevFile(java.util.List files, java.util.List revisions)
          Writes the Baserev file describing the names of files being edited and their revisions.
private  void writeEntriesFile()
          Writes the "Entries" file for this working directory to the supplied file.
(package private) static void writeEntriesFiles()
          Writes all "Entries" files that need to be written because entries have been modified in some working directories.
private  void writeRepositoryFile(java.io.File rootFile)
           
 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_Directory

private java.io.File m_Directory
The directory that this working directory represents.


m_Entries

private java.util.Map m_Entries
The cache of all entries in this working directory. The key is a File and the value is an Entry.


m_nEntriesFileLastModificationTime

private long m_nEntriesFileLastModificationTime
The last modified timestamp of the Entries file. This is used to determine in the cache of entries needs to be reloaded (because another program has modified it externally for example).


m_RepositoryLocation

private RepositoryLocation m_RepositoryLocation
The repository location for this working directory.


m_sModulePath

private java.lang.String m_sModulePath
The module path for this working directory relative to the root of the repository path.


m_bEntriesModified

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


g_WorkingDirectories

private static java.util.Map g_WorkingDirectories
The hash map of all entries files that have been loaded. This is effectively a cache to prevent reloading and reparsing of the "CVS" files every time.


m_FileEntryListener

private java.beans.PropertyChangeListener m_FileEntryListener
Listener that listens to proiperty changes for FileEntries in this working directory. When a file entry is modified it marks the cache as being modified so it knows that it has to be saved at some point (by calling writeEntriesFile). This is usually done automatically when a request has been performed.


m_Listeners

private java.util.ArrayList m_Listeners
The list of event listeners for events that this WorkingDirectory fires.

Constructor Detail

WorkingDirectory

private WorkingDirectory(java.io.File directory)
                  throws java.io.IOException,
                         CVSException
Method Detail

addWorkingDirectoryListener

public void addWorkingDirectoryListener(allensoft.javacvs.client.event.WorkingDirectoryListener l)

removeWorkingDirectoryListener

public void removeWorkingDirectoryListener(allensoft.javacvs.client.event.WorkingDirectoryListener l)

hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


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.


getEntry

public Entry getEntry(java.lang.String sName)
Gets a Entry with the specified name.


hasEntries

public boolean hasEntries(EntryFilter filter,
                          boolean bRecursive)
                   throws java.io.IOException,
                          CVSException
Checks if this working directory has any 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.


getDirectoryEntries

public DirectoryEntry[] getDirectoryEntries(DirectoryEntryFilter 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.


getDirectoryEntries

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


getEntries

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


getEntries

public void getEntries(java.util.Collection entries,
                       EntryFilter filter,
                       boolean bRecursive)
                throws java.io.IOException,
                       CVSException
Gets the entries that the filter accepts and adds them to the supplied collection.


getEntries

public Entry[] getEntries(EntryFilter filter,
                          boolean bRecursive)
                   throws java.io.IOException,
                          CVSException

loadEntriesFile

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


updateFileEntry

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

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

boolean setStaticDirectory()
                     throws java.io.IOException

clearStaticDirectory

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.


getCheckinProgram

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

getUpdateProgram

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

addDirectoryEntry

void addDirectoryEntry(java.lang.String sName)
                 throws CVSException

reloadEntriesFile

private void reloadEntriesFile()
                        throws java.io.IOException,
                               CVSException
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.


synchWithFileSystem

public static void synchWithFileSystem()
                                throws java.io.IOException,
                                       CVSException
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

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


writeEntriesFiles

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. This is called by the client after every request is performed. It is also called when the VM shuts down.


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

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

getDirectory

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


getCVSFile

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

getEntriesFile

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


getRootFile

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


getRepositoryFile

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


readBaserevFile

void readBaserevFile(java.util.List files,
                     java.util.List revisions)
               throws java.io.IOException
Reads the current Baserev file in the CVS directory to determine the names and revisions of files being edited in this working directory. This is package protected because it should not be used by API users directly as this file is managed through the EditRequest and UneditRequest classes.


writeBaserevFile

void writeBaserevFile(java.util.List files,
                      java.util.List revisions)
                throws java.io.IOException
Writes the Baserev file describing the names of files being edited and their revisions.


readSingleLineFile

private static java.lang.String readSingleLineFile(java.io.File file)
                                            throws java.io.IOException
Reads the first line from the supplied file and returns it as a string.


fireReloadedEntries

private void fireReloadedEntries()

fireEntryAdded

private void fireEntryAdded(Entry entry)

fireEntryRemoved

private void fireEntryRemoved(Entry entry)