com.microsoft.tfs.core.util.diffmerge
Class ThreeWayMerge

java.lang.Object
  extended by com.microsoft.tfs.core.util.diffmerge.ThreeWayMerge

public final class ThreeWayMerge
extends java.lang.Object

Encapsulates a three-way-merge operation, supporting internal and external merge methods.

Since:
TEE-SDK-10.1
Thread-safety:
thread-compatible

Constructor Summary
ThreeWayMerge()
          Creates a ThreeWayMerge that uses default configuration.
ThreeWayMerge(java.lang.String overrideMergedFileEndOfLine)
          Creates a ThreeWayMerge that always uses the given end-of-line character sequence in the output file, or the default configuration if the parameter is null.
 
Method Summary
 com.microsoft.tfs.util.process.ProcessRunner beginExternalMerge(Conflict conflict, ExternalTool tool, com.microsoft.tfs.util.process.ProcessFinishedHandler finishedHandler, java.io.OutputStream capturedStandardOutput, java.io.OutputStream capturedStandardError)
          Merges the content that would resolve the given conflict via an external tool the user has configured.
 boolean doInternalMerge(Conflict conflict, boolean onlyCountConflicts)
          Merges the content that would resolve the given conflict.
 boolean endExternalMerge(com.microsoft.tfs.util.process.ProcessRunner mergeProcess)
          Completes the external merge that was started by beginExternalMerge (and represented by the given mergeProcess).
 FileEncoding getBaseFileEncoding()
           
 java.lang.String getBaseFileLabel()
           
 java.lang.String getBaseFileName()
           
 FileEncoding getIntermediateMergeEncoding()
          Returns the file encoding that should be used in the intermediate merge step.
 FileEncoding getMergedFileEncoding()
           
 java.lang.String getMergedFileLabel()
           
 java.lang.String getMergedFileName()
           
 FileEncoding getModifiedFileEncoding()
           
 FileEncoding getOriginalFileEncoding()
           
 java.lang.String getTheirFileLabel()
           
 java.lang.String getTheirFileName()
           
 java.lang.String getYourFileLabel()
           
 java.lang.String getYourFileName()
           
 void setBaseFileEncoding(FileEncoding encoding)
           
 void setBaseFileLabel(java.lang.String baseFileLabel)
           
 void setBaseFileName(java.lang.String file)
           
 void setIntermediateMergeEncoding(FileEncoding encoding)
          Sets the file encoding that will be used for the intermediate merge step.
 void setMergedFileEncoding(FileEncoding encoding)
           
 void setMergedFileLabel(java.lang.String mergedFileLabel)
           
 void setMergedFileName(java.lang.String file)
           
 void setModifiedFileEncoding(FileEncoding encoding)
           
 void setOriginalFileEncoding(FileEncoding encoding)
           
 void setTheirFileLabel(java.lang.String theirFileLabel)
           
 void setTheirFileName(java.lang.String file)
           
 void setYourFileLabel(java.lang.String yourFileLabel)
           
 void setYourFileName(java.lang.String file)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreeWayMerge

public ThreeWayMerge()
Creates a ThreeWayMerge that uses default configuration.


ThreeWayMerge

public ThreeWayMerge(java.lang.String overrideMergedFileEndOfLine)
Creates a ThreeWayMerge that always uses the given end-of-line character sequence in the output file, or the default configuration if the parameter is null.

Parameters:
overrideMergedFileEndOfLine - the end-of-line character sequence to use when writing the merged file, or null to use the default (detected) end-of-line character sequence.
Method Detail

setBaseFileName

public void setBaseFileName(java.lang.String file)

getBaseFileName

public java.lang.String getBaseFileName()

setTheirFileName

public void setTheirFileName(java.lang.String file)

getTheirFileName

public java.lang.String getTheirFileName()

setYourFileName

public void setYourFileName(java.lang.String file)

getYourFileName

public java.lang.String getYourFileName()

setMergedFileName

public void setMergedFileName(java.lang.String file)

getMergedFileName

public java.lang.String getMergedFileName()

getBaseFileLabel

public java.lang.String getBaseFileLabel()

getMergedFileLabel

public java.lang.String getMergedFileLabel()

getTheirFileLabel

public java.lang.String getTheirFileLabel()

