Activating a profile when files exists using wildcards
Asked Answered
M

2

8

I activate in a parent pom.xml Spring support using

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

This works fine.

When I try to activate the CucumberJVM stuff in a profile using

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

However this refuses to work. So I guess the ** wildcard is ignored in this context.

Is this normal, is there a workaround to get this profile activated when .feature files are present?

Megasporophyll answered 16/7, 2013 at 10:26 Comment(0)
A
10

I'm actually surprised that *beans.xml works.

As far as I can see, wildcards are not supported in file activation. The source code that calculates profile activation based on <file> can be found in FileProfileActivator. The core logic goes like this:

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();

And neither interpolate(...) nor alignToBaseDirectory(...) process wildcards.

As a workaround you can try some gimick with <activation><property>, but that would require calling the maven build with a shell script.

Alcyone answered 2/8, 2013 at 10:25 Comment(1)
Note that in 3.0.5 source code (maven.apache.org/ref/3.0.5/xref/org/apache/maven/model/profile/…), context.getProjectProperties() is never called.Demitria
M
4

In our project, we use the configuration below to package all tests as jar-files using the jar-plugin:

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

This is able to work because:

  • we create boilerplate code using archetypes
  • most people only put resource files in the root folder
  • the profile activation works on directories, at least in Maven 3.0.5
Mcinnis answered 22/10, 2013 at 11:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.