gate.versioning.svnkit
Class SandboxManager

java.lang.Object
  extended by gate.versioning.svnkit.SandboxManager

public class SandboxManager
extends Object

This class manages a set of Sandboxes. This is a Spring Bean and it is assumed that this will be a singleton. It ensures that there is never more than one Sandbox object for any given SVN-managed file tree, and it linearises operations on these objects. It is intended to be thread-safe. NOTE: this API assumes that its clients are friendly enough not to add a sandbox that is a subdirectory of another sandbox also being managed. If this rule is not followed then the results will be unpredictable!


Constructor Summary
SandboxManager()
           
 
Method Summary
 boolean addSandbox(File location, org.tmatesoft.svn.core.auth.ISVNAuthenticationManager authManager)
          Add a new Sandbox.
 boolean addSandbox(File location, String username, String password)
          Add a new Sandbox.
 void addSandboxes(List folderIds, String username, String password)
          This method adds a list of sandboxes to the sandboxMap.
 org.tmatesoft.svn.core.SVNURL createLocalRepository(File location)
          Create a new local SVN repository.
 void forgetSandbox(File sbDir)
          Forget a sandbox.
 File getConfigDir()
           
 Sandbox getSandbox(String id)
          Get a sandbox from its ID (canonical path to the directory tree).
 String getSandboxId(File sbDir)
          Generate an ID for a File that points to a sandbox tree on disk.
 List<Sandbox> getSandboxList()
          Get an (immutable) list of all known sandboxes.
 Map<String,Sandbox> getSandboxMap()
          Get an (immutable) map of all known sandboxes indexed by id.
 boolean isSandboxDir(File sbDir)
          Check that a File points to a valid sandbox on disk.
 void setConfigDir(File dir)
           
 void shutdown()
          Close all managed sandboxes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SandboxManager

public SandboxManager()
Method Detail

setConfigDir

public void setConfigDir(File dir)

getConfigDir

public File getConfigDir()

addSandbox

public boolean addSandbox(File location,
                          String username,
                          String password)
                   throws gate.util.GateException
Add a new Sandbox. This will be identified by the canonical form of the path to the directory tree. If a sandbox that is already recorded is added nothing is done and the method returns false.

Parameters:
location - a file pointing to the top-level directory of the sandbox on disk.
username - - for svn authentication
password - - for svn authentication
Returns:
boolean indicates if the new sandbox was added.
Throws:
gate.util.GateException - when the location doesn't exist or isn't under version control.

addSandbox

public boolean addSandbox(File location,
                          org.tmatesoft.svn.core.auth.ISVNAuthenticationManager authManager)
                   throws gate.util.GateException
Add a new Sandbox. This will be identified by the canonical form of the path to the directory tree. If a sandbox that is already recorded is added nothing is done and the method returns false.

Parameters:
location - a file pointing to the top-level directory of the sandbox on disk.
authManager - - custom authentication manager for svn authentication
Returns:
boolean indicates if the new sandbox was added.
Throws:
gate.util.GateException - when the location doesn't exist or isn't under version control.

getSandboxId

public String getSandboxId(File sbDir)
                    throws gate.util.GateRuntimeException
Generate an ID for a File that points to a sandbox tree on disk. This ID is the directory's canonical path.

Throws:
gate.util.GateRuntimeException - when the location won't resolve to a canonical path.

isSandboxDir

public boolean isSandboxDir(File sbDir)
Check that a File points to a valid sandbox on disk.

Parameters:
sbDir - a file pointing to the top-level directory of the sandbox on disk.
Returns:
boolean indicates if the sandbox is valid.

forgetSandbox

public void forgetSandbox(File sbDir)
Forget a sandbox.

Parameters:
sbDir - a file pointing to the top-level directory of the sandbox on disk (it is assumed to be a File).

getSandbox

public Sandbox getSandbox(String id)
Get a sandbox from its ID (canonical path to the directory tree).

Parameters:
id - the ID of the Sandbox (if you only have the location of the sandbox on disk, use getSandboxId(File) and pass the result to this method.

getSandboxList

public List<Sandbox> getSandboxList()
Get an (immutable) list of all known sandboxes.


getSandboxMap

public Map<String,Sandbox> getSandboxMap()
Get an (immutable) map of all known sandboxes indexed by id.


createLocalRepository

public org.tmatesoft.svn.core.SVNURL createLocalRepository(File location)
                                                    throws org.tmatesoft.svn.core.SVNException
Create a new local SVN repository. This includes three directories "trunk", "tags" and "branches" as per normal convention.

Returns:
SVNURL the URL of the new repository.
Throws:
org.tmatesoft.svn.core.SVNException

addSandboxes

public void addSandboxes(List folderIds,
                         String username,
                         String password)
This method adds a list of sandboxes to the sandboxMap. In case of any exception, the runtime exception is thrown and since the method is called when starting the application, the process of starting the application will be terminated. // TODO why does this throw runtime exception?! We assume that all sandboxes are for users with same username/password on svn.

Parameters:
folderIds - the list of full paths of the sandboxes to be added.
username - - for svn authentication
password - - for svn authentication

shutdown

public void shutdown()
Close all managed sandboxes.