gate.versioning.cmdline
Class AbstractRepository

java.lang.Object
  extended by gate.versioning.cmdline.AbstractRepository
All Implemented Interfaces:
Repository
Direct Known Subclasses:
CvsRepository, SvnRepository

public abstract class AbstractRepository
extends Object
implements Repository

Abstract repository implementation. The public API of this class is documented on the Repository interface. Implementors control the behaviour of the methods here by overriding parameterisation methods like getCommandName(), or simply by providing their own replacement implementations of the Repository methods.

See Also:
Repository, CvsRepository, SvnRepository

Field Summary
protected  String commandOutput
          Output from repository command execution.
protected static boolean DEBUG
          Debugging messages.
protected  String nl
          Shorthand for newlines.
protected  String root
          The root or URL of the repository.
protected  String stderrOutput
          Stderr from repository command execution.
protected  String stdoutOutput
          Stdout from repository command execution.
protected  File workingDir
          The current working directory.
 
Constructor Summary
AbstractRepository()
          Construction.
 
Method Summary
 boolean add(String fileName)
          Add to the repository.
protected  String[] buildCommandArray(String fileName, String subCommand, String subCommandFlag)
          Calls buildCommandArray/4 with the no root parameter set false.
protected  String[] buildCommandArray(String fileName, String subCommand, String subCommandFlag, boolean noRoot)
          Build an array to pass to runtime.exec.
 boolean checkin(String fileName)
          Commit changes.
 boolean checkin(String fileName, String message)
          Commit changes.
 boolean checkout(String fileName)
          Check out a file, directory or module.
 boolean delete(String fileName)
          Delete from the repository.
 String diff(String fileName)
          Get the difference with the repository version.
abstract  String getCommandName()
          Name of the repository command to execute.
 String getCommandOutput()
          Get a string containing the stdout and stderr from the command execution.
 String getCommandStderr()
          Get a string containing the stderr from the command execution.
 String getCommandStdout()
          Get a string containing the stdout from the command execution.
protected abstract  List getPostCommand(String fileName, boolean noRoot)
          Specifies what (if anything) should follow the subcommand.
protected abstract  List getPreCommand()
          Specifies what (if anything) should precede the subcommand.
static Repository getRepository(String root)
          Return a class that supports the given root specifier.
 String getRoot()
          The root / URL of the repository
 void init()
          Validate parameters.
protected  boolean runCommand(String[] command)
          Run a command, wait for termination and report status
protected  boolean runCommand(String[] command, boolean allowExitOne)
          Run a command, wait for termination and report status.
 void setRoot(String root)
          The root / URL of the repository
 void setWorkingDir(File workingDir)
          The working directory for repository actions
 String status(String fileName)
          Status.
 boolean update(String fileName)
          Update.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gate.versioning.cmdline.Repository
create, exists, importDir, isModified, isOutOfDate, isUnknown
 

Field Detail

root

protected String root
The root or URL of the repository.


workingDir

protected File workingDir
The current working directory.


DEBUG

protected static boolean DEBUG
Debugging messages.


commandOutput

protected String commandOutput
Output from repository command execution.


stdoutOutput

protected String stdoutOutput
Stdout from repository command execution.


stderrOutput

protected String stderrOutput
Stderr from repository command execution.


nl

protected String nl
Shorthand for newlines.

Constructor Detail

AbstractRepository

public AbstractRepository()
Construction.

Method Detail

getCommandName

public abstract String getCommandName()
Name of the repository command to execute.

Specified by:
getCommandName in interface Repository

init

public void init()
          throws gate.util.GateException
Validate parameters.

Specified by:
init in interface Repository
Throws:
gate.util.GateException

setRoot

public void setRoot(String root)
The root / URL of the repository

Specified by:
setRoot in interface Repository

getRoot

public String getRoot()
The root / URL of the repository

Specified by:
getRoot in interface Repository

setWorkingDir

public void setWorkingDir(File workingDir)
The working directory for repository actions

Specified by:
setWorkingDir in interface Repository

checkout

