You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/08/29 19:15:21 UTC

(maven) 12/16: Add integration test for mvnup ToolchainPluginStrategy

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

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git

commit e3370d55f1d55167a5b59be3f1dc2e718b0f8cb0
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Wed Aug 5 23:57:19 2026 +0200

    Add integration test for mvnup ToolchainPluginStrategy
    
    Tests the full end-to-end flow: mvnup apply on a POM with
    maven.compiler.source=1.5 adds the maven-toolchains-plugin with
    select-jdk-toolchain goal and version constraint (,8], then verifies
    a second run is idempotent.
    
    Also adds mvnup to the chmod list in the IT suite's antrun config
    so it gets execute permission when extracted from the zip.
    
    Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
 its/core-it-suite/pom.xml                          |  6 +-
 .../MavenITMvnupToolchainPluginStrategyTest.java   | 88 ++++++++++++++++++++++
 .../mvnup-toolchain-plugin-strategy/pom.xml        | 12 +++
 3 files changed, 103 insertions(+), 3 deletions(-)

diff --git a/its/core-it-suite/pom.xml b/its/core-it-suite/pom.xml
index 8c087800a6..53e39f6986 100644
--- a/its/core-it-suite/pom.xml
+++ b/its/core-it-suite/pom.xml
@@ -519,7 +519,7 @@ under the License.
                 <unzip dest="${mavenHome}" src="${maven.multiModuleProjectDirectory}/apache-maven/target/apache-maven-${project.version}-bin.zip">
                   <regexpmapper from="^([^/]+)/(.*)$" handledirsep="true" to="\2" />
                 </unzip>
-                <chmod dir="${mavenHome}/bin" includes="mvn,mvnDebug,mvnenc" perm="ugo+rx" />
+                <chmod dir="${mavenHome}/bin" includes="mvn,mvnDebug,mvnenc,mvnup" perm="ugo+rx" />
               </target>
             </configuration>
           </execution>
@@ -805,7 +805,7 @@ under the License.
                     <unzip dest="${mavenHome}" src="${project.build.directory}/maven-bin.zip">
                       <globmapper from="apache-maven-${mavenVersion}/*" handledirsep="true" to="*" />
                     </unzip>
-                    <chmod dir="${mavenHome}/bin" includes="mvn,mvnDebug,mvnenc" perm="ugo+rx" />
+                    <chmod dir="${mavenHome}/bin" includes="mvn,mvnDebug,mvnenc,mvnup" perm="ugo+rx" />
                   </target>
                 </configuration>
               </execution>
@@ -860,7 +860,7 @@ under the License.
                     <unzip dest="${mavenHome}" src="${mavenDistro}">
                       <regexpmapper from="^([^/]+)/(.*)$" handledirsep="true" to="\2" />
                     </unzip>
-                    <chmod dir="${mavenHome}/bin" includes="mvn,mvnDebug,mvnenc" perm="ugo+rx" />
+                    <chmod dir="${mavenHome}/bin" includes="mvn,mvnDebug,mvnenc,mvnup" perm="ugo+rx" />
                   </target>
                 </configuration>
               </execution>
diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITMvnupToolchainPluginStrategyTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITMvnupToolchainPluginStrategyTest.java
new file mode 100644
index 0000000000..718b6db66d
--- /dev/null
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITMvnupToolchainPluginStrategyTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+package org.apache.maven.it;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Integration test for the {@code ToolchainPluginStrategy} in {@code mvnup}.
+ * <p>
+ * Verifies that running {@code mvnup apply} on a project with an old
+ * {@code --source} level (unsupported by the running JDK) automatically adds
+ * the {@code maven-toolchains-plugin} with the {@code select-jdk-toolchain}
+ * goal and the correct {@code <version>} constraint, and that a second run
+ * is idempotent.
+ *
+ * @since 4.1.0
+ */
+class MavenITMvnupToolchainPluginStrategyTest extends AbstractMavenIntegrationTestCase {
+
+    /**
+     * Verify that mvnup adds the maven-toolchains-plugin with select-jdk-toolchain
+     * goal and version constraint when the project's source level is unsupported
+     * by the running JDK, and that a second run is idempotent.
+     */
+    @Test
+    void testMvnupAddsToolchainsPluginForOldSourceLevel() throws Exception {
+        Path testDir = extractResources("mvnup-toolchain-plugin-strategy");
+
+        // First run — should add the plugin
+        Verifier verifier = newVerifier(testDir);
+        verifier.setForkJvm(true);
+        verifier.setLogFileName("first-run.txt");
+        verifier.setExecutable("mvnup");
+        verifier.addCliArgument("apply");
+        verifier.addCliArgument("-d");
+        verifier.addCliArgument(testDir.toString());
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+
+        // Verify mvnup reported adding the plugin
+        verifier.verifyTextInLog("Added maven-toolchains-plugin with select-jdk-toolchain goal");
+
+        // Verify the POM was modified to include the toolchains plugin
+        String pomContent = Files.readString(testDir.resolve("pom.xml"));
+        assertTrue(
+                pomContent.contains("maven-toolchains-plugin"),
+                "POM should contain maven-toolchains-plugin after mvnup apply");
+        assertTrue(
+                pomContent.contains("select-jdk-toolchain"),
+                "POM should contain select-jdk-toolchain goal after mvnup apply");
+        assertTrue(
+                pomContent.contains("<version>(,8]</version>"),
+                "POM should contain version constraint (,8] for source 5 after mvnup apply");
+
+        // Second run — should be idempotent (skip, already present)
+        verifier = newVerifier(testDir);
+        verifier.setForkJvm(true);
+        verifier.setLogFileName("second-run.txt");
+        verifier.setExecutable("mvnup");
+        verifier.addCliArgument("apply");
+        verifier.addCliArgument("-d");
+        verifier.addCliArgument(testDir.toString());
+        verifier.execute();
+        verifier.verifyErrorFreeLog();
+        verifier.verifyTextInLog("maven-toolchains-plugin with select-jdk-toolchain goal already configured");
+    }
+}
diff --git a/its/core-it-suite/src/test/resources/mvnup-toolchain-plugin-strategy/pom.xml b/its/core-it-suite/src/test/resources/mvnup-toolchain-plugin-strategy/pom.xml
new file mode 100644
index 0000000000..6fa0b3dc18
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mvnup-toolchain-plugin-strategy/pom.xml
@@ -0,0 +1,12 @@
+<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>com.example</groupId>
+    <artifactId>old-source-test</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <properties>
+        <maven.compiler.source>1.5</maven.compiler.source>
+        <maven.compiler.target>1.5</maven.compiler.target>
+    </properties>
+</project>