This is an automated email from the ASF dual-hosted git repository.

slawekjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-toolchains-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new ad7956b  Fix matching against one of multiple env-variables pointing 
to one JDK (#148)
ad7956b is described below

commit ad7956b4751baed1145126ba98dbc98bf83ff1a9
Author: Hannes Wellmann <[email protected]>
AuthorDate: Sat Jul 11 14:04:15 2026 -0300

    Fix matching against one of multiple env-variables pointing to one JDK 
(#148)
    
    * 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.
    
    * Add comments to clarify JAVA_HOME property usage
    
    ---------
    
    Co-authored-by: Slawomir Jaranowski <[email protected]>
---
 pom.xml                                            |  2 +
 src/it/select-jdk-env-multi/invoker.properties     | 20 ++++++++
 src/it/select-jdk-env-multi/pom.xml                | 54 ++++++++++++++++++++++
 .../toolchain/jdk/SelectJdkToolchainMojo.java      |  2 +-
 4 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 0e5e656..1121812 100644
--- a/pom.xml
+++ b/pom.xml
@@ -70,6 +70,8 @@ under the License.
     <javaVersion>8</javaVersion>
     <mavenVersion>3.9.16</mavenVersion>
     
<project.build.outputTimestamp>2024-04-18T00:34:08Z</project.build.outputTimestamp>
+    <!-- property used in src/it/select-jdk-env-multi/invoker.properties -->
+    <JAVA_HOME>${env.JAVA_HOME}</JAVA_HOME>
   </properties>
 
   <dependencies>
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..9d5da15
--- /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}
+invoker.environmentVariables.JAVA_Y_HOME = ${JAVA_HOME}
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..a2b0b49
--- /dev/null
+++ b/src/it/select-jdk-env-multi/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<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.apache.maven.plugins.toolchains.its</groupId>
+  <artifactId>select-jdk-env-multi</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>maven-toolchains-plugin IT: select jdk toolchain test with environment 
variable</name>
+  <description>Check that jdk toolchain can be selected when multiple 
environment variables are used</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-toolchains-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <env>JAVA_X_HOME</env>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>select-jdk-toolchain</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
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 77a79a1..70a6c2b 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 @@ public class SelectJdkToolchainMojo extends AbstractMojo {
             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);
         }

Reply via email to