我想比较两个符合给定 ecore 元模型的模型,如下所示:
public void compare() {
URI uri1 = URI.createFileURI("file1.xmi");
URI uri2 = URI.createFileURI("file2.xmi");
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
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();
// Let's merge every single diff
IMerger.Registry mergerRegistry = new IMerger.RegistryImpl();
IBatchMerger merger = new BatchMerger(mergerRegistry);
merger.copyAllLeftToRight(differences, new BasicMonitor());
}
如果我运行此代码,我会收到错误Package with uri '/uri/of/the/package' not found
,这是元模型的 URI。我尝试通过右键单击然后注册ecore模型Register EPackages
,但没有成功。我在做什么错?`我如何注册包(我更喜欢静态但动态也可以)。