问题
I have written one eclipse osgi plugin that runs cleanup and formatting actions on java files present in eclipse project. Some thing like:
- Run batch file that has eclipse command
- It open's eclipse editor
- Loads eclipse project passed as parameter in batch command
- Run cleanup and formatting actions
- Closes eclipse
Now my problem is I need to track the files that has been changed by this action. I am performing cleanup changes using cleanUpsAction
that runs as thread over multiple files and forks further. It returns void.
There is IResourceChangeListener
which I tried as well but I am not able to get name of resources that are changed. I get object of IResourceChangeEvent
but details of resource are not coming out of it, it always return project name when I prints IResourceChangeEvent.getSource()
.
回答1:
There are multiple levels of object in the IResourceChangeEvent
at the top is usually the project or the workspace and below that are folders and files. These are represented by IResourceDelta
objects.
To see all of them first get the top level IResourceDelta
from the event:
IResourceChangeEvent event = ... the event
IResourceDelta delta = event.getDelta();
and then use an IResourceDeltaVisitor
to visit each resource in the delta:
delta.accept(visitor);
where visitor
is a class implementing IResourceDeltaVisitor
.
There is just one method in the visitor:
public boolean visit(IResourceDelta delta) throws CoreException
which is given a delta for each resource.
IResourceDelta.getResource
gives you the changed resource. IResourceDelta.getKind
tells you the type of change (add, delete, change).
来源:https://stackoverflow.com/questions/42562305/track-files-changes-done-by-eclipse-cleanup-programmatically