getYourFileLabel

public java.lang.String getYourFileLabel()

setBaseFileLabel

public void setBaseFileLabel(java.lang.String baseFileLabel)

setMergedFileLabel

public void setMergedFileLabel(java.lang.String mergedFileLabel)

setTheirFileLabel

public void setTheirFileLabel(java.lang.String theirFileLabel)

setYourFileLabel

public void setYourFileLabel(java.lang.String yourFileLabel)

setBaseFileEncoding

public void setBaseFileEncoding(FileEncoding encoding)

getBaseFileEncoding

public FileEncoding getBaseFileEncoding()

setOriginalFileEncoding

public void setOriginalFileEncoding(FileEncoding encoding)

getOriginalFileEncoding

public FileEncoding getOriginalFileEncoding()

setModifiedFileEncoding

public void setModifiedFileEncoding(FileEncoding encoding)

getModifiedFileEncoding

public FileEncoding getModifiedFileEncoding()

setMergedFileEncoding

public void setMergedFileEncoding(FileEncoding encoding)

getMergedFileEncoding

public FileEncoding getMergedFileEncoding()

setIntermediateMergeEncoding

public void setIntermediateMergeEncoding(FileEncoding encoding)
Sets the file encoding that will be used for the intermediate merge step.

Parameters:
encoding -

getIntermediateMergeEncoding

public FileEncoding getIntermediateMergeEncoding()
Returns the file encoding that should be used in the intermediate merge step.

Returns:
The FileEncoding to use.

beginExternalMerge

public com.microsoft.tfs.util.process.ProcessRunner beginExternalMerge(Conflict conflict,
                                                                       ExternalTool tool,
                                                                       com.microsoft.tfs.util.process.ProcessFinishedHandler finishedHandler,
                                                                       java.io.OutputStream capturedStandardOutput,
                                                                       java.io.OutputStream capturedStandardError)
                                                                throws java.io.IOException,
                                                                       ExternalToolException
Merges the content that would resolve the given conflict via an external tool the user has configured. If the merge cannot happen (conflicts in the files), false is returned and no merged file is written. The conflict object is modified to include the conflicts found and result output.

For the state of the external merge process (whether it has completed normally, with error, still running), pass a Process

Parameters:
conflict - the conflict to merge content for.
tool - the merge tool to use (must not be null)
finishedHandler - an event handler whose methods are invoked when the process runner reaches one of its terminal states. The caller would normally implement the handler to call ExternalRunner.endMerge(ProcessRunner, String) when the runner reaches any terminal state. May be null if no state information is desired via the handler.
capturedStandardOutput - a stream to capture the text written by the child process to its standard output stream. Pass null if you don't want this output.

See the warning in ProcessRunner's Javadoc about deadlock.

capturedStandardError - a stream to capture the text written by the child process to its standard error stream. Pass null if you don't want this output.

See the warning in ProcessRunner's Javadoc about deadlock.

Returns:
the process runner that represents the running external merge tool.
Throws:
java.io.IOException - if an error occurred creating the merge output file before the merge tool was invoked.
ExternalToolException - if the configured merge command or arguments string caused a problem creating the merge tool.

endExternalMerge

public boolean endExternalMerge(com.microsoft.tfs.util.process.ProcessRunner mergeProcess)
Completes the external merge that was started by beginExternalMerge (and represented by the given mergeProcess). This method will block until the external merge tool has completed and returned an exit code.

Parameters:
mergeProcess - the merge process to complete (if null, false is returned).
Returns:
true if the merge result file was created, false if there was an error or no file was created.

doInternalMerge

public boolean doInternalMerge(Conflict conflict,
                               boolean onlyCountConflicts)
Merges the content that would resolve the given conflict. If the merge cannot happen (conflicts in the files), false is returned and no merged file is written. The conflict object is modified to include the conflicts found and result output.

Parameters:
conflict - the conflict to merge content for.
onlyCountConflicts - if true, no merge output will result, only conflicts are counted (and written to the conflict parameter's MergeSummary).
Returns:
true if no conflicts were found and the merge result file was created.
Throws:
CodePageMapping.UnknownCodePageException - if one of the input code pages or the output code pages cannot be converted to a Charset.


© 2015 Microsoft. All rights reserved.