maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ramón Rial <rri...@gmail.com>
Subject Fwd: About profile activation with JSR223
Date Mon, 07 Sep 2015 06:58:37 GMT
I have redesigned the project. It is available at
https://github.com/rrialq/jsr223-profile-activator-extension.

Instead of resolving properties  the extension resolves expressions with
the help of Maven interpolator, so it is possible use the original names of
properties and it is possible to write complex expressions.
An example (please, keep in mind that the following example was written
considering the simplicity of the same, not its correct syntax, so the XML
presented here is not well formed. For example, instead of the && you must
write &amp;&amp;):

<profiles>
    <profile>
        <id>MY_SITE_SKIP_ACTIVATED</id>
        <property>
            <name>=</name>
            <value>
                var mySiteSkip =
aitor.eval('${MY_SITE_SKIP}').getBoolean(false);
                var reportsEnabled =
aitor.eval('${REPORTS_ENABLED}').getBoolean(false);
                var reportsLevel = aitor.eval('${REPORTS_LEVEL}').getInt(0);
                var siteUrl = aitor.eval('${SITE_URL}').getString('');
                var siteDefined = ( siteUrl != '' );
                mySiteSkip && reportsEnabled && ( reportsLevel > 0 ) &&
siteDefined
            </value>
        </property>

----------
​Reply
 message ----------
From: Ramón Rial <rrialq@gmail.com>
Date: 2015-08-25 19:57 GMT+02:00
Subject: About profile activation with JSR223
To: dev@maven.apache.org


Hello.

*About JSR223 support for activating Profiles*
I have a modified version of *PropertyProfileActivation.java* that allows
activate a profile evaluating a script.
I've done that with JSR223, and it is a minimal modification.
The idea is:

   - Keep the old funcionality for property profile activation.
   - Allow the evaluation of scripts in some of the JSR223 languages
   allowed.
   - Add to the context of the evaluation the *ProjectProperties*, the
   *UserProperties* and *SystemProperties*.

*An example of this:*

<profile>

    <activation>

        <property>

            <name>=JavaScript</name>

            <value>( projectProperty == 'value' &amp;&amp; systemProperty
== '45' )

|| ( userProperty == 'development' )</value>

        </property>

    </activation>

</profile>

The explanation

The key to get this without modifying the current model of pom and choose
an ScriptEngine is the name of the property.

It begins with "*=*" (equals) char, to indicate that value is a JSR223
script, and after the equals char the name of the script engine.

We write the script in the value tag.

You can see in the example that we use system properties, project
properties and user properties, *AND* and *OR* logical operators, so you
can write so complex scripts as you want.

The logical AND should be written as &amp;&amp; because of XML.

*IMPORTANT*: The new *PropertyProfileActivation.java* converts the name of
the project properties, system properties and user properties to a safe
name, to allow use them in the script, so if you have a project property
with the name "*my.project.property*" it will be replaced in the script
context to "*my_project_property*".

Question

Do you think this could be interesting for Maven 3?

Greetings.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message