Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » How to compare UML models from code?
How to compare UML models from code? [message #1219673] Thu, 05 December 2013 10:59 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 59
Registered: August 2013
Member
Hi

Here is a code based on documentation:
URI uri1 = URI.createFileURI("model/ReferenceModel1.uml");
URI uri2 = URI.createFileURI("model/ReferenceModel2.uml");

UMLResourcesUtil.initResourceFactoryRegistry(Resource.Factory.Registry.INSTANCE);
        
ResourceSet resourceSet1 = new ResourceSetImpl();
ResourceSet resourceSet2 = new ResourceSetImpl();

resourceSet1.getResource(uri1, true);
resourceSet2.getResource(uri2, true);

IComparisonScope scope = new DefaultComparisonScope(resourceSet1, resourceSet2, null);
Comparison comparison = EMFCompare.builder().build().compare(scope);

List<Diff> differences = comparison.getDifferences();
for (Diff diff : differences) {
    System.out.println(diff);
}

The problem is that the models aren't recognized as UML models. And so comparator finds too much differences. When I compare the models in Eclipse using EMF Comparator GUI it finds only one actual difference.
Re: How to compare UML models from code? [message #1219681 is a reply to message #1219673] Thu, 05 December 2013 11:46 Go to previous messageGo to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 59
Registered: August 2013
Member
I tried to initalize UMLPostProcessor but nothing is changed:
Builder builder = EMFCompare.builder();
final IPostProcessor.Descriptor.Registry<String> postProcessorRegistry =
    new PostProcessorDescriptorRegistryImpl<String>();
BasicPostProcessorDescriptorImpl post = new BasicPostProcessorDescriptorImpl(
    new UMLPostProcessor(),
    Pattern.compile("http://www.eclipse.org/uml2/\\d\\.\\d\\.\\d/UML"),
    null);
postProcessorRegistry.put(UMLPostProcessor.class.getName(), post);
builder.setPostProcessorRegistry(postProcessorRegistry);
Comparison comparison = builder.build().compare(scope);

Also Eclipse shows a warning:
Discouraged access: The type UMLPostProcessor is not accessible due to restriction on required library
Re: How to compare UML models from code? [message #1222004 is a reply to message #1219673] Thu, 19 December 2013 10:42 Go to previous messageGo to next message
Mikael Barbero is currently offline Mikael BarberoFriend
Messages: 55
Registered: July 2009
Member
What do you mean by "the models aren't recognized as UML models". Would you provide us what makes you say this?

Best regards,

Mikael Barbero
Obeo
Re: How to compare UML models from code? [message #1222006 is a reply to message #1219681] Thu, 19 December 2013 10:53 Go to previous message
Mikael Barbero is currently offline Mikael BarberoFriend
Messages: 55
Registered: July 2009
Member
The initialization of the UMLPostProcessor is definitely needed to handle UML properly and you seem to do it well.

The discourage access is actually normal. The UMLPostProcessor is not yet public API.

About the differences in the number of differences found in the UI and programmatically, you have to be aware that the UI is hidding some changes for you by default. See http://wiki.eclipse.org/EMF_Compare/User_Guide#Filtering_Differences

When comparing UML models, there is an additional filter available.

Your code should report as many differences as the UI with all filters deactivated.


Best regards,

Mikael Barbero
Obeo
Previous Topic:[Bug?] Compare will not work with certan implementation of EStore
Next Topic:How to compare two "feature model" with EMF Compare
Goto Forum:
  


Current Time: Thu Dec 18 05:50:14 GMT 2014

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

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