编写 Eclipse 感知的 Ant 任务

发布于 2024-09-26 20:14:10 字数 422 浏览 0 评论 0原文

我想编写一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鼻尖触碰 2024-10-03 20:14:10

我认为这篇文章很大程度上解决了您的问题: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).

单挑你×的.吻 2024-10-03 20:14:10

因此,您需要一个在 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.

故人爱我别走 2024-10-03 20:14:10

您可能应该更多地说明您想做什么,因为您可以采取多种路线。

  1. Eclipse 提供了一些可在构建脚本中使用的 Ant 任务。 此处 有几个。还有更多,因此在 Eclipse 文档中搜索“ant 任务”;它们分散在不同的页面中。 Eclipse Preferences(Window..Preferences,然后选择 Ant/Runtime,然后查看 Classpath 选项卡中的“Contributed Entries”)显示每当从 Eclipse 调用 Ant 时 Eclipse 向运行时贡献的 Ant 任务列表;只要包含正确的 jar,您就可以自己调用任何这些任务。
  2. 可以从 Ant 任务中启动 Eclipse,因为可以从 Java 启动 Eclipse。您需要包含正确的 jar 并进行正确的调用;您还需要正确配置 Eclipse。 “org.eclipse.core.runtime.adaptor.EclipseStarter”应该为您提供一些详细信息。
  3. 也许您可以使用 Eclipse 定义的一个或多个变量,以便在启动 Ant(或任何其他程序)时使用。尝试创建一个外部工具配置(在“运行”菜单的底部)- 选择一个 Ant 构建并尝试使用参数(来自“主”选项卡)或环境变量(来自“环境”)选项卡对其进行自定义。两者都允许您访问 Eclipse 变量。当然,这些只是您可以传递到 Ant 脚本中的值,而不是您可以调用方法的任何内容的句柄。

你不能做什么:我很确定当 Eclipse 启动 Ant 时,它总是在一个单独的 VM 中,无法回调到 Eclipse。

所以也许你应该多说一些你想做什么。

You should probably say more about what you want to do, because there are several routes you can take.

  1. Eclipse provides some Ant tasks that you can use in your build scripts. Here are a few. There are more, so search for "ant tasks" in the Eclipse docs; they're scattered throughout different pages. Eclipse Preferences (Window..Preferences, then select Ant/Runtime, and look at the "Contributed Entries" in the Classpath tab) shows you a list of Ant tasks that Eclipse contributes to the runtime whenever Ant is invoked from Eclipse; you can invoke any of these tasks yourself as long as you include the right jar.
  2. It's possible to start up Eclipse from within an Ant task, because it's possible to start Eclipse from Java. You need to include the right jars and make the right calls; you also need to configure Eclipse correctly. "org.eclipse.core.runtime.adaptor.EclipseStarter" should give you some detail.
  3. Perhaps you can use one or more of the variables Eclipse defines for use when launching Ant (or any other program). Try creating an External Tool Configuration (at the bottom of the Run menu) - select an Ant Build and try customizing it with arguments (from the Main tab) or environment variables (from the Environment) tab. Both give you access to Eclipse variables. But of course these are just values you can pass into your Ant script, not handles to anything you can invoke a method on.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文