以编程方式跟踪由eclipse清理完成的文件更改 [英] Track files changes done by eclipse cleanup programmatically
问题描述
- 运行具有eclipse命令的批处理文件
- 它打开的eclipse编辑器
-
- 加载在批处理命令中作为参数传递的eclipse项目
- 运行清理和格式化操作
- 关闭eclipse
现在我的问题是我需要跟踪已经被这个动作改变的文件。我正在执行清理更改,使用 cleanUpsAction
作为多个文件的线程运行,并进一步分叉。它返回void。
我尝试了 IResourceChangeListener
,但是我无法获取更改的资源名称。我收到 IResourceChangeEvent
的对象,但资源的细节没有出来,它总是返回项目名称,当我打印 IResourceChangeEvent.getSource()
。
在中有多个对象级别IResourceChangeEvent $ c顶部的$ c>通常是项目或工作区,下面是文件夹和文件。这些由
IResourceDelta
对象表示。
要查看所有这些都首先获得顶级 IResourceDelta
从事件:
IResourceChangeEvent event = ...事件
IResourceDelta delta = event.getDelta();
然后使用 IResourceDeltaVisitor
访问每个delta中的资源:
delta.accept(visitor);
其中访问者
是一个实现 IResourceDeltaVisitor
。
访问者只有一种方法:
public boolean visit(IResourceDelta delta)throws CoreException
which给每个资源一个增量。
IResourceDelta.getResource
为您提供了更改的资源。 IResourceDelta.getKind
告诉您更改的类型(添加,删除,更改)。
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()
.
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).
这篇关于以编程方式跟踪由eclipse清理完成的文件更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!