测试Tycho Master POM [英] Test Tycho Master POM

查看:108
本文介绍了测试Tycho Master POM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们公司所有的RCP插件都具有相同的Maven父代,在向其中添加了许多Maven插件后,我意识到Tycho并不像我希望的那样具有确定性.

All our company's RCP plug-ins have the same Maven parent, and after adding a bunch of Maven plug-ins to it I realized that Tycho is not as deterministic as I'd like it to be.

我知道这不是什么新闻,所以这就是为什么我要为父 pom.xml 设置一些测试的原因.我在考虑一些基本的东西:启用了哪些配置文件,执行了哪些插件,为已定义的 pom.xml 抛出了什么异常,命令行参数和目标平台.

That's hardly news, I know, so that's why I want to set up some tests for the parent pom.xml. I'm thinking of basic stuff: which profiles are enabled, which plug-ins are executed, what exception is thrown for a defined pom.xml, command line arguments and target platform.

尽管大多数其他项目似乎在某个地方都有一个主POM,但我找不到任何方法对其进行测试.我该怎么办?

Even though most other projects seem to have a master POM somewhere, I could not find any way to test it. How do I do that?

推荐答案

我的团队负责为开发人员创建一套公司POM.我已经使用 maven-invoker-plugin 来验证父级POM行为.查看许多Apache Maven插件的源(测试)代码,如果需要入门帮助,您将找到调用者测试用例.

My team is responsible for creating a suite of corporate POMs for the development staff. I have used the maven-invoker-plugin for validating parent POM behavior. Look at the source (test) code for many of the Apache Maven plugins and you'll find invoker test cases if you need help getting started.

使用使用Beanshell或Groovy编写的构建后脚本.对于您要验证的事物类型(插件执行,配置文件激活等),我发现的最佳方法是检查build.log中是否有预期的消息.我用这样的方法编写了一个帮助器类:

Validation of the results is done with a post build script written in either Beanshell or Groovy. For the types of things you'd like to verify (plugin executions, profile activations, etc.) the best way I've found is to examine the build.log for expected messages. I wrote a helper class with methods like this:

public static boolean assertPatternsExist(final InputStream is, final String fileName,
                                          final List<String> patternList) throws IOException {

    try (final Scanner scanner = new Scanner(is)) {
        for (final String pattern : patternList) {
            if (scanner.findWithinHorizon(pattern, 0) == null) {
                LOG.error(String.format("Could not match pattern '%s' in file %s", pattern, fileName)); //$NON-NLS-1$
                return false;
            }
        }
    }
    return true;
}

然后我的验证脚本(verify.groovy)包括使用这些辅助方法的验证.

And then my validation script (verify.groovy) includes validations using those helper methods.

def result = assertPatternsExist(new File(basedir, '/build.log'), [
    'INFO.*?maven-dependency-plugin:.*?:copy-dependencies \\(some-execution-id\\)',
    'INFO.*?maven-assembly-plugin:.*?:single \\(another-execution-id\\)',
    '.*?propertyDefinedInProfile = valueFromActivatedProfile' ])

在此示例中,测试期望依赖插件的copy-dependencies目标作为ID为'some-execution-id'的执行的一部分运行,然后是程序集插件的single目标作为执行的一部分运行另一个执行ID".第三种模式验证如果激活了配置文件,则配置文件中定义的属性具有预期的值.模式的顺序很重要.

In this example, the test is expecting the dependency plugin's copy-dependencies goal to be run as part of an execution with id 'some-execution-id', followed by the assembly plugin's single goal run as part of execution 'another-execution-id'. The third pattern verifies that a property defined in a profile has the value expected if that profile was activated. Order of the patterns matters.

请注意,搜索条件是根据正则表达式指定的.这样可以使测试免受日志格式的微小更改的影响.该测试套件是为Maven 3.0.x编写的,到目前为止,它仍可与更高版本的Maven一起使用.

Note that the search criteria is specified in terms of regular expressions. This should insulate the tests from minor changes in log format. The test suite was written for Maven 3.0.x and has continued to work with later Maven versions thus far.

这篇关于测试Tycho Master POM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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