Skip to main content



      Home
Home » Modeling » Compare » How to compare UML models from code?
How to compare UML models from code? [message #1219673] Thu, 05 December 2013 05:59 Go to next message
Eclipse UserFriend
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 06:46 Go to previous messageGo to next message
Eclipse UserFriend
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 05:42 Go to previous messageGo to next message
Eclipse UserFriend
What do you mean by "the models aren't recognized as UML models". Would you provide us what makes you say this?
Re: How to compare UML models from code? [message #1222006 is a reply to message #1219681] Thu, 19 December 2013 05:53 Go to previous message
Eclipse UserFriend
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.
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: Wed Jul 23 16:20:22 EDT 2025

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

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

Back to the top