From d2c86751bdfce1d2569c564cf140c3c31de27db0 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 22 Jul 2026 15:21:43 +0000 Subject: [PATCH] Add integration test for SelectJdkToolchainMojo version range matching Refs #167 Add an integration test that verifies the select-jdk-toolchain goal correctly matches a toolchain version against a version range requirement. The test configures a JDK toolchain with version "11" and requests version range "[11,17)". If the version matching in SelectJdkToolchainMojo.matches() were broken, the build would fail with "Cannot find matching toolchain definitions". Uses reflection-free approach via maven-invoker-plugin integration test to exercise the full plugin execution path. --- .../invoker.properties | 19 +++++++ .../pom.xml | 51 +++++++++++++++++++ .../toolchains.xml | 32 ++++++++++++ .../verify.groovy | 27 ++++++++++ 4 files changed, 129 insertions(+) create mode 100644 src/it/select-jdk-toolchain-version-range/invoker.properties create mode 100644 src/it/select-jdk-toolchain-version-range/pom.xml create mode 100644 src/it/select-jdk-toolchain-version-range/toolchains.xml create mode 100644 src/it/select-jdk-toolchain-version-range/verify.groovy diff --git a/src/it/select-jdk-toolchain-version-range/invoker.properties b/src/it/select-jdk-toolchain-version-range/invoker.properties new file mode 100644 index 0000000..c70b205 --- /dev/null +++ b/src/it/select-jdk-toolchain-version-range/invoker.properties @@ -0,0 +1,19 @@ +# 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 = --toolchains toolchains.xml -Dtoolchain.jdk.version=[11,17) -Dtoolchain.jdk.discover=false -Dtoolchain.jdk.mode=Never compile +invoker.maven.version = 3.0+ diff --git a/src/it/select-jdk-toolchain-version-range/pom.xml b/src/it/select-jdk-toolchain-version-range/pom.xml new file mode 100644 index 0000000..3e44c80 --- /dev/null +++ b/src/it/select-jdk-toolchain-version-range/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + + org.apache.maven.plugins.toolchains.its + select-jdk-toolchain-version-range + 1.0-SNAPSHOT + jar + + maven-toolchains-plugin IT: select jdk toolchain with version range + Check that the select-jdk-toolchain goal correctly matches a toolchain version against a version range requirement + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-toolchains-plugin + @project.version@ + + + + select-jdk-toolchain + + + + + + + diff --git a/src/it/select-jdk-toolchain-version-range/toolchains.xml b/src/it/select-jdk-toolchain-version-range/toolchains.xml new file mode 100644 index 0000000..db207a6 --- /dev/null +++ b/src/it/select-jdk-toolchain-version-range/toolchains.xml @@ -0,0 +1,32 @@ + + + + + jdk + + 11 + test-vendor + + + /usr/lib/jvm/default-java + + + diff --git a/src/it/select-jdk-toolchain-version-range/verify.groovy b/src/it/select-jdk-toolchain-version-range/verify.groovy new file mode 100644 index 0000000..28e2166 --- /dev/null +++ b/src/it/select-jdk-toolchain-version-range/verify.groovy @@ -0,0 +1,27 @@ +/* + * 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. + */ + +content = new File(basedir, 'build.log').text + +// Verify that the version range requirement was parsed correctly +assert content.contains("Required toolchain: jdk [ version='[11,17)' ]") + +// Verify that a matching toolchain was selected (if matching is broken, the build would fail +// with "Cannot find matching toolchain definitions") +assert content.contains('Selected JDK toolchain:')