Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » Using a custom merger
Using a custom merger [message #1752725] Thu, 26 January 2017 14:48 Go to next message
Vlad Acretoaie is currently offline Vlad AcretoaieFriend
Messages: 95
Registered: April 2014
Member
Hi,

I have a question which I have already posted in another thread (https://www.eclipse.org/forums/index.php?t=msg&th=1083264&goto=1752586&#msg_1752586), but I think it is actually a separate issue that deserves its own thread.

How can I programmatically configure EMF Compare to use a custom merger that I wrote instead of the default org.eclipse.emf.compare.egit.internal.merge.RecursiveModelMerger? I checked the developer documentation, but the section describing how to provide custom mergers is still under construction.

I tried adding the following extension to my plugin.xml, but with no effect:

   <extension point="org.eclipse.egit.core.mergeStrategy">
      <strategy      
            class="com.myplugin.MyMergeStrategy"
            label="My Merge Strategy">
      </strategy>
   </extension>


Best regards,
Vlad

[Updated on: Thu, 26 January 2017 14:54]

Report message to a moderator

Re: Using a custom merger [message #1752780 is a reply to message #1752725] Fri, 27 January 2017 08:52 Go to previous messageGo to next message
Philip Langer is currently offline Philip LangerFriend
Messages: 99
Registered: March 2015
Location: Vienna, Austria
Member

Hi Vlad,

your extension looks fine to me. Does your class extend org.eclipse.jgit.merge.ThreeWayMergeStrategy? What do you mean with "has no effect"? Does it show up in the Team -> Git -> Synchronize preferences page? Your merge strategy won't be active automatically. You have to enable it using this preference.

Hope this helps!

Best wishes,

Philip

--
Philip Langer

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/


--
Philip Langer

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: Using a custom merger [message #1752784 is a reply to message #1752780] Fri, 27 January 2017 09:18 Go to previous messageGo to next message
Vlad Acretoaie is currently offline Vlad AcretoaieFriend
Messages: 95
Registered: April 2014
Member
Hi Philip,

Thank you for your answer.

My class extends org.eclipse.emf.compare.egit.internal.merge.StrategyResolve, which in turns extends org.eclipse.jgit.merge.ThreeWayMergeStrategy.

However, I am not able to access the Team -> Git -> Synchronize preferences page, since I am using EMF Compare as part of my own Eclipse-based application which does not have this menu. I think I will have to find out how to set this preference programmatically. Do you have any suggestion as to how I could do this?

Thanks again!

Vlad

[Updated on: Fri, 27 January 2017 09:21]

Report message to a moderator

Re: Using a custom merger [message #1752801 is a reply to message #1752784] Fri, 27 January 2017 13:14 Go to previous messageGo to next message
Vlad Acretoaie is currently offline Vlad AcretoaieFriend
Messages: 95
Registered: April 2014
Member
Hi again,

I think I found out how to set my strategy as the default merge strategy. I added the following line to the start() method of my plugin Activator:

InstanceScope.INSTANCE.getNode(org.eclipse.egit.core.Activator.getPluginId()).put(GitCorePreferences.core_preferredMergeStrategy, "my strategy");


I also overrode the getName() method of my strategy, so that it returns "my plugin". Everything seems to be fine, and I can check at runtime that core_preferredMergeStrategy points to my strategy.

However, one thing I noticed is that, even without any customization (when the RecursiveModelMerger is set as the preferred merger), EMF Compare does not invoke any methods from org.eclipse.emf.compare.egit.internal.merge.RecursiveModelMerger or any of its superclasses. I placed breakpoints in all the methods of these classes, and none of them is hit while using EMF Compare to perform conflict resolution. So at the moment I don't really understand what the role of these mergers is, or how EMF Compare can perform a merge without invoking them.

To make things even more confusing, I can see that another extension point (org.eclipse.emf.compare.rcp.merger) allows specifying custom mergers from a completely different class hierarchy, i.e. mergers extending org.eclipse.emf.compare.merge.AbstractMerger. So it seems like the term "merger" is used with two different meanings in EMF Compare. Is my understanding correct?

Best regards,
Vlad

[Updated on: Fri, 27 January 2017 13:59]

Report message to a moderator

Re: Using a custom merger [message #1752879 is a reply to message #1752801] Mon, 30 January 2017 09:07 Go to previous messageGo to next message
Philip Langer is currently offline Philip LangerFriend
Messages: 99
Registered: March 2015
Location: Vienna, Austria
Member

Hi Vlad,

you could also pre-configure your merge strategy in the plugin_customization.ini of your RCP:
org.eclipse.egit.core/core_preferredMergeStrategy=<your-merge-strategy-id>

Quote:
To make things even more confusing, I can see that another extension point (org.eclipse.emf.compare.rcp.merger) allows specifying custom mergers from a completely different class hierarchy, i.e. mergers extending org.eclipse.emf.compare.merge.AbstractMerger. So it seems like the term "merger" is used with two different meanings in EMF Compare. Is my understanding correct?


Yes, on the one hand, there are EGit merge strategies, which are responsible to merge resource mappings (this is what you just did), and on the other hand, there are mergers, which are responsible for merging single model differences (such as a reference change, etc.).

Hope that helps,

Philip

--
Philip Langer

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/


--
Philip Langer

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: Using a custom merger [message #1752895 is a reply to message #1752879] Mon, 30 January 2017 12:03 Go to previous messageGo to next message
Vlad Acretoaie is currently offline Vlad AcretoaieFriend
Messages: 95
Registered: April 2014
Member
Hi Philip,

Thank you for the answer and the explanation.

I tried configuring the merge strategy in my plugin_customization.ini, and it seems to be working the same as my existing customization.

However, my merge strategy is still never invoked during conflict resolution, and as far as I can tell no merge strategy at all is invoked.
Do you know why this is the case? If no merge strategy is invoked, how can EMF Compare actually perform a merge (it does indeed merge my models)?

Best regards,
Vlad
Re: Using a custom merger [message #1752978 is a reply to message #1752895] Tue, 31 January 2017 14:48 Go to previous message
Philip Langer is currently offline Philip LangerFriend
Messages: 99
Registered: March 2015
Location: Vienna, Austria
Member

Hi Vlad,

the merge strategy is called by EGit to handle EMF model resource mappings (that is a bunch of related EMF resources). It'll be called during the merge, rebase, and cherry-pick and has to find out if there is a conflict and, if no, merge the resource mapping. If there is a conflict, this is reported back and, depending on a configuration, it'll also do a pre-merge or not.

The merge strategy is not involved in the conflict resolution at all. To resolve a conflict, the user opens a merge tool, resolves the conflict, and stages the conflicting file after resolution. EMF Compare provides an own action to open the EMF Model Merge tool, where users can interactively resolve conflicts by accepting or rejecting conflicting changes. This will invoke the "other" mergers, depending on which kind of difference is accepted or rejected.

Hope this clarifies the process a bit.

Best wishes,

Philip

--
Philip Langer

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/


--
Philip Langer

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Previous Topic:Behaviour of "Previous Difference" and "Next Difference" buttons for tree expand
Next Topic:Problems using the UI compare with dynamic Ecore models
Goto Forum:
  


Current Time: Fri Apr 19 20:08:49 GMT 2024

Powered by FUDForum. Page generated in 0.03751 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top