在eclipse之外的程序中列出eclipse工作区中的打开项目 [英] Programatically list open projects in an eclipse workspace from outside of eclipse
问题描述
Workspace workspace = EclipseUtils.parseWorkspace(c:/ myEclipseWorkspace);
集合<项目> projects = workspace.getProjects(); (项目项目:项目)
{
System.out.println(String.format(name =%s,location =%s,open =%s,
project.getName (),project.getLocation(),project.isOpen()));
}
我看过我的工作区,可以看到一些 .location
文件在 c:\myEclipseWorkspace\.metadata\.plugins\org.eclipse.core.resources\.projects\
但是这些文件是一个自定义的二进制格式
是否有可以调用的eclipse API来解析这些?或者一些其他解决方案来迭代工作区中的打开的项目。
请注意,我想在eclipse外部执行此操作,而不是在eclipse插件中。
阅读私人描述获取位置
由于您是用Java编写的,然后从外部位置重新使用Eclipse代码。
ie从 org.eclipse.core.resources.ResourcesPlugin
中拉出一些关键代码。从 org.eclipse.core.resources.ResourcesPlugin.getWorkspace()
的含义开始,然后以...的方式工作到 org.eclipse.core.resources .IWorkspaceRoot.getProjects()
上面的代码在这里读取项目描述: org.eclipse.core.internal .resources.LocalMetaArea.readPrivateDescription(IProject,ProjectDescription)
,这是从 org.eclipse.core.internal.localstore.FileSystemResourceManager.read(IProject,boolean)
它有一些关于默认位置的逻辑。
这是EPL的喜悦,只要您的新程序/功能是EPL,您可以重用Eclipse的核心代码做新事物。
阅读工作区状态以获取打开/关闭状态
阅读工作区状态时, a href =https://git.eclipse.org/c/platform/eclipse.platform.resources.git/tree/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/watson/ ElementTree.java?id=203adc38703c15ee3fa52113131811962dd336e2#n23rel =nofollow> ElementTree 数据结构。没有使用ElementTree类阅读这个可能是不切实际的。使用没有完整OSGi的ElementTree类可能是不切实际的。我提供以下注意事项来帮助您。
向后工作:
-
ICoreConstants.M_OPEN
是指示项目打开或关闭的标志值(设置为开放,清除关闭) - M_OPEN在
Project.isOpen )
被称为 - 运行时的标志位于
ResourceInfo.readFrom()
从SaveManager.readElement()
-
DataInput
input
传递给readElement
来自.metadata / .plu轧花/ org.eclipse.core.resources / .root /< ID> .TREE
。要使用的文件的特定版本(id)记录在安全表.metadata / .plugins / org.eclipse.core.resources / .safetable / org.eclipse.core.resources
- 安全表是存储在 SaveManager 的内部状态的一部分//git.eclipse.org/c/platform/eclipse.platform.resources.git/tree/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/SaveManager.java?id= 203adc38703c15ee3fa52113131811962dd336e2#n37rel =nofollow>
MasterTable
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.
Something like
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()));
}
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
Is there an eclipse API that I can invoke to parse these? Or some other solution to iterate the open projects in a workspace.
Please note that I want to do this externally to eclipse and NOT within an eclipse plugin.
Reading the Private Description to Obtain Location
Since you are writing in Java, then reuse the Eclipse code from your external location.
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()
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.
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.
Reading Workspace State to Obtain Open/Close State
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.
Working backwards:
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屋!