Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF Diff/Merge » Cant get the merge to work
Cant get the merge to work [message #1754929] Fri, 24 February 2017 08:01 Go to next message
Simon BBBBBBB is currently offline Simon BBBBBBBFriend
Messages: 63
Registered: March 2015
Member
Hello there,

i try to merge two of my models. my first model is a normal EMF-Model without references to other ecore-models.

http://imgur.com/WSmfuRo

then i create a new file and try to merge all the differences with the following code:

		LocalDateTime localDateTime = LocalDateTime.now();
		String uhrZeitDatum = "" + localDateTime.getYear() + localDateTime.getMonth() + localDateTime.getDayOfMonth()
				+ localDateTime.getMinute() + localDateTime.getSecond();

		URI referenceURI = URI.createPlatformResourceURI("Test/core.ecore", true);
		URI targetURI = URI.createPlatformResourceURI("Test/" + uhrZeitDatum + ".ecore", true);

		ResourceSet resourceSet = new ResourceSetImpl();
		Resource referenceResource = resourceSet.getResource(referenceURI, true);
		Resource targetResource = resourceSet.createResource(targetURI);
		try {
			targetResource.save(Collections.EMPTY_MAP);
		} catch (IOException e) {
			e.printStackTrace();
		}

		// Instantiate the scopes to compare
		IEditableModelScope referenceScope = new FragmentedModelScope(referenceResource, false);
		IEditableModelScope targetScope = new FragmentedModelScope(targetResource, false);
		IComparison comparison = new EComparisonImpl(targetScope, referenceScope);

		ConfigurableMatchPolicy configurableMatchPolicy = new ConfigurableMatchPolicy();
		ConfigurableDiffPolicy configurableDiffPolicy = new ConfigurableDiffPolicy();
		DefaultMergePolicy defaultMergePolicy = new DefaultMergePolicy();
		comparison.compute(configurableMatchPolicy, configurableDiffPolicy, defaultMergePolicy, null);

		List<IDifference> differences = comparison.getDifferences(Role.REFERENCE);
		comparison.merge(differences, Role.TARGET, true, null);


the result is the following

http://imgur.com/KL2A4Ln

so the supertypes get duplicated. i tryed to change the merge to the following:

		for (IDifference iDifference : differences) {
			if (iDifference instanceof IElementPresence) {
				IElementPresence elementPresenceDifference = (IElementPresence) iDifference;
				elementPresenceDifference.mergeTo(Role.TARGET);
			} else if (iDifference instanceof IReferenceValuePresence) {
				IReferenceValuePresence referenceValuePresence = (IReferenceValuePresence) iDifference;
				referenceValuePresence.mergeTo(Role.TARGET);
			} else if (iDifference instanceof IAttributeValuePresence) {
				IAttributeValuePresence attributeValuePresence = (IAttributeValuePresence) iDifference;
				attributeValuePresence.mergeTo(Role.TARGET);
			}
		}


And the result looks even more strange:

http://imgur.com/74Qfdxf

what am i doing wrong?

[Updated on: Fri, 24 February 2017 08:05]

Report message to a moderator

Re: Cant get the merge to work [message #1755065 is a reply to message #1754929] Mon, 27 February 2017 18:18 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 106
Registered: January 2012
Senior Member
Hello Simon,

You are doing nothing wrong, I could reproduce the issue. It is due to the fact that the behavior of the EClass::eSuperTypes reference is not like other references and must be treated as a specific case. The default comparison method does not handle this specific case because it preferentially targets EMF models (Ecore instance models) over EMF metamodels (Ecore models). Still, I can have a look and see how many such specific cases there are and possibly support them. Are you willing to open a Bugzilla entry? (On the EMF Diff/Merge wiki page, click Bugzilla then click the "File a new bug" link at the bottom of the page.)

Note that it is impossible to provide 100% reliable diff/merge algorithms for EMF metamodels because Ecore elements do not have unique identifiers (unless you provide IDs in another way, via an alternative serialization mechanism for example). You can use alternative, non-ID-based matching algorithms but they will not cover all possible cases, so there are situations where you would have to perform part of the "merge" by editing the model manually.
Re: Cant get the merge to work [message #1755066 is a reply to message #1754929] Mon, 27 February 2017 18:18 Go to previous messageGo to next message
Olivier Constant is currently offline Olivier ConstantFriend
Messages: 106
Registered: January 2012
Senior Member
Hello Simon,

You are doing nothing wrong, I could reproduce the issue. It is due to the fact that the behavior of the EClass::eSuperTypes reference is not like other references and must be treated as a specific case. The default comparison method does not handle this specific case because it preferentially targets EMF models (Ecore instance models) over EMF metamodels (Ecore models). Still, I can have a look and see how many such specific cases there are and possibly support them. Are you willing to open a Bugzilla entry? (On the EMF Diff/Merge wiki page, click Bugzilla then click the "File a new bug" link at the bottom of the page.)

Note that it is impossible to provide 100% reliable diff/merge algorithms for EMF metamodels because Ecore elements do not have unique identifiers (unless you provide IDs in another way, via an alternative serialization mechanism for example). You can use alternative, non-ID-based matching algorithms but they will not cover all possible cases, so there are situations where you would have to perform part of the "merge" by editing the model manually.
Re: Cant get the merge to work [message #1755143 is a reply to message #1755066] Tue, 28 February 2017 12:00 Go to previous message
Simon BBBBBBB is currently offline Simon BBBBBBBFriend
Messages: 63
Registered: March 2015
Member
Hello Oliver, thx for your response. i created a bugzilla entry: https://bugs.eclipse.org/bugs/show_bug.cgi?id=512806
Previous Topic:Cannot access the Javadoc
Next Topic:Use Ids as keys instead of Fragment path in bridgetraces
Goto Forum:
  


Current Time: Sat Apr 27 01:35:58 GMT 2024

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

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

Back to the top