Beanshell
This rule can execute a beanshell script and evaluate the result.
The following parameters are supported by this rule:
- condition - the beanshell statement to evaluate.
- message - an optional message to the user if the rule fails.
Sample Plugin Configuration:
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.5.0</version> <executions> <execution> <id>enforce-beanshell</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <evaluateBeanshell> <condition>${project.artifactId} == foo</condition> </evaluateBeanshell> </rules> <fail>true</fail> </configuration> </execution> </executions> </plugin> </plugins> </build> [...] </project>
The condition can be a complex script or a simple expression. As long as it results in True, the rule will succeed. This means code can be executed as long as the last line results in true.
<evaluateBeanshell> <condition>for (int i = 0;i!=10;i++){print ("Hello World "+i);};1==1</condition> </evaluateBeanshell>