Hello, all!

I have an extension

  https://github.com/imca-cat/profile-activation-advanced

that allows property-based profile activation based on an MVEL
expression.

My problem is that it works

===
$ mvn help:active-profiles validate
...
The following profiles are active:

 - foo_env-development (source: org.example.foo:foo:1.0.0)
...
===

when loaded via Maven's lib/ext directory or when specified on the
command line with "-Dmaven.ext.class.path=<path-to-extension-jars>", but
does *not* work

===
$ mvn help:active-profiles validate
...
The following profiles are active:

...
===

when loaded via a project's .mvn/extensions.xml file.

The extension hijacks the normal property activator like this

  @Component(role = ProfileActivator.class, hint = "property")
  public class AdvancedProfileActivator implements ProfileActivator {
    ...
  }

and evaluates the property value as an MVEL expression if the property
name equals "mvel" or "mvel(" <properties-map-identifier> ")".

Does anyone know why it would work from Maven's lib/ext directory, but
not from a project's .mvn/extensions.xml file?  Or does anyone know how
to debug this?

Is it possible that the hijack doesn't work when loaded from a
project's .mvn/extensions.xml because the original profile activator is
found on the class path *before* the AdvancedProfileActivator of the
extension, but when the extension JAR is placed in Maven's lib/ext,
the AdvancedProfileActivator is found on the class path *before* the
original profile activator?  (Just a wild guess.)

The full source code of the extension's profile activator is at

  
https://github.com/imca-cat/profile-activation-advanced/blob/master/src/main/java/org/imca_cat/maven/profile_activation_advanced/AdvancedProfileActivator.java

To reproduce the problem, simply create a new Maven project directory
containing the following pom.xml file:

===
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
        http://maven.apache.org/xsd/maven-4.0.0.xsd";>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example.foo</groupId>
  <artifactId>foo</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <profiles>
    <profile>
      <id>foo_env-development</id>
      <activation>
        <property>
          <name>mvel</name>
          <value>(!isdef foo_env) || foo_env == "development"</value>
        </property>
      </activation>
    </profile>
  </profiles>
</project>
===

(The foo_env-development profile should activate if the foo_env property
(or system property) is not set or is set to the string "development".)

Create .mvn/extensions.xml:

===
<?xml version="1.0" encoding="UTF-8"?>
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0
        http://maven.apache.org/xsd/core-extensions-1.0.0.xsd";>
  <extension>
    <groupId>org.imca-cat.maven</groupId>
    <artifactId>profile-activation-advanced</artifactId>
    <version>0.1.0</version>
  </extension>
</extensions>
===

Run the following command:

===
$ mvn help:active-profiles validate
===

It should report that the foo_env-development profile is active (because
the foo_env property is not set), but it does not. :-(

I previously asked on the Maven User list

  
https://lists.apache.org/thread.html/99ee87ba1bc86d98652173482b3a5882a52e344fad18df2cd50e8750@%3Cusers.maven.apache.org%3E

but did not receive any replies.

Thank you for your help!

Lewis

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org

Reply via email to