Package com.nomagic.magicdraw.merge
Class MergeUtil
java.lang.Object
com.nomagic.magicdraw.merge.CompareUtil
com.nomagic.magicdraw.merge.MergeUtil
Allows using MagicDraw project merge to merge projects.
See Open API manual for the usage details.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidacceptChanges(Set<Change> preferredChanges, Set<Change> changes) Accept given changes.static booleanapplyChanges(ProjectDifference difference, ErrorHandler<Exception> errorHandler) Apply project difference changes.static voidcallInEsiIDSupport(Runnable runnable) Executes runnable wheregetID(BaseElement)uses twc server element id when comparing elements.static ProjectDescriptorcreateRemoteAncestorDescriptorForMerge(Project targetProject, long mergeFrom, boolean lock) Creates remote ancestor descriptor for merge.static Collection<String>Get element IDs of all elements in given project.getConflictingChanges(Set<Change> changes) Filter only changes that has conflicts.static BaseElementgetElementByID(Project project, String id) Return element from project with given simple or derived id.static StringgetID(BaseElement be) Returns element ID, or project id combination with element id for TWC elements.static booleanmerge(Project targetProject, ProjectDescriptor source, ProjectDescriptor ancestor, ConflictResolution conflictResolution, ErrorHandler<Exception> errorHandler, Optimization optimization) Merge projects.static voidregisterCreatedElement(String compositeID, ModelObject element) Register created element by composite id.static voidReset known composite id support.static voidReset known created elements.static voidsetChangeState(Change change, ChangeState state) Set change state.static booleanshowMergeGUI(ProjectDifference projectDifference) Show merge GUI.Methods inherited from class com.nomagic.magicdraw.merge.CompareUtil
compareProjects, getDifference, getDifference, restore, showDifferenceGUI
-
Constructor Details
-
MergeUtil
public MergeUtil()
-
-
Method Details
-
acceptChanges
public static void acceptChanges(Set<Change> preferredChanges, Set<Change> changes) throws IllegalStateException Accept given changes. If change fromchangesconflicts with change frompreferredChanges, it is rejected. The result is - allpreferredChangesare accepted, and only not conflictingchangesare accepted.- Parameters:
preferredChanges- accept all these changes.changes- accept only not conflicting changes.- Throws:
IllegalStateException- if merge is not available
-
showMergeGUI
public static boolean showMergeGUI(ProjectDifference projectDifference) throws IllegalStateException Show merge GUI.- Parameters:
projectDifference- project difference.- Returns:
- true proceed merging, false - cancel merging.
- Throws:
IllegalStateException- if merge is not available
-
applyChanges
public static boolean applyChanges(ProjectDifference difference, ErrorHandler<Exception> errorHandler) throws IllegalStateException Apply project difference changes.- Parameters:
difference- project difference.errorHandler- invoked if error occurs.- Returns:
- true if changes applied, otherwise - false.
- Throws:
IllegalStateException- if merge is not available, if changes applied on not latest teamwork project version, or trying to merge local project with teamwork project.
-
getConflictingChanges
Filter only changes that has conflicts.- Parameters:
changes- changes to filter.- Returns:
- conflicting changes.
-
setChangeState
Set change state. Dependent, required and conflicting changes states are also modified (if modification is required).- Parameters:
change- change to modify state.state- new change state.
-
merge
public static boolean merge(Project targetProject, ProjectDescriptor source, @CheckForNull ProjectDescriptor ancestor, @CheckForNull ConflictResolution conflictResolution, ErrorHandler<Exception> errorHandler, Optimization optimization) throws IllegalStateException Merge projects.- Parameters:
targetProject- target project.source- source project descriptor.ancestor- ancestor project descriptor. Pass value only for 3-way merge (nullfor 2-way merge).conflictResolution- define conflict resolution. Used only in 3-way merge.nullis treated asConflictResolution.TARGET_PREFERRED.errorHandler- invoked if error occurs. Allows to perform custom action.optimization- optimization option.- Returns:
trueif project merged, otherwisefalse.- Throws:
IllegalStateException- if merge is not available, if changes applied on not latest teamwork project version, or trying to merge local project with teamwork project.
-
getID
Returns element ID, or project id combination with element id for TWC elements.- Parameters:
be- base element- Returns:
- element ID
-
getElementByID
Return element from project with given simple or derived id. For esi project checks project for found element - if there are more than one project with same local id.- Parameters:
project- projectid- simple or derived id- Returns:
- element or null
-
getAllIDS
Get element IDs of all elements in given project.- Parameters:
project- project- Returns:
- element IDs
-
resetCompositeIDSupportCreatedElements
public static void resetCompositeIDSupportCreatedElements()Reset known created elements. -
resetCompositeIDSupport
public static void resetCompositeIDSupport()Reset known composite id support. -
callInEsiIDSupport
Executes runnable wheregetID(BaseElement)uses twc server element id when comparing elements.- Parameters:
runnable- runnable to execute
-
registerCreatedElement
Register created element by composite id. Composite id may contain information that element is in module, but in ancestor such module is still not used. When element is registered it can be found by provided composite id.- Parameters:
compositeID- composite id.element- created element.
-
createRemoteAncestorDescriptorForMerge
@CheckForNull public static ProjectDescriptor createRemoteAncestorDescriptorForMerge(Project targetProject, long mergeFrom, boolean lock) Creates remote ancestor descriptor for merge.- Parameters:
targetProject- target project.mergeFrom- source version.lock- should decomposition lock be taken.- Returns:
- created descriptor or null.
-