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
Hello,

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: 1902
Registered: July 2009
Senior Member
Hi Yasser,

You should directly depend on org.eclipse.emf.compare.edit and re-use the IItemXXXProviders that we use ourselves to display the UI. Basically, look at org.eclipse.emf.compare.provider.IItemDescriptionProvider 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);
System.out.println(itemDescriptionProvider.getDescription(attributeChange);


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

Regards,

Laurent Goubet
Obeo

[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: Fri Nov 08 11:54:11 GMT 2024

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

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

Back to the top