net.sf.statsvn.util
Class SvnDiffUtils

java.lang.Object
  extended by net.sf.statsvn.util.SvnDiffUtils
All Implemented Interfaces:
ISvnDiffProcessor
Direct Known Subclasses:
SvnKitDiff

public class SvnDiffUtils
extends java.lang.Object
implements ISvnDiffProcessor

Utilities class that manages calls to svn diff.

 

Field Summary
protected static java.lang.String BINARY_TYPE
           
protected static java.lang.String INDEX_MARKER
           
protected  ISvnProcessor processor
           
protected static java.lang.String PROPERTY_CHANGE
           
protected static java.lang.String PROPERTY_NAME
           
protected static int PROPERTY_NAME_LINE
           
static int RESULT_SIZE
           
 
Constructor Summary
SvnDiffUtils(ISvnProcessor processor)
          Invokes diffs using the svn diff command line.
 
Method Summary
protected  void appendResults(java.util.Vector answer, java.lang.String currFile, java.lang.StringBuffer sb)
          Append results to answer vector.
protected  ProcessUtils callSvnDiff(java.lang.String newRevNr)
          Calls svn diff on all files for given revision and revision-1.
protected  ProcessUtils callSvnDiff(java.lang.String oldRevNr, java.lang.String newRevNr, java.lang.String filename)
          Calls svn diff for the filename and revisions given.
 java.util.Vector getLineDiff(java.lang.String newRevNr)
          Returns line count differences for all files in a particular revision.
 int[] getLineDiff(java.lang.String oldRevNr, java.lang.String newRevNr, java.lang.String filename)
          Returns line count differences between two revisions of a file.
protected  ISvnProcessor getProcessor()
           
protected  boolean isBinaryErrorMessage(java.lang.String msg)
          Returns true if msg is an error message display that the file is binary.
protected  int[] parseDiff(net.sf.statcvs.util.LookaheadReader diffReader)
          Returns line count differences between two revisions of a file.
protected  void parseMultipleDiffStream(java.util.Vector answer, java.io.InputStream diffStream)
           
protected  int[] parseSingleDiffStream(java.io.InputStream diffStream)
           
protected  void verifyOutput(ProcessUtils pUtils)
          Verifies the process error stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESULT_SIZE

public static final int RESULT_SIZE
See Also:
Constant Field Values

PROPERTY_NAME_LINE

protected static final int PROPERTY_NAME_LINE
See Also:
Constant Field Values

PROPERTY_CHANGE

protected static final java.lang.String PROPERTY_CHANGE
See Also:
Constant Field Values

PROPERTY_NAME

protected static final java.lang.String PROPERTY_NAME
See Also:
Constant Field Values

BINARY_TYPE

protected static final java.lang.String BINARY_TYPE
See Also:
Constant Field Values

INDEX_MARKER

protected static final java.lang.String INDEX_MARKER
See Also:
Constant Field Values

processor

protected ISvnProcessor processor
Constructor Detail

SvnDiffUtils

public SvnDiffUtils(ISvnProcessor processor)
Invokes diffs using the svn diff command line.

Method Detail

getProcessor

protected ISvnProcessor getProcessor()

callSvnDiff

protected ProcessUtils callSvnDiff(java.lang.String oldRevNr,
                                   java.lang.String newRevNr,
                                   java.lang.String filename)
                            throws java.io.IOException
Calls svn diff for the filename and revisions given. Will use URL invocation, to ensure that we get diffs even for deleted files.

Throws:
java.io.IOException
Parameters:
oldRevNr - old revision number
newRevNr - new revision number
filename - filename.
Returns:
the InputStream related to the call. If the error steam is non-empty, will return the error stream instead of the default input stream.

callSvnDiff

protected ProcessUtils callSvnDiff(java.lang.String newRevNr)
                            throws java.io.IOException
Calls svn diff on all files for given revision and revision-1.

Throws:
java.io.IOException
Parameters:
newRevNr - revision number
Returns:
the InputStream related to the call. If the error steam is non-empty, will return the error stream instead of the default input stream.

getLineDiff

public int[] getLineDiff(java.lang.String oldRevNr,
                         java.lang.String newRevNr,
                         java.lang.String filename)
                  throws java.io.IOException,
                         BinaryDiffException
Description copied from interface: ISvnDiffProcessor
Returns line count differences between two revisions of a file.

Specified by:
getLineDiff in interface ISvnDiffProcessor
Throws:
java.io.IOException - problem parsing the stream
BinaryDiffException - if the error message is due to trying to diff binary files.
Parameters:
oldRevNr - old revision number
newRevNr - new revision number
filename - the filename
Returns:
A int[2] array of [lines added, lines removed] is returned.

parseSingleDiffStream

protected int[] parseSingleDiffStream(java.io.InputStream diffStream)
                               throws java.io.IOException,
                                      BinaryDiffException
Throws:
java.io.IOException
BinaryDiffException

verifyOutput

protected void verifyOutput(ProcessUtils pUtils)
                     throws java.io.IOException,
                            BinaryDiffException
Verifies the process error stream.

Throws:
java.io.IOException - problem parsing the stream
BinaryDiffException - if the error message is due to trying to diff binary files.
Parameters:
pUtils - the process call

getLineDiff

public java.util.Vector getLineDiff(java.lang.String newRevNr)
                             throws java.io.IOException,
                                    BinaryDiffException
Description copied from interface: ISvnDiffProcessor
Returns line count differences for all files in a particular revision.

Specified by:
getLineDiff in interface ISvnDiffProcessor
Throws:
java.io.IOException - problem parsing the stream
BinaryDiffException - if the error message is due to trying to diff binary files.
Parameters:
newRevNr - new revision number
Returns:
A vector of object[3] array of [filename, int[2](lines added, lines removed), isBinary] is returned.

parseMultipleDiffStream

protected void parseMultipleDiffStream(java.util.Vector answer,
                                       java.io.InputStream diffStream)
                                throws java.io.IOException
Throws:
java.io.IOException

appendResults

protected void appendResults(java.util.Vector answer,
                             java.lang.String currFile,
                             java.lang.StringBuffer sb)
                      throws java.io.IOException
Append results to answer vector.

Throws:
java.io.IOException - problem parsing the stream
BinaryDiffException - if the error message is due to trying to diff binary files.
Parameters:
answer - the current answers
currFile - the current file being added.
sb - the diff for this individual file.

isBinaryErrorMessage

protected boolean isBinaryErrorMessage(java.lang.String msg)
Returns true if msg is an error message display that the file is binary.

Parameters:
msg - the error message given by ProcessUtils.getErrorMessage();
Returns:
true if the file is binary

parseDiff

protected int[] parseDiff(net.sf.statcvs.util.LookaheadReader diffReader)
                   throws java.io.IOException,
                          BinaryDiffException
Returns line count differences between two revisions of a file.

Throws:
java.io.IOException - problem parsing the stream
BinaryDiffException
Parameters:
diffReader - the stream reader for svn diff
Returns:
A int[2] array of [lines added, lines removed] is returned.