在eclipse之外的程序中列出eclipse工作区中的打开项目 [英] Programatically list open projects in an eclipse workspace from outside of eclipse

查看:272
本文介绍了在eclipse之外的程序中列出eclipse工作区中的打开项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个Gradle插件,它可以检查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类可能是不切实际的。我提供以下注意事项来帮助您。



向后工作:




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 from SaveManager.readElement()
  • The DataInput input passed to readElement 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 a MasterTable

这篇关于在eclipse之外的程序中列出eclipse工作区中的打开项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