Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » Programmatically "merge without deletions"
Programmatically "merge without deletions" [message #1393101] Thu, 03 July 2014 08:35 Go to next message
Cioran Naroic is currently offline Cioran NaroicFriend
Messages: 18
Registered: December 2013
Junior Member
Hello everyone,

I would like to use EMF/Compare programmatically to "merge" two models (in my case, Ecore models). By "merge", I mean actually adding (or merging if classes already exist) all classes/datatypes/enums/features/operations of one Ecore model into another one, without removing anything from the base Ecore model.

However, this is not the default behavior in Compare, as some elements may be removed from the base model if they don't get matched by elements of the other model.

I tried some things, such as discarding all non-ADD diff elements (thus preventing deletions): (this is Xtend code, but I'm sure you'll get it Wink)

val EPackage pkg1 = ...
val EPackage pkg2 = ...

val scope = new DefaultComparisonScope(pkg1, pkg2, null)
val comparison = EMFCompare.builder.build.compare(scope)

val diffs = comparison.differences
diffs.filter[
    kind != DifferenceKind.ADD
    && !requires.exists[r | r.kind == DifferenceKind.ADD]
].forEach[
    discard
]

val mergerRegistry = IMerger.RegistryImpl.createStandaloneInstance
val merger = new BatchMerger(mergerRegistry)
merger.copyAllLeftToRight(diffs, null)


However, this does not meet the expected behavior, e.g. new datatypes are not added into the base model, etc.

Is there any way I can "properly" implement this behavior? I cannot find the appropriate filter/merger for such purpose. Alternatively, do you have some ideas on how I should filter my diffs in order to meet the expected behavior?

Thank you,
Re: Programmatically "merge without deletions" [message #1393189 is a reply to message #1393101] Thu, 03 July 2014 11:42 Go to previous messageGo to next message
Mikael Barbero is currently offline Mikael BarberoFriend
Messages: 55
Registered: July 2009
Member
Hi Cioran,

I don't understand why you want to discard the changes that are not "additions". You could only merge those additions, and you will get your result:

val diffs = comparison.differences.filter[kind == DifferenceKind.ADD].toList
val mergerRegistry = IMerger.RegistryImpl.createStandaloneInstance
val merger = new BatchMerger(mergerRegistry)
merger.copyAllLeftToRight(diffs, null)


Hope this helps.


Best regards,

Mikael Barbero
Obeo
Re: Programmatically "merge without deletions" [message #1393322 is a reply to message #1393189] Thu, 03 July 2014 16:01 Go to previous message
Cioran Naroic is currently offline Cioran NaroicFriend
Messages: 18
Registered: December 2013
Junior Member
The problem is that some ADD differences depends on other differences that are not ADD-typed.

So I need some kind of transitive closure on all diff objects required by any ADD-typed difference in order to get the expected result. Am I wrong?
Previous Topic:Default Comparison Scope in v3.1.0
Next Topic:Customization and Team support
Goto Forum:
  


Current Time: Mon Jan 22 22:35:28 GMT 2018

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

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