public boolean checkout(String fileName)
Check out a file, directory or module.

Specified by:
checkout in interface Repository
Parameters:
fileName - the file or directory to work on (should be relative to the repository's working directory, and use "/" as a path separator).
Returns:
boolean representing success or failure.

getPreCommand

protected abstract List getPreCommand()
Specifies what (if anything) should precede the subcommand.


getPostCommand

protected abstract List getPostCommand(String fileName,
                                       boolean noRoot)
Specifies what (if anything) should follow the subcommand.


buildCommandArray

protected String[] buildCommandArray(String fileName,
                                     String subCommand,
                                     String subCommandFlag)
Calls buildCommandArray/4 with the no root parameter set false.


buildCommandArray

protected String[] buildCommandArray(String fileName,
                                     String subCommand,
                                     String subCommandFlag,
                                     boolean noRoot)
Build an array to pass to runtime.exec. Behaviour modified by getCommandName(), getPreCommand() and getPostCommand(java.lang.String, boolean).

Parameters:
fileName - the file or directory to work on (should be relative to the repository's working directory, and use "/" as a path separator).
subCommand - the repository command, e.g. "co".
subCommandFlag - a flag for the command (e.g. "-d"), or null.
noRoot - when true indicates that the root isn't necessary for this command.

checkin

public boolean checkin(String fileName)
Commit changes. A default message is used.

Specified by:
checkin in interface Repository
Parameters:
fileName - the file or directory to work on (should be relative to the repository's working directory, and use "/" as a path separator).
Returns:
boolean representing success or failure.

checkin

public boolean checkin(String fileName,
                       String message)
Commit changes.

Specified by:
checkin in interface Repository
Parameters:
fileName - the file or directory to work on (should be relative to the repository's working directory, and use "/" as a path separator).
message - a commit message.
Returns:
boolean representing success or failure.

update

public boolean update(String fileName)
Update.

Specified by:
update in interface Repository
Parameters:
fileName - the file or directory to work on (should be relative to the repository's working directory, and use "/" as a path separator).
Returns:
boolean representing success or failure.

status

public String status(String fileName)
Status.

Specified by:
status in interface Repository
Parameters:
fileName - the file or directory to work on (should be relative to the repository's working directory, and use "/" as a path separator).
Returns:
String giving status ouput.

delete

public boolean delete(String fileName)
Delete from the repository.

Specified by:
delete in interface Repository
Parameters:
fileName - the file or directory to work on (should be relative to the repository's working directory, and use "/" as a path separator).
Returns:
boolean representing success or failure.

add

public boolean add(String fileName)
Add to the repository.

Specified by:
add in interface Repository
Parameters:
fileName - the file or directory to work on (should be relative to the repository's working directory, and use "/" as a path separator).
Returns:
boolean representing success or failure.

diff

public String diff(String fileName)
Get the difference with the repository version.

Specified by:
diff in interface Repository
Parameters:
fileName - the file or directory to work on (should be relative to the repository's working directory, and use "/" as a path separator).
Returns:
a string containing the difference, or "" for no difference, or null for error.

getCommandStdout

public String getCommandStdout()
Get a string containing the stdout from the command execution.

Specified by:
getCommandStdout in interface Repository

getCommandStderr

public String getCommandStderr()
Get a string containing the stderr from the command execution.

Specified by:
getCommandStderr in interface Repository

getCommandOutput

public String getCommandOutput()
Get a string containing the stdout and stderr from the command execution.

Specified by:
getCommandOutput in interface Repository

getRepository

public static Repository getRepository(String root)
Return a class that supports the given root specifier. The type of the class is a guess based on characteristics of the string (e.g. URLs are for SVN).

Parameters:
root - root specifier for the desired Repository implementor.
Returns:
a non-initialised Repository object

runCommand

protected boolean runCommand(String[] command)
Run a command, wait for termination and report status


runCommand

protected boolean runCommand(String[] command,
                             boolean allowExitOne)
Run a command, wait for termination and report status.

Parameters:
allowExitOne - accept a command return value of 1 as success (e.g. for cvs diff).