Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activating a profile when files exists using wildcards

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?

like image 481
Peter Tillemans Avatar asked Jul 16 '13 10:07

Peter Tillemans


2 Answers

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.

like image 143
rzymek Avatar answered Sep 21 '22 07:09

rzymek


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
like image 36
marjohr Avatar answered Sep 20 '22 07:09

marjohr