如何在 m2e 插件中拦截来自 Maven Mojo 的日志消息
我有一个特殊的 JavaScript maven 插件,它验证/压缩 /src/main/javascript 中的 JavaScript 源并将其存储到 /target/scripts 中。在带有 m2e 0.x 的 Eclipse 3.6 中,这工作得很好,因为这个插件是在进程资源阶段执行的。因此,每次我在 Eclipse 中保存文件时,都会编译项目。当验证器发现问题时,该问题将作为错误记录到 Maven 控制台。
现在,在 Eclispe 3.7 和新的 m2e 1.x 中,这不再有效,因为需要特殊的连接器来处理此插件。还可以配置生命周期映射,以便轻松执行该插件。但是当我这样做时,我不再有记录消息。当发现 Javascript 错误时,我只会在 POM 中看到错误标记。这其实没什么用。所以我试图编写一个 m2e 插件来执行 Maven 插件,然后在 Eclipse 中很好地显示错误。但说到 Eclipse 插件编程,我完全是个菜鸟。我的参与者目前看起来是这样的:
public class Participant extends MojoExecutionBuildParticipant
{
public Participant(final MojoExecution execution)
{
super(execution, true);
}
@Override
public Set<IProject> build(final int kind, final IProgressMonitor monitor)
throws Exception
{
final Set<IProject> result = super.build(kind, monitor);
return result;
}
}
构建方法被正确调用,maven插件也被正确执行。但通过这种简单的方法,当插件失败时,我什至没有得到任何错误标记。那么我现在如何挂钩 Maven 执行来拦截构建错误以及如何在 Eclipse 中显示它们?当错误日志消息再次显示在 Maven 控制台中时就足够了,但是当我可以创建指向真实文件位置的真实错误标记(我可以从 Maven 插件日志记录中解析)时,它会更酷。
I have a special JavaScript maven plugin which validates/compresses JavaScript sources from /src/main/javascript and stores it into /target/scripts. In Eclipse 3.6 with m2e 0.x this worked perfectly because this plugin is executed during the process-resources phase. So everytime I save a file in Eclipse the project is compiled. When the validator finds a problem then this problem is logged as an error to the maven console.
Now with Eclispe 3.7 and the new m2e 1.x this no longer works because a special connector is needed to process this plugin. It is also possible to configure a lifecycle mapping so this plugin is simply executed. But when I do this I have no logging messages any longer. I only get an error marker in the POM when a Javascript error was found. This isn't really useful. So I'm trying to write a m2e plugin which executes the maven plugin and then displays the errors nicely in Eclipse. But I'm a total noob when it comes to eclipse plugin programming. My participant currently looks like this:
public class Participant extends MojoExecutionBuildParticipant
{
public Participant(final MojoExecution execution)
{
super(execution, true);
}
@Override
public Set<IProject> build(final int kind, final IProgressMonitor monitor)
throws Exception
{
final Set<IProject> result = super.build(kind, monitor);
return result;
}
}
The build method is correctly called and the maven plugin is also correctly executed. But with this simple approach I even don't get any error markers when the plugin fails. So how can I hook into the maven execution now to intercept build errors and how can I display them in Eclipse? It would be sufficient when the error log messages simply are displayed in the maven console again but it would be even cooler when I could create real error markers pointing to the real file locations (Which I could parse from the maven plugin logging).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论