从Eclipse外部以编程方式列出Eclipse工作区中的打开项目 [英] Programmatically list open projects in an eclipse workspace from outside of eclipse
问题描述
我想编写一个Gradle插件,该插件可以检查Eclipse工作区目录并遍历工作区中打开的项目并确定每个项目的位置.
I want to write a Gradle plugin which can inspect an eclipse workspace directory and iterate over the open projects within the workspace and determine the location of each.
类似
Workspace workspace = EclipseUtils.parseWorkspace("c:/myEclipseWorkspace");
Collection<Project> projects = workspace.getProjects();
for (Project project : projects) {
System.out.println(String.format("name=%s, location=%s, open=%s",
project.getName(), project.getLocation(), project.isOpen()));
}
我已经查看了我的工作区,并可以在c:\myEclipseWorkspace\.metadata\.plugins\org.eclipse.core.resources\.projects\
I've looked at my workspace and can see some .location
files under c:\myEclipseWorkspace\.metadata\.plugins\org.eclipse.core.resources\.projects\
但是这些文件是自定义二进制格式
But these files are a custom binary format
我可以调用一个eclipse API来解析这些吗?或其他一些方法来迭代工作空间中打开的项目.
Is there an eclipse API that I can invoke to parse these? Or some other solution to iterate the open projects in a workspace.
请注意,我想在外部执行此操作,而不是在eclipse插件中执行.
Please note that I want to do this externally to eclipse and NOT within an eclipse plugin.
推荐答案
读取私人描述以获取位置
由于您使用Java编写,因此请从外部位置重新使用Eclipse代码.
Reading the Private Description to Obtain Location
Since you are writing in Java, then reuse the Eclipse code from your external location.
即从org.eclipse.core.resources.ResourcesPlugin
中拉出一些关键代码.从org.eclipse.core.resources.ResourcesPlugin.getWorkspace()
的隐含代码开始,然后按您的方式操作到org.eclipse.core.resources.IWorkspaceRoot.getProjects()
i.e. Pull out some of the key code from org.eclipse.core.resources.ResourcesPlugin
. Start with the impl of org.eclipse.core.resources.ResourcesPlugin.getWorkspace()
and then work your way to org.eclipse.core.resources.IWorkspaceRoot.getProjects()
上面的代码在这里读取项目描述:org.eclipse.core.internal.resources.LocalMetaArea.readPrivateDescription(IProject, ProjectDescription)
,它从org.eclipse.core.internal.localstore.FileSystemResourceManager.read(IProject, boolean)
调用,它具有一些关于默认位置的逻辑.
The above code reads the project description here: org.eclipse.core.internal.resources.LocalMetaArea.readPrivateDescription(IProject, ProjectDescription)
and that is called from org.eclipse.core.internal.localstore.FileSystemResourceManager.read(IProject, boolean)
which has some logic about default locations.
这是EPL的乐趣,只要您的新程序/功能是EPL,您就可以重用Eclipse的核心代码来做新奇的事情.
This is the joy of EPL, as long as your new program/feature is EPL you can reuse Eclipse's core code to do new and wonderful things.
When reading workspace state, you are moving into the ElementTree data structures. Reading this without using the ElementTree classes is probably unrealistic. Using the ElementTree classes without full OSGi is probably unrealistic. I provide the following notes to help you on your way.
后退:
-
Project.isOpen()
被称为 - 运行时的标志位于
ResourceInfo.readFrom()
从SaveManager.readElement()
-
DataInput
readElement的>来自存储在 .metadata/.plugins/org.eclipse.core.resources/.root/<id>.tree
中工作空间元目录中的元素树.使用的文件的特定版本(id)记录在安全表.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources
中
- 安全表是
SaveManager
内部状态的一部分,存储在
ICoreConstants.M_OPEN
is the flag value indicating project is open or closed (set for open, clear for closed)- M_OPEN is tested when
Project.isOpen()
is called - The flags at runtime are in
ResourceInfo.flags
- The flags are loaded by
ResourceInfo.readFrom()
called fromSaveManager.readElement()
- The
DataInput
input
passed toreadElement
is from the Element Tree stored in the workspace meta directory in.metadata/.plugins/org.eclipse.core.resources/.root/<id>.tree
. The specific version (id) of the file to use is recorded in the safe table.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources
- The safe table is part of the
SaveManager
's internal state stored in aMasterTable
这篇关于从Eclipse外部以编程方式列出Eclipse工作区中的打开项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!