【问题标题】:Activating a profile when files exists using wildcards当文件存在时使用通配符激活配置文件
【发布时间】:2013-07-14 11:46:39
【问题描述】:

我在父 pom.xml Spring 支持中激活使用

<activation>
    <file>
        <exists>src/main/resources/*beans.xml</exists>
    </file>
</activation>

这很好用。

当我尝试使用

激活配置文件中的 CucumberJVM 内容时
<activation>
    <file>
        <exists>src/test/resources/**/*.feature</exists>
    </file>
</activation>

但是,这无法正常工作。所以我猜** 通配符在这种情况下被忽略了。

这正常吗,当存在.feature 文件时,是否有解决方法来激活此配置文件?

【问题讨论】:

    标签: maven cucumber activation profiles


    【解决方案1】:

    我真的很惊讶*beans.xml 有效。

    据我所知,文件激活不支持通配符。基于&lt;file&gt;计算配置文件激活的源代码可以在FileProfileActivator找到。核心逻辑是这样的:

    String path = //<file><exists> ...
    
    RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
    interpolator.addValueSource(/* ${basedir} suppert */)
    interpolator.addValueSource( new MapBasedValueSource( context.getProjectProperties() ) );
    interpolator.addValueSource( new MapBasedValueSource( context.getUserProperties() ) );
    interpolator.addValueSource( new MapBasedValueSource( context.getSystemProperties() ) );
    path = interpolator.interpolate( path, "" );
    path = pathTranslator.alignToBaseDirectory( path, basedir );
    File f = new File( path );
    if ( !f.isAbsolute() ){
        return false;
    }
    boolean isActive = f.exists();
    

    interpolate(...)alignToBaseDirectory(...) 都不会处理通配符。

    作为一种解决方法,您可以尝试使用&lt;activation&gt;&lt;property&gt; 进行一些噱头,但这需要使用 shell 脚本调用 maven 构建。

    【讨论】:

    【解决方案2】:

    在我们的项目中,我们使用下面的配置通过jar-plugin将所有测试打包成jar文件:

        <activation>
            <file>
                <exists>src/test/resources/com/companyname/platform/test/</exists>
            </file>
        </activation>
    

    这可以工作,因为:

    • 我们使用原型创建样板代码
    • 大多数人只将资源文件放在根文件夹中
    • 配置文件激活适用于目录,至少在 Maven 3.0.5 中

    【讨论】:

      猜你喜欢
      • 2011-07-17
      • 2016-05-20
      • 2011-11-12
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      • 2015-08-19
      • 2014-11-25
      相关资源
      最近更新 更多