Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » compare two xml models?
compare two xml models? [message #925245] Thu, 27 September 2012 14:28 Go to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member
Hi,

Can someone give show me a code sample to compare two xml models? I need to look into, how to compare two xml models using EMF compare programatically.

Thanks
K
Re: compare two xml models? [message #926058 is a reply to message #925245] Fri, 28 September 2012 09:07 Go to previous messageGo to next message
Kosala Yapa is currently offline Kosala Yapa
Messages: 159
Registered: September 2010
Senior Member

File file1 = new File("EMFModelA.ecore");
File file2 = new File("EMFModelB.ecore");


//register XMI resource factory for all other extensions
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(
).put(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());

ResourceSet resourceSet = new ResourceSetImpl();


//Loading resources
EObject model1 = ModelUtils.load(file1,resourceSet);
EObject model2 = ModelUtils.load(file2,resourceSet);


//matching models
// MatchModel match = MatchService.doMatch(model1, model2, Collections.<String, Object> emptyMap());
MatchModel match = MatchService.doContentMatch(model1, model2, Collections.<String, Object> emptyMap());


//matching engine and matching
GenericMatchEngine eng = new GenericMatchEngine();
match = eng.contentMatch(model1, model2, Collections.<String, Object> emptyMap());

//Differencing models
DiffModel diff = DiffService.doDiff(match);

Iterator<DiffElement> it = diff.getDifferences().iterator();
while (it.hasNext()){
System.out.println(it.next());
}
Re: compare two xml models? [message #957520 is a reply to message #926058] Thu, 25 October 2012 09:29 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Hi Kosala,

The solution you give here is how to compare with EMF Compare 1 (you can find similar info on the FAQ). However, you should avoid loading the two versions of your model in the same resource set.

For EMF Compare 2, that would be :

File file1 = new File("EMFModelA.ecore");
File file2 = new File("EMFModelB.ecore");

//register XMI resource factory for all other extensions
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(
).put(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());

ResourceSet resourceSet1 = new ResourceSetImpl();
ResourceSet resourceSet2 = new ResourceSetImpl();

//Loading resources
EObject model1 = ModelUtils.load(file1, resourceSet1);
EObject model2 = ModelUtils.load(file2, resourceSet2);

IComparisonScope scope = EMFCompare.createDefaultScope(resourceSet1, resourceSet2);
Comparison result = EMFCompare.builder().build().compare(scope);

Iterator<Diff> it = result.getDifferences().iterator();
while (it.hasNext()){ 
System.out.println(it.next());
}
Re: compare two xml models? [message #1004023 is a reply to message #957520] Tue, 22 January 2013 13:00 Go to previous messageGo to next message
Pedro Dusso is currently offline Pedro Dusso
Messages: 3
Registered: January 2013
Junior Member
Where are located the classes EMFCompare, Comparison, IComparisonScope and Diff? I'm importing

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.*;
import org.eclipse.emf.compare.diff.*;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;

but still Eclipse cannot resolve them!
Re: compare two xml models? [message #1004578 is a reply to message #1004023] Wed, 23 January 2013 13:44 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Pedro,

You are using EMF Compare 1 (as given out with your "org.eclipse.emf.compare.diff.*" import). The four classes you mention are EMF Compare 2 classes.

Please see the EMF Compare FAQ for how to programmatically compare models. Either for the recommmanded EMF Compare 2 or the legacy EMF Compare 1.

Laurent Goubet
Obeo
Re: compare two xml models? [message #1006507 is a reply to message #1004578] Thu, 31 January 2013 14:29 Go to previous messageGo to next message
Pedro Dusso is currently offline Pedro Dusso
Messages: 3
Registered: January 2013
Junior Member
So, if I clone this git: git://git.eclipse.org/gitroot/emfcompare/org.eclipse.emf.compare.git
I can import the the org.eclipse.emf.compare, which is inside the plugin folder. Correct? Will I have to build this lib?
Re: compare two xml models? [message #1006632 is a reply to message #1006507] Fri, 01 February 2013 09:32 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Pedro,

Please elaborate upon what you are trying to achieve.

All you should have to do is install the already built library. Whether you want EMF Compare to be usable to compare EMF models in your Eclipse, you want to develop an Eclipse plug-in that augments or makes use of EMF Compare or you wish to use EMF Compare from your standalone application.

Cloning the git repository containing the source code of EMF Compare is only necessary if you wish to develop patches or contributions to EMF Compare.

Follow the Installation instructions in order to install EMF Compare in Eclipse. Once done, the jars will simply be available to you. The will be located in your Eclipse "<installation directory>/plugins" folders ... but that is only relevant if you wish to develop a standalone application. Otherwise you'll never have to meddle with their location on disk.

Laurent Goubet
Obeo
Previous Topic:Using EMF Compare to Compare Other Files
Next Topic:Building EMF Compare with Guava Libraries
Goto Forum:
  


Current Time: Sun Oct 26 08:41:47 GMT 2014

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

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