we are using the Java and Inventory Discoverer to get complete models of our java projects.
For the further processing in our tools we use the following code to load the _java2kdm.xmi model and to ensure that all referenced submodels are resolved:
ResourceSet resourceSet = new ResourceSetImpl();
EObject model = ModelUtils.load(java2kdmModelFile, resourceSet);
However, the ModelUtils class comes from the EMFCompare project and as you can see we need to explicitly reference the packages to ensure they are registered before the model is loaded.
Is there any recommended way or any utility offered by MoDisco to simplify loading java2kdm models and resolving all references? Could you provide some example code how this can be done better and even without any dependency on EMF Compare?
Trying your code, I end up with nullpointer exception because no resource is returned.
I veryfied that the filepath is valid. Btw. I am trying to run this code within a unit test. So would this be an issue?
Ok, I found the issue.
Due to the JUnit test environment (not a Junit Plugin Test), there was no default resource factory registered.
Explicitly registering the resource solved the problem:
// load the required meta class packages
// register the factory to be able to read xmi files
// load the resource and resolve the proxies
ResourceSet rs = new ResourceSetImpl();
Resource r = rs.createResource(URI.createFileURI(java2kdmModelFile.getAbsolutePath()));