javaemf-compare

EMF Compare programatically for local history of uml file


I am trying to compare a uml file with its local history. Is it possible to do it programatically?


Solution

  • Yes, but you will have to find the proper history revision to compare with yourself.

    See org.eclipse.core.resources.IFile.getHistory(IProgressMonitor) for info on how to retrieve the local history of a given file. You will then need to load these revisions as EMF Resources for use by EMF Compare.

    Something like the following should get you started:

    String uri = "platform:/resource/project/path/to/file.ext";
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri));
    IFileState[] states = file.getHistory(new NullProgressMonitor());
    if (states.length > 0) {
        IFileState lastFromHistory = states[0];
        ResourceSet set = new ResourceSetImpl();
        Resource res = set.createResource(URI.createURI(uri));
        res.load(lastFromHistory.getContents(), Collections.emptyMap());
    }