I need to have always up to date content of some file in my program. I've created an EMF resource set.
Because resourceSet.getResource(resourceURI, true)
takes a lot of time to complete I store the resource set in a static field, so files can be cached.
I.e. once resourceSet.getResource(resourceURI, true)
is called for some URI the file is cached in resourceSet
.
The problem is that resourceSet
doesn't update it's cache automatically:
I.e.:
resourceSet.getResource(resourceURI, true);
// delete resourceURI from file system
// Here I expect null, but old version of the file is returned
resourceSet.getResource(resourceURI, true);
How to force resourceSet
to update cache if needed?
I'm using org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
, but probably I need another version of ResourceSet
that takes modification stamps into account?
Two things: first if you want to reload the resource, you'll have to call
As EMF is not requiring Eclipse in any way the
Resource
andResourceSet
classes are not the same as the Eclipse workspaceIResource
subclasses, which mean changing a file on the file system will not cause the EMF Resources to be reloaded.It's pretty easy to do though, have a look on the
XxxxEditor
EMF generated for you, the class instantiate aIResourceChangeListener
which will receive deltas from the Eclipse workspace when a file is being modified. The generated listener process these deltas by reloading the resources.