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 |
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 |
|
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 |
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 |
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 #1269376 is a reply to message #1268896] |
Tue, 11 March 2014 19:48 |
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 |
|
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 |
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:
In that case, I think I have to create the following for 'MethodPlugin':
- interface MethodPlugin extends EPackage
- 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 |
|
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
|
|
| |
Goto Forum:
Current Time: Wed Apr 24 14:29:15 GMT 2024
Powered by FUDForum. Page generated in 0.04313 seconds
|