Skip to content

Commit f2a6135

Browse files
committed
[OPENJDK-1549] Mvn project to test for MAVEN_ARGS
Simple test Maven project for which the validate phase will fail if MAVEN_ARGS is defined in the environment and pass otherwise. Signed-off-by: Jonathan Dowland <[email protected]>
1 parent 4a2ae60 commit f2a6135

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

tests/OPENJDK-1549/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Test for OPENJDK-1549
2+
3+
<https://issues.redhat.com/browse/OPENJDK-1549>
4+
5+
This is a minimal Maven project for which the `validate` target will fail
6+
if the environment variable `MAVEN_ARGS` is defined.
7+
8+
This is achieved using the Enforcer plugin. We could not use the
9+
`requireEnvironmentVariable` built-in rule as it can only fail if a variable
10+
is undefined, rather than if it is. Instead we use `evaluateBeanshell` and
11+
a very short Beanshell expression.
12+
13+
Maven expands strings of the form `${env.foo}` within the POM only if the
14+
variable is defined. That is, when `MAVEN_ARGS` is not defined in the
15+
environment, the string `${env.MAVEN_ARGS}` is passed through unaltered.
16+
If the variable is defined (including defined but empty), Maven will expand
17+
it. Some string concatenation trickery is needed to match against the
18+
un-expanded form.

tests/OPENJDK-1549/pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project>
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.acme</groupId>
5+
<artifactId>getting-started</artifactId>
6+
<version>1.0.0-SNAPSHOT</version>
7+
<build>
8+
<plugins>
9+
<plugin>
10+
<groupId>org.apache.maven.plugins</groupId>
11+
<artifactId>maven-enforcer-plugin</artifactId>
12+
<version>3.3.0</version>
13+
<executions>
14+
15+
<!-- ensure the environment variable MAVEN_ARGS is unset -->
16+
<execution>
17+
<id>enforce-beanshell</id>
18+
<goals>
19+
<goal>enforce</goal>
20+
</goals>
21+
<configuration>
22+
<rules>
23+
<evaluateBeanshell>
24+
<condition>"${env.MAVEN_ARGS}".equals("${env."+"MAVEN_ARGS}")</condition>
25+
</evaluateBeanshell>
26+
</rules>
27+
<fail>true</fail>
28+
</configuration>
29+
</execution>
30+
31+
</executions>
32+
</plugin>
33+
</plugins>
34+
</build>
35+
</project>

0 commit comments

Comments
 (0)