From c78106136d73395906457c4caa67957b2ea6faa9 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Wed, 11 Mar 2026 00:45:33 +0100 Subject: [PATCH] Fix matching against one of multiple env-variables pointing to one JDK The arguments when matching the collected env-variables pointing to one JDK against the required one were mistakenly swapped. This had the effect that the 'env'-variable match always failed when more than one env variable points to the same JDK. --- pom.xml | 30 +++++++++++ .../select-jdk-env-multi/invoker.properties | 20 +++++++ src/it/select-jdk-env-multi/pom.xml | 54 +++++++++++++++++++ .../toolchain/jdk/SelectJdkToolchainMojo.java | 2 +- 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/it/select-jdk-env-multi/invoker.properties create mode 100644 src/it/select-jdk-env-multi/pom.xml diff --git a/pom.xml b/pom.xml index cc61c0a..7f36b04 100644 --- a/pom.xml +++ b/pom.xml @@ -146,4 +146,34 @@ under the License. + + + run-its + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.6.1 + + + sanitize-java-home + + regex-property + + + + java.home.sanitized + ${java.home} + \\ + / + false + + + + + + + + diff --git a/src/it/select-jdk-env-multi/invoker.properties b/src/it/select-jdk-env-multi/invoker.properties new file mode 100644 index 0000000..51759a4 --- /dev/null +++ b/src/it/select-jdk-env-multi/invoker.properties @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals = compile +invoker.environmentVariables.JAVA_X_HOME = ${java.home.sanitized} +invoker.environmentVariables.JAVA_Y_HOME = ${java.home.sanitized} diff --git a/src/it/select-jdk-env-multi/pom.xml b/src/it/select-jdk-env-multi/pom.xml new file mode 100644 index 0000000..89af305 --- /dev/null +++ b/src/it/select-jdk-env-multi/pom.xml @@ -0,0 +1,54 @@ + + + + 4.0.0 + + org.apache.maven.plugins.toolchains.its + select-jdk-toolchain-range + 1.0-SNAPSHOT + jar + + maven-toolchains-plugin IT: select jdk toolchain test with environment variable + Check that jdk toolchain can be selected when multiple environment variables are used + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-toolchains-plugin + @project.version@ + + JAVA_X_HOME + + + + + select-jdk-toolchain + + + + + + + diff --git a/src/main/java/org/apache/maven/plugins/toolchain/jdk/SelectJdkToolchainMojo.java b/src/main/java/org/apache/maven/plugins/toolchain/jdk/SelectJdkToolchainMojo.java index 7a1276a..5614b6d 100644 --- a/src/main/java/org/apache/maven/plugins/toolchain/jdk/SelectJdkToolchainMojo.java +++ b/src/main/java/org/apache/maven/plugins/toolchain/jdk/SelectJdkToolchainMojo.java @@ -255,7 +255,7 @@ private boolean matches(String key, String reqVal, String tcVal) { case VERSION: return RequirementMatcherFactory.createVersionMatcher(tcVal).matches(reqVal); case ENV: - return reqVal.matches("(.*,|^)\\Q" + tcVal + "\\E(,.*|$)"); + return tcVal.matches("(.*,|^)\\Q" + reqVal + "\\E(,.*|$)"); default: return RequirementMatcherFactory.createExactMatcher(tcVal).matches(reqVal); }