Print Structural differences to Console [message #1696990] |
Sat, 30 May 2015 05:42  |
Eclipse User |
|
|
|
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 10:20  |
Eclipse User |
|
|
|
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 10:21] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04542 seconds