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 17:19  |
Eclipse User |
|
|
|
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 17:19] by Moderator
|
|
| | |
Re: Trying to build EMF Compare [message #1268555 is a reply to message #1267201] |
Mon, 10 March 2014 13:03   |
Eclipse User |
|
|
|
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 13:05] by Moderator
|
|
| |
Re: Trying to build EMF Compare [message #1269376 is a reply to message #1268896] |
Tue, 11 March 2014 15:48   |
Eclipse User |
|
|
|
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 15:48] by Moderator
|
|
|
Re: Trying to build EMF Compare [message #1270153 is a reply to message #1269376] |
Wed, 12 March 2014 11:02   |
Eclipse User |
|
|
|
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 13:57   |
Eclipse User |
|
|
|
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 14:27] by Moderator
|
|
| | |
Goto Forum:
Current Time: Wed Jul 23 05:12:28 EDT 2025
Powered by FUDForum. Page generated in 0.27068 seconds
|