编写 Eclipse 感知的 Ant 任务
我想编写一个简单的 Ant 任务,它可以与 Eclipse 工作区交互以从中获取一些信息。我希望能够使用各种 Eclipse API(例如,IWorkspace
)。
我的问题是执行此操作的最简单方法是什么。
作为 Eclipse 平台的用户,我对 Eclipse 平台非常了解,但对 Eclipse 开发一无所知。我知道,在运行时,我的 Ant 任务必须在与工作区相同的 JRE 下调用 - 这是我愿意遵守的限制。
我首先创建一个 Java 项目来保存我的 Ant 任务。我相信现在唯一的问题是如何定义 Eclipse JAR 的 JAR 依赖关系。我显然不想依赖于一个特定的 Eclipse JAR,因为它们是有版本的(例如 Eclipse 的“Resources”插件)。是否可以让我的 Java 项目构建时间取决于“资源插件的当前 JAR 是什么”?
I would like to write a simple Ant task that would interact with an Eclipse workspace to get some information from it. I would like to be able to use the various Eclipse API's (for example, IWorkspace
).
My question is what would be the simplest way to go about doing this.
I have excellent knowledge of the Eclipse platform as a user of it - but none with development for Eclipse. I understand that, in runtime, my Ant task will have to be invoked under the same JRE as the workspace - that's a restriction I'm willing to be bound to.
I started by creating a Java project to hold my Ant task. I believe that the only thing in my way now is how to define the JAR dependency on Eclipse's JARs. I obviously don't want to depend on one specific Eclipse JAR as these are versioned (for example, Eclipse's "Resources" plugin). Is it possible to have my Java project buildtime-depend on "whatever the current JAR is for the Resources plugin"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这篇文章很大程度上解决了您的问题:http://www.ibm. com/developerworks/rational/library/09/eclipsecustomanttasks/
它是针对 IBM Rational Application Developer,但它是基于 Eclipse 和 AFAIS 的,至少这里没有发生太多非 Eclipse 特定的事情不考虑如何使任务在 Eclipse 中可用的细节(编写插件定义等)。
I think this article quite much addresses your problem: http://www.ibm.com/developerworks/rational/library/09/eclipsecustomanttasks/
It is targeted to the IBM Rational Application Developer, but that one is based on Eclipse and AFAIS there is not overly much non-eclipse-specific happening here, at least not regarding the specifics about how to make the task available in Eclipse (writing the plugin definition etc).
因此,您需要一个在 Eclipse 中运行的 Ant 任务。正如您所说,很明显这些任务正在使用 Eclipse API。截至目前,我还不太明白他们是如何做到的。我查看了其中几个的来源,但仍然有疑问。
要查找 Eclipse 提供的所有 Ant 任务的位置,请执行插件搜索 org.eclipse.ant.core.antTasks。当我这样做时,我看到大约二十个扩展,其中许多扩展定义了多个任务。
如果您获得了贡献这些任务之一的插件的源包,您可以查看它的源代码。 RefreshLocalTask 位于 org.eclipse.core.resources 中;不幸的是,当我将此包作为源项目导入到我的工作区时,Ant 任务的源代码无法正确链接。它们有一个单独的 jar(在捆绑包内),并且虽然源位于捆绑包中,但不清楚该 jar 是如何编译的。结果是我的工作区中没有编译 Ant 任务源。
您还可以 Google 查找 Ant 任务源;这是 RefreshLocalTask 的 3.6.0 源。
无论如何,在源代码中,您可以看到对 org.eclipse.core.resources.ResourcePlugin 的调用,这些调用说明了您可能需要的内容。
啊,我在扩展点描述中看到 - 右键单击这些搜索结果之一并选择“显示描述”,或者从清单编辑器转到那里 - 有一个可以设置的标志,“eclipseRuntime”;文本暗示如果设置了该值,Eclipse 将在同一 VM 中启动该任务。
So, you want an Ant task that runs within Eclipse. And as you say, it's clear that those tasks are using the Eclipse API. As of this moment, I don't really understand how they're doing it. I've looked at the source of a couple of them and I still have questions.
To find the locations of all the Ant tasks contributed by Eclipse, do a Plug-in Search for
org.eclipse.ant.core.antTasks
. When I do that, I see twenty or so extensions, many of which define multiple tasks.If you get the source bundle for a plugin that contributes one of these tasks, you can look at the source for it. RefreshLocalTask is in org.eclipse.core.resources; unfortunately, when I import this bundle into my workspace as a source project, the source for the Ant tasks doesn't get linked correctly. There is a separate jar (inside the bundle) for them, and, while the source is in the bundle, it's not clear how the jar is compiled. The upshot is that I don't have the Ant task source compiling in my workspace.
You can also Google for the Ant task source; here's the 3.6.0 source for
RefreshLocalTask
.Anyway, in the source you can see calls to
org.eclipse.core.resources.ResourcePlugin
that are illustrative of what you probably need.Ah, I see in the extension point description - right-click on one of those search results and choose "Show Description", or go there from the Manifest editor - that there is a flag you can set, "eclipseRuntime"; the text implies that if it is set, Eclipse will launch the task in the same VM.
您可能应该更多地说明您想做什么,因为您可以采取多种路线。
你不能做什么:我很确定当 Eclipse 启动 Ant 时,它总是在一个单独的 VM 中,无法回调到 Eclipse。
所以也许你应该多说一些你想做什么。
You should probably say more about what you want to do, because there are several routes you can take.
What you can't do: I'm pretty sure that when Eclipse launches Ant, it is always in a separate VM, with no way to call back into Eclipse.
So perhaps you should say more about what you want to do.