Skip to content

Commit 662e0e8

Browse files
authored
Merge pull request #376 from jmtd/OPENJDK-1548-maven-args
[OPENJDK-1548] [rhel-8] unset MAVEN_ARGS for Maven (and OPENJDK-2068, OPENJDK-2069)
2 parents 375df40 + a28fe84 commit 662e0e8

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

modules/maven/default/artifacts/opt/jboss/container/maven/default/maven.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ function maven_build() {
8181
log_info "Using MAVEN_OPTS ${MAVEN_OPTS}"
8282
log_info "Using $(mvn $MAVEN_ARGS --version)"
8383
log_info "Running 'mvn $MAVEN_ARGS $goals'"
84-
# Execute the actual build
85-
mvn $MAVEN_ARGS $goals
84+
85+
# Execute the actual build (ensuring MAVEN_ARGS is unset, OPENJDK-1548)
86+
REAL_MAVEN_ARGS="$MAVEN_ARGS"
87+
unset MAVEN_ARGS
88+
mvn $REAL_MAVEN_ARGS $goals
8689

8790
popd &> /dev/null
8891

tests/OPENJDK-1548/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Test for OPENJDK-1548
2+
3+
<https://issues.redhat.com/browse/OPENJDK-1548>
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-1548/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>

tests/features/java/java_s2i.feature

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,37 @@ Feature: Openshift OpenJDK S2I tests
293293
Given s2i build https://github.com/jboss-openshift/openshift-examples from spring-boot-sample-simple/target
294294
Then s2i build log should not contain skipping directory .
295295
And run find /deployments in container and check its output for spring-boot-sample-simple-1.5.0.BUILD-SNAPSHOT.jar
296+
297+
# OPENJDK-2069 - MAVEN_REPOS
298+
Scenario: run the s2i and check the maven mirror and proxy have been initialised in the default settings.xml, uses http_proxy
299+
Given s2i build https://github.com/jboss-openshift/openshift-examples from spring-boot-sample-simple/target
300+
| variable | value |
301+
| MAVEN_REPOS | TESTREPO,ANOTHER |
302+
| TESTREPO_MAVEN_REPO_URL | http://repo.example.com:8080/maven2/ |
303+
| TESTREPO_MAVEN_REPO_ID | myrepo |
304+
| ANOTHER_MAVEN_REPO_URL | https://repo.example.org:8888/ |
305+
| ANOTHER_MAVEN_REPO_ID | another |
306+
And XML namespaces
307+
| prefix | url |
308+
| ns | http://maven.apache.org/SETTINGS/1.0.0 |
309+
Then XML file /tmp/artifacts/configuration/settings.xml should have 1 elements on XPath //ns:server[ns:id='myrepo']
310+
Then XML file /tmp/artifacts/configuration/settings.xml should have 1 elements on XPath //ns:profile[ns:id='myrepo-profile']/ns:repositories/ns:repository[ns:url='http://repo.example.com:8080/maven2/']
311+
Then XML file /tmp/artifacts/configuration/settings.xml should have 1 elements on XPath //ns:server[ns:id='another']
312+
Then XML file /tmp/artifacts/configuration/settings.xml should have 1 elements on XPath //ns:profile[ns:id='another-profile']/ns:repositories/ns:repository[ns:url='https://repo.example.org:8888/']
313+
314+
# OPENJDK-2068: MAVEN_REPO_URL and MAVEN_REPO_ID
315+
Scenario: Check MAVEN_REPO_URL generates Maven settings and profile configuration
316+
Given s2i build https://github.com/jboss-openshift/openshift-examples from spring-boot-sample-simple/target
317+
| variable | value |
318+
| MAVEN_REPO_URL | http://repo.example.com:8080/maven2/ |
319+
| MAVEN_REPO_ID | myrepo |
320+
And XML namespaces
321+
| prefix | url |
322+
| ns | http://maven.apache.org/SETTINGS/1.0.0 |
323+
Then XML file /tmp/artifacts/configuration/settings.xml should have 1 elements on XPath //ns:server[ns:id='myrepo']
324+
Then XML file /tmp/artifacts/configuration/settings.xml should have 1 elements on XPath //ns:profile[ns:id='myrepo-profile']/ns:repositories/ns:repository[ns:url='http://repo.example.com:8080/maven2/']
325+
326+
Scenario: Ensure the environment is cleaned when executing mvn (OPENJDK-1548)
327+
Given s2i build https://github.com/jmtd/openjdk from tests/OPENJDK-1548 with env using OPENJDK-1548-maven-args
328+
| variable | value |
329+
| MAVEN_ARGS | validate |

0 commit comments

Comments
 (0)