2013-07-16 50 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中