Code Monkey home page Code Monkey logo

el-profile-activator-extension's Introduction

EL Profile Activation Maven Extension

Allows profile to be activated using an expression language expression. Currently supports MVEL2 only. Extension hijacks property activation and tries to evaluate mvel expression first, if this is not successful it passes control to original property activator.

In order to activate extension, you cannot include it into <build><extensions> element, because profile activation is done before it would be activated. So you need to copy following files into $MAVEN_HOME/lib/ext:

To profit from new activation, add following in your pom.xml:

<profile>
    <id>my-profile</id>

    <activation>
        <property>
        	<!-- mvel property name is obligatory -->
            <name>mvel</name>
            <value>isdef foo &amp;&amp; foo=="abc"</value>
        </property>
    </activation>
</profile>            

A few examples (an MVEL cheatsheet)

  • Check if foo and bar are defined and have same value

      isdef foo &amp;&amp; isdef bar &amp;&amp; foo==bar
    
  • Check if foo is defined while bar is not

      isdef foo &amp;&amp; !isdef bar
    
  • Check if foo starts with abc or baz contains xyz

      isdef foo &amp;&amp; foo.startsWith("abc")) || (isdef baz &amp;&amp; baz.contains("xyz"))
    

Complete MVEL reference guide is available at http://mvel.codehaus.org/Language+Guide+for+2.0

el-profile-activator-extension's People

Contributors

bartoszmajsak avatar kpiwko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

el-profile-activator-extension's Issues

No way to get value of property with dot in name

I tried to use the property foo.env to control profile activation, but the extension fails to evaluate the expression:

$ mvn -Dfoo.env=development validate
[INFO] Scanning for projects...
[WARNING] Unable to evaluate mvel property value ("if (isdef foo.env) {
  foo.env == "development";
} else {
  true;
}")
[INFO]
[INFO] ------------------------< org.example.foo:foo >-------------------------
[INFO] Building foo 1.0.0
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.230 s
[INFO] Finished at: 2018-10-19T17:27:51-05:00
[INFO] ------------------------------------------------------------------------

Is it treating foo.env as a property expression (i.e., an expression to extract the env property out of the foo variable or context object)?

This is with Maven 3.5.4, MVEL 2.4.2, and EL Profile Activation Maven Extension snapshot c3b490a.

The pom.xml file contains:

<?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>
<![CDATA[
if (isdef foo.env) {
  foo.env == "development";
} else {
  true;
}
]]>
          </value>
        </property>
      </activation>
    </profile>
  </profiles>
</project>

How can I get the value of the foo.env property?

The Profile Activator Extension seems to have adopted the syntax value["foo.env"] for this situation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.