Package org.eclipse.team.core.mapping
Class DelegatingStorageMerger
- java.lang.Object
-
- org.eclipse.team.core.mapping.DelegatingStorageMerger
-
- All Implemented Interfaces:
IStorageMerger
public class DelegatingStorageMerger extends Object implements IStorageMerger
This storage merger delegates to the appropriate merger or returns a conflict if no merger is available or if a merge was not possible.The target storage is used to look for an appropriate merger. If the target is an
IFile
, the content type of the file is used. Otherwise, theIContentTypeManager
is used to find an appropriate content type. If an appropriate merger is not found, a status containing theCONFLICT
is returned.Clients may use this class directly or subclass it.
- Since:
- 3.4
-
-
Field Summary
-
Fields inherited from interface org.eclipse.team.core.mapping.IStorageMerger
CONFLICT, INTERNAL_ERROR, OK, UNSUPPORTED_ENCODING
-
-
Constructor Summary
Constructors Constructor Description DelegatingStorageMerger()
Default no-arg constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canMergeWithoutAncestor()
Return whether this merger can merge the two contributors without an ancestor.protected IStorageMerger
createDelegateMerger(IStorage target)
Create a merger for the given storage or returnnull
if an appropriate merger could not be created.static IStorageMerger
createTextMerger()
Return the storage merger associated with theIContentTypeManager.CT_TEXT
content type.static IContentType
getContentType(IStorage target)
A helper method that finds the content type for the given storage or returnsnull
if a content type cannot be found.static String
getExtension(String name)
Helper method for returning the extension of a file namestatic IStorageMerger
getInstance()
Helper method that returns a singleton instance that can be used to merge twoIStorage
instances.protected int
getType(IStorage target)
Return the Team content type associated with the given target.IStatus
merge(OutputStream output, String outputEncoding, IStorage ancestor, IStorage target, IStorage other, IProgressMonitor monitor)
Performs a merge operation on the given storage instances and writes the merge result to the output stream.
-
-
-
Method Detail
-
createTextMerger
public static IStorageMerger createTextMerger()
Return the storage merger associated with theIContentTypeManager.CT_TEXT
content type.- Returns:
- the storage merger associated with the
IContentTypeManager.CT_TEXT
content type
-
getInstance
public static IStorageMerger getInstance()
Helper method that returns a singleton instance that can be used to merge twoIStorage
instances.- Returns:
- a storage merger that delegates the merge based on the type of the target storage.
-
merge
public IStatus merge(OutputStream output, String outputEncoding, IStorage ancestor, IStorage target, IStorage other, IProgressMonitor monitor) throws CoreException
Description copied from interface:IStorageMerger
Performs a merge operation on the given storage instances and writes the merge result to the output stream. On success a statusIStatus.OK
is returned, on error a statusIStatus.ERROR
. If the merge operation cannot deal with conflicts, the code of the error status has the valueIStreamMerger.CONFLICT
. For text oriented mergers the encoding for the input and output is honored if they implementIEncodedStorage
. It is the responsibility of callers to close the output stream.The provided ancestor may be
null
if this merger returnstrue
fromIStorageMerger.canMergeWithoutAncestor()
.- Specified by:
merge
in interfaceIStorageMerger
- Parameters:
output
- the byte stream to which the merge result is written; the merger will not close the streamoutputEncoding
- the encoding to use when writing to the output streamancestor
- the storage from which the common ancestor is readtarget
- the storage containing the target of the mergeother
- the storage containing the target of the mergemonitor
- reports progress of the merge operation- Returns:
- returns the completion status of the operation
- Throws:
CoreException
- if an error occurs
-
createDelegateMerger
protected IStorageMerger createDelegateMerger(IStorage target) throws CoreException
Create a merger for the given storage or returnnull
if an appropriate merger could not be created. This method is called bymerge(OutputStream, String, IStorage, IStorage, IStorage, IProgressMonitor)
to create the merger to which the merge should be delegated.- Parameters:
target
- the storage that contains the target contents of the merge.- Returns:
- a merger for the given storage or
null
- Throws:
CoreException
- no merger found
-
getType
protected int getType(IStorage target)
Return the Team content type associated with the given target.- Parameters:
target
- the storage that contains the target contents for the merge.- Returns:
- the Team content type associated with the given target
- See Also:
Team.getFileContentManager()
,IFileContentManager.getType(IStorage)
-
getExtension
public static String getExtension(String name)
Helper method for returning the extension of a file name- Parameters:
name
- the file name- Returns:
- the extension of the file name or
null
if the file name does not have an extension
-
getContentType
public static IContentType getContentType(IStorage target) throws CoreException
A helper method that finds the content type for the given storage or returnsnull
if a content type cannot be found. Any exceptions that occur when trying to determine the content type are propagated.- Parameters:
target
- the storage that contains the target contents of the merge.- Returns:
- the content type of the storage or
null
- Throws:
CoreException
- if an exception occurs
-
canMergeWithoutAncestor
public boolean canMergeWithoutAncestor()
Description copied from interface:IStorageMerger
Return whether this merger can merge the two contributors without an ancestor. This is typically not possible but may be for some file types (for instances, files that contain a timestamp based list of events).- Specified by:
canMergeWithoutAncestor
in interfaceIStorageMerger
- Returns:
- whether this merger can merge the two contributors without an ancestor
-
-