com.aragost.javahg.internals
Class AbstractCommand

java.lang.Object
  extended by com.aragost.javahg.internals.AbstractCommand
Direct Known Subclasses:
AddCommandFlags, AddRemoveCommandFlags, AnnotateCommandFlags, BackoutCommandFlags, BisectCommandFlags, BookmarksCommandFlags, BranchCommandFlags, BranchesCommandFlags, CatCommandFlags, CloneCommandFlags, CommitCommandFlags, CopyCommandFlags, DiffCommandFlags, ExportCommandFlags, GenericCommand, GraftCommandFlags, HeadsCommandFlags, ImportCommandFlags, IncomingCommandFlags, LocateCommandFlags, LogCommandFlags, ManifestCommandFlags, MergeCommandFlags, OutgoingCommandFlags, ParentsCommandFlags, PhaseCommandFlags, PullCommandFlags, PushCommandFlags, RemoveCommandFlags, RenameCommandFlags, ResolveCommandFlags, RevertCommandFlags, RollbackCommandFlags, RootCommandFlags, StatusCommandFlags, TagCommandFlags, TagsCommandFlags, UpdateCommandFlags, VersionCommandFlags

public abstract class AbstractCommand
extends Object

Base class for the command classes. Each Mercurial command (e.g., "log", "commit", etc) is mapped to a command class, which is a subclass of this class. The command classes will provide methods for setting command line flags and for actually executing the command. Concurrency: Instances of this class should be accessed only on a single thread. The only exception is cancel(). States: Normally: READY->QUEUED->RUNNING->READY. If cancelled: From READY, QUEUED, or RUNNING -> CANCELLING -> READY. If cancelled the executing thread will have a CancelledExecutionException thrown and state will be READY.


Nested Class Summary
static class AbstractCommand.State
           
 
Constructor Summary
protected AbstractCommand(Repository repository)
           
protected AbstractCommand(Repository repository, String commandName)
           
 
Method Summary
 void cancel()
          Cancel a running command.
protected  void clear()
           
 void cmdAppend(String option)
           
 void cmdAppend(String option, DateTime date)
           
 void cmdAppend(String option, int arg)
           
 void cmdAppend(String option, String arg)
           
 void cmdAppend(String option, String[] args)
           
protected  void doneHook()
          This method is called when the processing of a command is finished.
abstract  String getCommandName()
           
 String getErrorString()
           
 Repository getRepository()
           
 int getReturnCode()
           
protected  boolean isSuccessful()
          Check if the command ended with a zero return code.
protected  LineIterator launchIterator(String... args)
           
protected  HgInputStream launchStream(String... args)
          Launch the command and return stdout as a InputStream.
protected  String launchString(String... args)
          Launch the command and return stdout as a String.
 boolean needsInputLine()
           
 void reopenOutputChannelStream()
          Open the output stream again after sending input to the command server.
 void sendLine(String s)
          Send input line to command server in response to reading a block on the 'L' channel.
 String toString()
           
protected  void withDebugAndChangesetStyle()
           
protected  void withDebugFlag()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractCommand

protected AbstractCommand(Repository repository)

AbstractCommand

protected AbstractCommand(Repository repository,
                          String commandName)
Method Detail

getCommandName

public abstract String getCommandName()
Returns:
the name of this Mercurial command, i.e., "add", "log", etc

cmdAppend

public void cmdAppend(String option)

cmdAppend

public void cmdAppend(String option,
                      String arg)

cmdAppend

public void cmdAppend(String option,
                      String[] args)

cmdAppend

public void cmdAppend(String option,
                      int arg)

cmdAppend

public void cmdAppend(String option,
                      DateTime date)

launchString

protected final String launchString(String... args)
Launch the command and return stdout as a String.

Parameters:
args - extra command line arguments (optional).
Returns:
stdout as a String.
Throws:
IOException

launchStream

protected final HgInputStream launchStream(String... args)
Launch the command and return stdout as a InputStream.

Parameters:
args - extra command line arguments (optional).
Returns:
stdout stream

launchIterator

protected final LineIterator launchIterator(String... args)

reopenOutputChannelStream

public void reopenOutputChannelStream()
Open the output stream again after sending input to the command server. When the server alternates between sending output on the 'o' channel and reading input lines, the output channel will run dry several times. Call this method after sending input to the command server in response to reading from the 'L' channel. New output from the server will then appear on the output channel.


sendLine

public void sendLine(String s)
Send input line to command server in response to reading a block on the 'L' channel.

Parameters:
s - line of input.

needsInputLine

public boolean needsInputLine()
Returns:
true if we have read a 'L' channel from the server.

clear

protected void clear()

isSuccessful

protected boolean isSuccessful()
Check if the command ended with a zero return code. Subclasses can override this to accept other return codes as successful.

Returns:
true if the command ended successfully.

getErrorString

public String getErrorString()
Returns:
data read on the 'e' channel

getReturnCode

public int getReturnCode()
Returns:
the return code read from the 'r' channel

getRepository

public Repository getRepository()
Returns:
the Repository associated with this command.

toString

public String toString()
Overrides:
toString in class Object

withDebugAndChangesetStyle

protected void withDebugAndChangesetStyle()

withDebugFlag

protected void withDebugFlag()

cancel

public final void cancel()
Cancel a running command. May be called from a different thread. Returns immediately. The thread executing the command should return soon after with a CancelledExecutionException thrown.


doneHook

protected void doneHook()
This method is called when the processing of a command is finished. More precise it is called just after the 'r' channel is read

It can be overridden in subclasses.



Copyright © 2011-2013 aragost Trifork ag. All Rights Reserved.