2013-07-16 41 views
7

我在父pom.xml Spring支持激活激活配置文件。文件时存在使用</p> <pre><code><activation> <file> <exists>src/main/resources/*beans.xml</exists> </file> </activation> </code></pre> <p>这正常使用通配符

当我尝试使用

<activation> 
    <file> 
     <exists>src/test/resources/**/*.feature</exists> 
    </file> 
</activation> 

但是这个拒绝工作以激活CucumberJVM东西的轮廓。所以我猜这个上下文中的**通配符会被忽略。

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

回答

6

我真的很惊讶,*beans.xml的作品。

据我所见,通配符不支持在文件激活。根据<file>计算配置文件激活的源代码可在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(...)过程通配符。

作为一种解决方法,您可以尝试使用<activation><property>,但这需要使用shell脚本调用maven版本。

+0

请注意,在3.0.5源代码(https://maven.apache.org/ref/3.0.5/xref/org/apache/maven/model/profile/activation/FileProfileActivator.html)中,'' context.getProjectProperties()'永远不会被调用。 – Stephan

2

在我们的项目中,我们使用下面的配置使用jar-插件打包所有的测试为JAR档案:

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

这是能够工作是因为:

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