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:25 UTC
(maven) 16/16: Leverage MNG-2520: use mvn --up instead of mvnup script in IT
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 07c53d2cb503338ebf0bf14e90e648654c0c06a5
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Aug 28 15:33:10 2026 +0200
Leverage MNG-2520: use mvn --up instead of mvnup script in IT
Now that MavenCling is the hardcoded entry point (#12875) and delegates
via maven.mainClass, the IT can use "mvn --up" instead of the separate
"mvnup" script. This eliminates the chmod workaround for CI environments
where zip extraction loses Unix execute permissions.
Also use orElseGet for optional element creation (review feedback).
Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
.../invoker/mvnup/goals/ToolchainPluginStrategy.java | 10 ++--------
.../it/MavenITMvnupToolchainPluginStrategyTest.java | 19 +++++++++----------
2 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/ToolchainPluginStrategy.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/ToolchainPluginStrategy.java
index 82028835b3..9db93a51a2 100644
--- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/ToolchainPluginStrategy.java
+++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/ToolchainPluginStrategy.java
@@ -327,14 +327,8 @@ private boolean hasSelectGoalInPluginSection(Element pluginsElement) {
*/
void addToolchainsPlugin(Document pomDocument, int maxJdkVersion) {
Element root = pomDocument.root();
- Element build = root.childElement(BUILD).orElse(null);
- if (build == null) {
- build = DomUtils.insertNewElement(BUILD, root);
- }
- Element plugins = build.childElement(PLUGINS).orElse(null);
- if (plugins == null) {
- plugins = DomUtils.insertNewElement(PLUGINS, build);
- }
+ Element build = root.childElement(BUILD).orElseGet(() -> DomUtils.insertNewElement(BUILD, root));
+ Element plugins = build.childElement(PLUGINS).orElseGet(() -> DomUtils.insertNewElement(PLUGINS, build));
Element plugin = DomUtils.createPlugin(plugins, TOOLCHAINS_PLUGIN_GROUP_ID, MAVEN_TOOLCHAINS_PLUGIN, null);
Element executions = DomUtils.insertNewElement("executions", plugin);
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
index 944e6a43d8..a2481bf740 100644
--- 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
@@ -20,7 +20,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
@@ -29,11 +28,16 @@
/**
* Integration test for the {@code ToolchainPluginStrategy} in {@code mvnup}.
* <p>
- * Verifies that running {@code mvnup apply} on a project with an old
+ * Verifies that running {@code mvn --up 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.
+ * <p>
+ * Uses {@code mvn --up} instead of the {@code mvnup} script directly.
+ * The {@code --up} flag is handled by the {@code mvn} launcher script
+ * which sets {@code -Dmaven.mainClass=MavenUpCling}, and {@code MavenCling}
+ * (the default entry point since MNG-2520) delegates to it.
*
* @since 4.1.0
*/
@@ -48,17 +52,12 @@ class MavenITMvnupToolchainPluginStrategyTest extends AbstractMavenIntegrationTe
void testMvnupAddsToolchainsPluginForOldSourceLevel() throws Exception {
Path testDir = extractResources("mvnup-toolchain-plugin-strategy");
- // Ensure mvnup script is executable (zip extraction may lose permissions on some CI environments)
- Path mvnupBin = Paths.get(System.getProperty("maven.home"), "bin", "mvnup");
- if (Files.exists(mvnupBin)) {
- mvnupBin.toFile().setExecutable(true);
- }
-
// First run — should add the plugin
+ // Use "mvn --up" to invoke mvnup via the MavenCling delegation (MNG-2520)
Verifier verifier = newVerifier(testDir);
verifier.setForkJvm(true);
verifier.setLogFileName("first-run.txt");
- verifier.setExecutable("mvnup");
+ verifier.addCliArgument("--up");
verifier.addCliArgument("apply");
verifier.addCliArgument("-d");
verifier.addCliArgument(testDir.toString());
@@ -84,7 +83,7 @@ void testMvnupAddsToolchainsPluginForOldSourceLevel() throws Exception {
verifier = newVerifier(testDir);
verifier.setForkJvm(true);
verifier.setLogFileName("second-run.txt");
- verifier.setExecutable("mvnup");
+ verifier.addCliArgument("--up");
verifier.addCliArgument("apply");
verifier.addCliArgument("-d");
verifier.addCliArgument(testDir.toString());