构建自定义 Maven 模型验证器

发布于 2024-12-13 03:18:45 字数 371 浏览 0 评论 0原文

我经常使用 Flexmojos 插件,并尽力帮助 Flexmojos 邮件列表中的人们。

在帮助的过程中,我发现一大堆问题总是重复出现,而且通常都有相同的解决方案。

我现在的想法是向 flexmojos 添加某种验证代码,以便人们更容易找出问题所在。在查看 Maven 代码时,我遇到了 ModelValidators(主要是因为我试图找到一种方法来摆脱那些烦人的范围警告)。我认为创建一个实现 ModelValidator 的验证器并将其包含在插件中是一个好主意。

不幸的是,我找不到实际提供自定义验证器的记录方法。如果 DefaultModelValidator 是 Maven 支持的唯一一个,这里有人可以指导我如何完成此操作吗?或者阻止我继续搜索。

克里斯

I use the flexmojos plugin quite a lot and am trying to help people on the flexmojos mailinglist as good as I can.

While helping, I could see that a hand full of problems allway reoccur and usually allways have the same solution.

My idea now was to add some sort of validation code to flexmojos in order to make it easier for people to find out what's going wrong. While looking through the Maven code I enountered the ModelValidators (mainly because I was trying to find a way to get rid of those anoying scope warnings). I thougt it would be a good Idea to create a validator that implements ModelValidator and to include that in the plugin.

Unfortunately I couldn't find a documented way to actually provide custom validators. Could someone here please guide me to how this is done or stop me from seaching any longer if the DefaultModelValidator is the only one that Maven supports.

Chris

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

感性 2024-12-20 03:18:45

好吧......我终于找到了解决我的问题的方法。这里是:

一般来说,Maven 不支持我想要的。幸运的是,有一种方法可以做到这一点。
当我重新配置 Maven 时,我必须创建一个具有 ModelValidator 角色的组件。如果我随后将包含此组件的 jar 放在我的 MAVEN_HOME/lib/ext 目录中,它将覆盖编织并使用我的 ModelValidator 而不是默认的。

@Component( role = ModelValidator.class )
public class FMDefaultModelValidator extends DefaultModelValidator {
    @Override
    public void validateEffectiveModel(Model model, ModelBuildingRequest request, ModelProblemCollector problems) {
        //super.validateEffectiveModel(model, request, problems);
    }
}

有了这个技巧,我可以通过验证做任何我想做的事情。
我记录了这一点,并在我的公司汇合中添加了一个默认项目:
https://dev.c-ware.de /confluence/display/PUBLIC/Flexmojos+in+Continously+Integration+Builds

Ok ... I finally figgured out a solution to my problem. Here goes:

In general Maven doesn't support what I want. Fortunately there is a way to do it.
As I am reconfiguring Maven, I have to create a component with the role ModelValidator. If I then place the jar containing this component in my MAVEN_HOME/lib/ext directory, it overrides the weaving and my ModelValidator is used instead of the default one.

@Component( role = ModelValidator.class )
public class FMDefaultModelValidator extends DefaultModelValidator {
    @Override
    public void validateEffectiveModel(Model model, ModelBuildingRequest request, ModelProblemCollector problems) {
        //super.validateEffectiveModel(model, request, problems);
    }
}

With this trick I can do whatever I want with the validation.
I documented this and added a default project in my companies confluence:
https://dev.c-ware.de/confluence/display/PUBLIC/Flexmojos+in+Continuous+Integration+Builds

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