Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » Print Structural differences to Console
Print Structural differences to Console [message #1696990] Sat, 30 May 2015 09:42 Go to next message
Yasser Khan is currently offline Yasser KhanFriend
Messages: 23
Registered: October 2011
Junior Member

1) i want to compare 2 uml models and print the structural differences on the console. Same as we see in 'Structural Differences' view of Eclipse.

For example,
13 change(s) in model
2 change(s) in package
<Activity> AC has been removed
<ForkNode> AF has been added

2) Ignore the UML tag <elementImport> in the comparison

My code is as follows:

public void compare(String expected, String actual){

URI expectedUri = URI.createFileURI(expected);
URI actualUri = URI.createFileURI(actual);

ResourceSet expectedResSet = new ResourceSetImpl();
ResourceSet actualResSet = new ResourceSetImpl();

Map<String, Object> factoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap();
factoryMap.put("uml", new UMLResourceFactoryImpl());

expectedResSet.getResource(expectedUri, true);
actualResSet.getResource(actualUri, true);

IComparisonScope scope = EMFCompare.createDefaultScope(expectedResSet, actualResSet);

Comparison comparison = EMFCompare.builder().build().compare(scope);
List<Diff> differences = comparison.getDifferences();

for(Diff d: differences)
System.err.println("d.getKind(): "+ d.getKind());
System.err.println("d.getMatch(): " + d.getMatch());
System.err.println("State: " + d.getState());

Please advise what changes I need to make to answer my above question.
Thank you

Re: Print Structural differences to Console [message #1697640 is a reply to message #1696990] Fri, 05 June 2015 14:20 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1897
Registered: July 2009
Senior Member
Hi Yasser,

You should directly depend on and re-use the IItemXXXProviders that we use ourselves to display the UI. Basically, look at and how you can use it. It should look a little like this:

AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
final IItemDescriptionProvider itemDescriptionProvider = (IItemDescriptionProvider) adapterFactory.adapt(attributeChange, IItemDescriptionProvider.class);

or you can take a look at the for something we used in unit tests to have a standalone console view of a comparison model.


Laurent Goubet

[Updated on: Fri, 05 June 2015 14:21]

Report message to a moderator

Previous Topic:Compare nodes with different parent hierarchy
Next Topic:Model Resolving step
Goto Forum:

Current Time: Wed Jun 29 10:43:49 GMT 2022

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

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

Back to the top