org.eclipse.jgit.pgm
Class TextBuiltin

java.lang.Object
  extended by org.eclipse.jgit.pgm.TextBuiltin

public abstract class TextBuiltin
extends java.lang.Object

Abstract command which can be invoked from the command line.

Commands are configured with a single "current" repository and then the execute(String[]) method is invoked with the arguments that appear on the command line after the command name.

Command constructors should perform as little work as possible as they may be invoked very early during process loading, and the command may not execute even though it was constructed.


Field Summary
protected  RevWalk argWalk
          RevWalk used during command line parsing, if it was required.
protected  Repository db
          Git repository the command was invoked within.
protected  java.lang.String gitdir
          Directory supplied via --git-dir command line option.
protected  java.io.PrintWriter out
          Stream to output to, typically this is standard output.
 
Constructor Summary
TextBuiltin()
           
 
Method Summary
protected static Die die(java.lang.String why)
           
protected static Die die(java.lang.String why, java.lang.Throwable cause)
           
 void execute(java.lang.String[] args)
          Parse arguments and run this command.
 Repository getRepository()
           
protected  java.util.ResourceBundle getResourceBundle()
           
protected  void init(Repository repository, java.lang.String gitDir)
          Initialize the command to work with a repository.
protected  void parseArguments(java.lang.String[] args)
          Parses the command line arguments prior to running.
 void printUsageAndExit(CmdLineParser clp)
          Print the usage line
 void printUsageAndExit(java.lang.String message, CmdLineParser clp)
          Print an error message and the usage line
protected  boolean requiresRepository()
           
protected abstract  void run()
          Perform the actions of this command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.PrintWriter out
Stream to output to, typically this is standard output.


db

protected Repository db
Git repository the command was invoked within.


gitdir

protected java.lang.String gitdir
Directory supplied via --git-dir command line option.


argWalk

protected RevWalk argWalk
RevWalk used during command line parsing, if it was required.

Constructor Detail

TextBuiltin

public TextBuiltin()
Method Detail

requiresRepository

protected boolean requiresRepository()
Returns:
true if db/getRepository() is required.

init

protected void init(Repository repository,
                    java.lang.String gitDir)
Initialize the command to work with a repository.

Parameters:
repository - the opened repository that the command should work on.
gitDir - value of the --git-dir command line option, if repository is null.

execute

public final void execute(java.lang.String[] args)
                   throws java.lang.Exception
Parse arguments and run this command.

Parameters:
args - command line arguments passed after the command name.
Throws:
java.lang.Exception - an error occurred while processing the command. The main framework will catch the exception and print a message on standard error.

parseArguments

protected void parseArguments(java.lang.String[] args)
Parses the command line arguments prior to running.

This method should only be invoked by execute(String[]), prior to calling run(). The default implementation parses all arguments into this object's instance fields.

Parameters:
args - the arguments supplied on the command line, if any.

printUsageAndExit

public void printUsageAndExit(CmdLineParser clp)
Print the usage line

Parameters:
clp -

printUsageAndExit

public void printUsageAndExit(java.lang.String message,
                              CmdLineParser clp)
Print an error message and the usage line

Parameters:
message -
clp -

getResourceBundle

protected java.util.ResourceBundle getResourceBundle()
Returns:
the resource bundle that will be passed to args4j for purpose of string localization

run

protected abstract void run()
                     throws java.lang.Exception
Perform the actions of this command.

This method should only be invoked by execute(String[]).

Throws:
java.lang.Exception - an error occurred while processing the command. The main framework will catch the exception and print a message on standard error.

getRepository

public Repository getRepository()
Returns:
the repository this command accesses.

die

protected static Die die(java.lang.String why)
Parameters:
why - textual explanation
Returns:
a runtime exception the caller is expected to throw

die

protected static Die die(java.lang.String why,
                         java.lang.Throwable cause)
Parameters:
why - textual explanation
cause - why the command has failed.
Returns:
a runtime exception the caller is expected to throw


Copyright © 2011. All Rights Reserved.