Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » Trying to build EMF Compare(I want to use it programmatically too.)
Trying to build EMF Compare [message #1266026] Thu, 06 March 2014 22:19 Go to next message
Felipe González is currently offline Felipe González
Messages: 10
Registered: March 2014
Junior Member
Hello,

I was able to download EMF Compare through 'Install new software > ...", but I want to use it programmatically. I cloned the project from github and builded it successfully, although the tests didn't.

Anyway, I created a new Java Project on Eclipse (aka myProject) and I copy-pasted the test from the package "org.eclipse.emf.compare.tests.match" to reproduce it, but errors related to dependencies came up. I decided to import EMF Compare and add the emf.compare project to the build Path of myProject.

In the process of setting up emf.compare I imported the jars required but one error remains:
The type org.eclipse.swt.layout.GridData cannot be resolved. It is indirectly referenced from required .class files

And for myProject I have the following error:
The type org.eclipse.emf.common.util.TreeIterator cannot be resolved. It is indirectly referenced from required .class files

Do I keep adding jars? I think did something wrong when I tried to set up EMF Compare to use it programmatically, but I don't know what. Any help is appreciated.

Regards,
Felipe.

[Updated on: Thu, 06 March 2014 22:19]

Report message to a moderator

Re: Trying to build EMF Compare [message #1266277 is a reply to message #1266026] Fri, 07 March 2014 07:57 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Felipe,

This will all depend on what you wish to do with EMF Compare, but if you only need to compare models programmatically without displaying our UI, all you need to import from the git repository is the project "org.eclipse.emf.compare". This is enough to give you access to the comparison API.

If you need to compare and display our UI through your own actions, then you need to create an RCP application at least : our UI is not standalone and depends on Eclipse compare.

If you are "adding jars" then you probably are fully standalone and do not wish to use Eclipse or an RCP app for your comparison. Otherwise, you should be developping a plug-in project and adding your dependencies through the MANIFEST.MF instead of using plain jars.

Laurent Goubet
Obeo
Re: Trying to build EMF Compare [message #1267201 is a reply to message #1266277] Sat, 08 March 2014 16:41 Go to previous messageGo to next message
Felipe González is currently offline Felipe González
Messages: 10
Registered: March 2014
Junior Member
Laurent,

Thank you for your help. I imported the project "org.eclipse.emf.compare" to my workspace and make a .jar from it. Afterwards I added to the Java Bulid Path as a Library. I copied some random tests and it worked so far. Did I do it correctly?

I have a custom metamodel and my models are instances of it. I need to compare two models programmatically and print only the differences, like the operation "Compare With > Each Other" in the context menu. There's any test/resource to start with?

Regards,
Felipe.

[Updated on: Sat, 08 March 2014 16:43]

Report message to a moderator

Re: Trying to build EMF Compare [message #1268555 is a reply to message #1267201] Mon, 10 March 2014 17:03 Go to previous messageGo to next message
Felipe González is currently offline Felipe González
Messages: 10
Registered: March 2014
Junior Member
Hello again.

I worked on a couple of tests and finding some examples posted by sbegaudeau (http://stackoverflow.com/questions/9386348/emf-register-ecore-meta-model-programmatically/9389901#9389901 ) in stackOverflow and I have this:

public Comparison compare() {
		
	// register globally the Ecore Resource Factory to the ".ecore" extension
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
	ResourceSet rs = new ResourceSetImpl();
	final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(rs.getPackageRegistry());
	rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);

	URI modelURI = URI.createFileURI("processes/ spem.ecore");
	Resource r = rs.getResource(modelURI, true);
	EObject eObject = r.getContents().get(0);
	if (eObject instanceof EPackage) {
		EPackage p = (EPackage)eObject;
		rs.getPackageRegistry().put(p.getNsURI(), p);
	}
		
	// Register the factory
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
		
	// Load the two input models
	ResourceSet resourceSet1 = new ResourceSetImpl();
	ResourceSet resourceSet2 = new ResourceSetImpl();
	URI uri1 = URI.createFileURI("processes/ A.xmi");
	URI uri2 = URI.createFileURI("processes/ B.xmi");
	resourceSet1.getResource(uri1, true);
	resourceSet2.getResource(uri2, true);
	    
	// Configure EMF Compare
	EMFCompare comparator = EMFCompare.builder().build();
	// Compare the two models
	IComparisonScope scope = new DefaultComparisonScope(resourceSet1, resourceSet2, null);
	return comparator.compare(scope);
}


I tried to load the .ecore file as the link said without success. The spem.ecore file has a eSubpackage named MethodPlugin, but this error shows:
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http: //spem/1.0/MethodPlugin' not found. (file:///Users/felipegmch/Documents/workspace/CompareProcess/processes/A.xmi, 2, 327)


I also tried the method I_get_a_PackageNotFoundException described in the wiki FAQ ( https://wiki.eclipse.org/EMF-FAQ#I_get_a_PackageNotFoundException:_e.g..2C_.22Package_with_uri_.27http:.2F.2Fcom.example.company.ecore.27_not_found..22_What_do_I_need_to_do.3F ), but when I tried:
EPackage.Registry.INSTANCE.put(companyPackage.getNsURI(), companyPackage);

I don't know how to create the instance companyPackage.

I'm feeling a little loss. I appreciate any help.

Regards,
Felipe.

[Updated on: Mon, 10 March 2014 17:05]

Report message to a moderator

Re: Trying to build EMF Compare [message #1268896 is a reply to message #1268555] Tue, 11 March 2014 05:30 Go to previous messageGo to next message
Felipe González is currently offline Felipe González
Messages: 10
Registered: March 2014
Junior Member
I forgot to show the structure of the metamodel, here is a snipet of 'spem.ecore', which is a subset of spem defined by me:

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
	name="spem" nsURI="http://spem/1.0" nsPrefix="spem">
	<eSubpackages name="MethodPlugin" nsURI="http://spem/1.0/MethodPlugin" nsPrefix="methodPlugin">
		<eClassifiers xsi:type="ecore:EClass" name="MethodLibrary"
			eSuperTypes="#//Core/spemElement #//ManagedContent/DescribableElement">
			<eAnnotations source="exeed">
				<details key="classIcon" value="methodlibrary" />
			</eAnnotations>
			<eStructuralFeatures xsi:type="ecore:EReference"
				name="predefinedConfiguration" upperBound="-1" eType="#//MethodPlugin/MethodConfiguration" containment="true" />
			<eStructuralFeatures xsi:type="ecore:EReference"
				name="ownedMethodPlugin" upperBound="-1" eType="#//MethodPlugin/MethodPlugin" containment="true" />
		</eClassifiers>
...

The exception says that the package with the uri: 'http://spem/1.0/MethodPlugin' wasn't found, although that's the attribute's name for the eSubpackage showed above.

I hope to express my question clearly this time: to compare programmatically two models (with .xmi extension) which are instances of a custom metamodel (spem.ecore), do I have to register the metamodel or do any other action? I have followed the documentation and some tests, but I cannot find anything to help me with this case. Any help is appreciated.

Regards,
Felipe.
Re: Trying to build EMF Compare [message #1269376 is a reply to message #1268896] Tue, 11 March 2014 19:48 Go to previous messageGo to next message
Felipe González is currently offline Felipe González
Messages: 10
Registered: March 2014
Junior Member
I think I know what to do, but not how to do it.

My metamodel has other EPackages on it, but the exception states that 'Package with uri 'http: //spem/1.0/MethodPlugin' not found' so the inner EPackages doesn't register automatically.

I tried the following:

public Comparison compare(String path1, String path2) {
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
	ResourceSet rs = new ResourceSetImpl();
	final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(rs.getPackageRegistry());
	rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, extendedMetaData);

	URI modelURI = URI.createFileURI("processes/spem.ecore");
	Resource r = rs.getResource(modelURI, true);
	EObject eObject = r.getContents().get(0);
		
	if (eObject instanceof EPackage) {
		EPackage p = (EPackage)eObject;
		rs.getPackageRegistry().put(p.getNsURI(), p);

                EList<EPackage> sub = p.getESubpackages();
		for (EPackage package : sub) {	
			rs.getPackageRegistry().put(package.getNsURI(), package);
		}
	}
	EMFCompare comparator = EMFCompare.builder().build();
	IComparisonScope scope = new DefaultComparisonScope(getResource(path1), getResource(path2), r);
	return comparator.compare(scope);
}


I tried to put the inner EPackages in the ResourceSet as the first EPackage without success. Any help is appreciated.
Regards,
Felipe.

[Updated on: Tue, 11 March 2014 19:48]

Report message to a moderator

Re: Trying to build EMF Compare [message #1270153 is a reply to message #1269376] Wed, 12 March 2014 15:02 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Felipe,

Creating metamodels with nested EPackage is not recommended overall as it can lead to a number of issues such as this one.

Whatever the case, you will need to register all of them manually, and you cannot use an iteration over the metamodel to do it, since the generated "XyzPackage" is not the same as the "EPackage" you have in the model.

Basically, this "might" suffice, though I doubt it :
rs.getPackageRegistry().put(SpemPackage.eNS_URI, SpemPackage.eINSTANCE);


You'll probably need to add this (if there is a package that get generated for subpackages, I don't really know since that is something we avoid, precisely to avoid these errors) :
rs.getPackageRegistry().put(MethodPluginPackage.eNS_URI, MethodPluginPackage.eINSTANCE);


Laurent Goubet
Obeo
Re: Trying to build EMF Compare [message #1270225 is a reply to message #1270153] Wed, 12 March 2014 17:57 Go to previous messageGo to next message
Felipe González is currently offline Felipe González
Messages: 10
Registered: March 2014
Junior Member
Laurent,

I tried the code
rs.getPackageRegistry().put(SpemPackage.eNS_URI, SpemPackage.eINSTANCE);
but the 'SpemPackage' cannot be resolved to a type. Correct me if I'm wrong, but do I have to extend an EPackage for each of my subpackages?

My metamodel is structured as it follows: index.php/fa/17724/0/

In that case, I think I have to create the following for 'MethodPlugin':

  1. interface MethodPlugin extends EPackage
  2. class MethodPluginImpl extends EPackage implements MethodPlugin


And so on for every subpackage just like 'ComparePackage' and 'ComparePackageImpl' both located in the 'org.eclipse.emf.compare.impl package', and finally register them like this:
rs.getPackageRegistry().put(MethodPluginPackage.eNS_URI, MethodPluginPackage.eINSTANCE);


Am I correct?

Edit: Inspecting the way that 'ComparePackage' I tried the following without success:
String mpURI = "http://spem/1.0/MethodPlugin";
EPackage mp = (EPackage)EPackage.Registry.INSTANCE.get(mpURI);
rs.getPackageRegistry().put(mpURI, mp);


Regards,
Felipe.

[Updated on: Wed, 12 March 2014 18:27]

Report message to a moderator

Re: Trying to build EMF Compare [message #1270645 is a reply to message #1270225] Thu, 13 March 2014 09:12 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Felipe,

Before even trying advanced usage such as using EMF in a standalone environment, please look at how to create and generate your metamodel with EMF. After a very quick survey of this one, I think it should be enough to get you started. You need to follow steps 3.4 to 4.3 at the very least.

Once you've generated your metamodel code, it should become clear to you what 'SpemPackage' should be and how it comes to exist.

Laurent Goubet
Obeo
Re: Trying to build EMF Compare [message #1271308 is a reply to message #1270645] Fri, 14 March 2014 19:52 Go to previous message
Felipe González is currently offline Felipe González
Messages: 10
Registered: March 2014
Junior Member
Thank you Laurent, I will check out the tutorial.
I will post my findings afterwards.

Regards,
Felipe.
Previous Topic:Invalid link in EMF Compare developer guide
Next Topic:Export Comparison
Goto Forum:
  


Current Time: Thu Oct 30 23:47:23 GMT 2014

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

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