From c6c5eb0d22b7daff24020a7aeb7955fcb4279394 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 3 Sep 2026 06:17:50 +0000 Subject: [PATCH] Adapt ITs for restricted interpolation of repository-resolved models Maven 3.10.x commit 03c947d820 restricts property interpolation for models built at VALIDATION_LEVEL_MINIMAL (dependency, parent and BOM-import POMs). User, system and environment properties are no longer resolved in those models by default. Each of the 4 affected ITs (IT0085, MNG-3586, MNG-4379, MNG-4590) is updated with: 1. A version-gated branch in the original test method: on 3.10.0-rc-1 or earlier, the test expects the old behavior (full interpolation without opt-out); on later versions, it verifies that the build fails without the opt-out flag. 2. A new test method that explicitly passes -Dmaven.model.dependencyInterpolation.full=true and verifies the opt-out works correctly on all versions. Since AbstractMavenIntegrationTestCase.removePattern() strips RC qualifiers (both rc-1 and rc-2 become 3.10.0), the version guard uses a combination of getMavenVersion().toString().equals("3.10.0-rc-1") and matchesVersionRange("(,3.10.0)") to correctly distinguish rc-1 from later versions. --- .../MavenIT0085TransitiveSystemScopeTest.java | 43 ++++++++++++++++ ...ng3586SystemScopePluginDependencyTest.java | 47 +++++++++++++++++ ...eSystemPathInterpolatedWithEnvVarTest.java | 46 +++++++++++++++++ ...tedPomUsesSystemAndUserPropertiesTest.java | 51 +++++++++++++++++++ 4 files changed, 187 insertions(+) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0085TransitiveSystemScopeTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0085TransitiveSystemScopeTest.java index 6f7d0825b..33da96873 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0085TransitiveSystemScopeTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenIT0085TransitiveSystemScopeTest.java @@ -21,6 +21,7 @@ import java.io.File; import java.util.Collection; +import org.apache.maven.shared.verifier.VerificationException; import org.apache.maven.shared.verifier.Verifier; import org.apache.maven.shared.verifier.util.ResourceExtractor; import org.junit.jupiter.api.Test; @@ -35,6 +36,10 @@ public MavenIT0085TransitiveSystemScopeTest() { * when they are resolved transitively via another (non-system) * dependency. Inherited scope should not apply in the case of * system-scoped dependencies, no matter where they are. + *

+ * Since 3.10.0-rc-2, repository-resolved models restrict property + * interpolation by default, so the opt-out flag is required for the + * legacy behavior and the default behavior causes a build failure. * * @throws Exception in case of failure */ @@ -51,6 +56,44 @@ public void testit0085() throws Exception { verifier.addCliArgument("--settings"); verifier.addCliArgument("settings.xml"); verifier.addCliArgument("validate"); + + String mavenVersion = getMavenVersion() != null ? getMavenVersion().toString() : ""; + if (mavenVersion.equals("3.10.0-rc-1") || matchesVersionRange("(,3.10.0)")) { + // Before restricted interpolation: full interpolation works without opt-out + verifier.execute(); + verifier.verifyErrorFreeLog(); + } else { + // With restricted interpolation: build fails without opt-out + try { + verifier.execute(); + verifier.verifyErrorFreeLog(); + fail("Build should not succeed without -Dmaven.model.dependencyInterpolation.full=true"); + } catch (VerificationException e) { + verifier.verifyTextInLog("must specify an absolute path but is ${test.home}/system.jar"); + } + } + } + + /** + * Verify that system-scoped dependencies work correctly when the opt-out + * property {@code -Dmaven.model.dependencyInterpolation.full=true} is set. + * + * @throws Exception in case of failure + */ + @Test + public void testit0085WithFullInterpolation() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/it0085"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setAutoclean(false); + verifier.deleteDirectory("target"); + verifier.deleteArtifacts("org.apache.maven.its.it0085"); + verifier.getSystemProperties().setProperty("test.home", testDir.getAbsolutePath()); + verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8"); + verifier.addCliArgument("--settings"); + verifier.addCliArgument("settings.xml"); + verifier.addCliArgument("validate"); + verifier.addCliArgument("-Dmaven.model.dependencyInterpolation.full=true"); verifier.execute(); verifier.verifyErrorFreeLog(); diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3586SystemScopePluginDependencyTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3586SystemScopePluginDependencyTest.java index f20a99c0b..463f876f5 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3586SystemScopePluginDependencyTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3586SystemScopePluginDependencyTest.java @@ -21,6 +21,7 @@ import java.io.File; import java.util.Properties; +import org.apache.maven.shared.verifier.VerificationException; import org.apache.maven.shared.verifier.Verifier; import org.apache.maven.shared.verifier.util.ResourceExtractor; import org.junit.jupiter.api.Test; @@ -40,6 +41,10 @@ public MavenITmng3586SystemScopePluginDependencyTest() { /** * Test that plugin dependencies with scope system are part of the plugin class realm. This test checks * dependencies that are declared in the plugin POM. + *

+ * Since 3.10.0-rc-2, repository-resolved models restrict property + * interpolation by default, so the opt-out flag is required for the + * legacy behavior and the default behavior causes a build failure. * * @throws Exception in case of failure */ @@ -56,6 +61,48 @@ public void testitFromPlugin() throws Exception { verifier.addCliArgument("--settings"); verifier.addCliArgument("settings.xml"); verifier.addCliArgument("validate"); + + String mavenVersion = getMavenVersion() != null ? getMavenVersion().toString() : ""; + if (mavenVersion.equals("3.10.0-rc-1") || matchesVersionRange("(,3.10.0)")) { + // Before restricted interpolation: full interpolation works without opt-out + verifier.execute(); + verifier.verifyErrorFreeLog(); + + Properties props = verifier.loadProperties("target/it.properties"); + assertEquals("PASSED", props.getProperty("test")); + } else { + // With restricted interpolation: build fails without opt-out + try { + verifier.execute(); + verifier.verifyErrorFreeLog(); + fail("Build should not succeed without -Dmaven.model.dependencyInterpolation.full=true"); + } catch (VerificationException e) { + verifier.verifyTextInLog("must specify an absolute path but is ${test.home}/tools.jar"); + } + } + } + + /** + * Test that plugin dependencies with scope system are part of the plugin class realm when the + * opt-out property {@code -Dmaven.model.dependencyInterpolation.full=true} is set. + * This test checks dependencies that are declared in the plugin POM. + * + * @throws Exception in case of failure + */ + @Test + public void testitFromPluginWithFullInterpolation() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3586/test-1"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setAutoclean(false); + verifier.deleteDirectory("target"); + verifier.deleteArtifacts("org.apache.maven.its.mng3586"); + verifier.getSystemProperties().setProperty("test.home", testDir.getAbsolutePath()); + verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8"); + verifier.addCliArgument("--settings"); + verifier.addCliArgument("settings.xml"); + verifier.addCliArgument("validate"); + verifier.addCliArgument("-Dmaven.model.dependencyInterpolation.full=true"); verifier.execute(); verifier.verifyErrorFreeLog(); diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4379TransitiveSystemPathInterpolatedWithEnvVarTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4379TransitiveSystemPathInterpolatedWithEnvVarTest.java index 733eeb80b..2fc3ccc92 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4379TransitiveSystemPathInterpolatedWithEnvVarTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4379TransitiveSystemPathInterpolatedWithEnvVarTest.java @@ -21,6 +21,7 @@ import java.io.File; import java.util.List; +import org.apache.maven.shared.verifier.VerificationException; import org.apache.maven.shared.verifier.Verifier; import org.apache.maven.shared.verifier.util.ResourceExtractor; import org.junit.jupiter.api.Test; @@ -39,6 +40,10 @@ public MavenITmng4379TransitiveSystemPathInterpolatedWithEnvVarTest() { /** * Test that the path of a system-scope dependency gets interpolated using environment variables during * transitive dependency resolution. + *

+ * Since 3.10.0-rc-2, repository-resolved models restrict property + * interpolation by default, so the opt-out flag is required for the + * legacy behavior and the default behavior causes a build failure. * * @throws Exception in case of failure */ @@ -55,6 +60,47 @@ public void testit() throws Exception { verifier.addCliArgument("-s"); verifier.addCliArgument("settings.xml"); verifier.addCliArguments("validate"); + + String mavenVersion = getMavenVersion() != null ? getMavenVersion().toString() : ""; + if (mavenVersion.equals("3.10.0-rc-1") || matchesVersionRange("(,3.10.0)")) { + // Before restricted interpolation: env var interpolation works without opt-out + verifier.execute(); + verifier.verifyErrorFreeLog(); + + List classpath = verifier.loadLines("target/classpath.txt", "UTF-8"); + assertTrue(classpath.toString(), classpath.contains("pom.xml")); + } else { + // With restricted interpolation: build fails without opt-out + try { + verifier.execute(); + verifier.verifyErrorFreeLog(); + fail("Build should not succeed without -Dmaven.model.dependencyInterpolation.full=true"); + } catch (VerificationException e) { + verifier.verifyTextInLog("must specify an absolute path but is ${env.MNG_4379_HOME}/pom.xml"); + } + } + } + + /** + * Test that the path of a system-scope dependency gets interpolated using environment variables when + * the opt-out property {@code -Dmaven.model.dependencyInterpolation.full=true} is set. + * + * @throws Exception in case of failure + */ + @Test + public void testitWithFullInterpolation() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4379"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setAutoclean(false); + verifier.deleteDirectory("target"); + verifier.deleteArtifacts("org.apache.maven.its.mng4379"); + verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8"); + verifier.setEnvironmentVariable("MNG_4379_HOME", testDir.getAbsolutePath()); + verifier.addCliArgument("-s"); + verifier.addCliArgument("settings.xml"); + verifier.addCliArguments("validate"); + verifier.addCliArgument("-Dmaven.model.dependencyInterpolation.full=true"); verifier.execute(); verifier.verifyErrorFreeLog(); diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4590ImportedPomUsesSystemAndUserPropertiesTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4590ImportedPomUsesSystemAndUserPropertiesTest.java index 49419ed81..629b32843 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4590ImportedPomUsesSystemAndUserPropertiesTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4590ImportedPomUsesSystemAndUserPropertiesTest.java @@ -21,6 +21,7 @@ import java.io.File; import java.util.Properties; +import org.apache.maven.shared.verifier.VerificationException; import org.apache.maven.shared.verifier.Verifier; import org.apache.maven.shared.verifier.util.ResourceExtractor; import org.junit.jupiter.api.Test; @@ -38,6 +39,10 @@ public MavenITmng4590ImportedPomUsesSystemAndUserPropertiesTest() { /** * Verify that imported POMs are processed using the same system/user properties as the importing POM. + *

+ * Since 3.10.0-rc-2, repository-resolved models restrict property + * interpolation by default, so the opt-out flag is required for the + * legacy behavior and the default behavior causes a build failure. * * @throws Exception in case of failure */ @@ -55,6 +60,52 @@ public void testit() throws Exception { verifier.addCliArgument("--settings"); verifier.addCliArgument("settings.xml"); verifier.addCliArgument("validate"); + + String mavenVersion = getMavenVersion() != null ? getMavenVersion().toString() : ""; + if (mavenVersion.equals("3.10.0-rc-1") || matchesVersionRange("(,3.10.0)")) { + // Before restricted interpolation: full interpolation works without opt-out + verifier.execute(); + verifier.verifyErrorFreeLog(); + + Properties props = verifier.loadProperties("target/pom.properties"); + assertEquals("1", props.getProperty("project.dependencyManagement.dependencies")); + assertEquals("dep-a", props.getProperty("project.dependencyManagement.dependencies.0.artifactId")); + assertEquals( + new File(testDir, "pom.xml").getAbsoluteFile(), + new File(props.getProperty("project.dependencyManagement.dependencies.0.systemPath"))); + } else { + // With restricted interpolation: build fails without opt-out + try { + verifier.execute(); + verifier.verifyErrorFreeLog(); + fail("Build should not succeed without -Dmaven.model.dependencyInterpolation.full=true"); + } catch (VerificationException e) { + verifier.verifyTextInLog("must specify an absolute path but is ${test.dir}/${test.file}"); + } + } + } + + /** + * Verify that imported POMs are processed using the same system/user properties as the importing POM + * when the opt-out property {@code -Dmaven.model.dependencyInterpolation.full=true} is set. + * + * @throws Exception in case of failure + */ + @Test + public void testitWithFullInterpolation() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-4590"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setAutoclean(false); + verifier.deleteDirectory("target"); + verifier.deleteArtifacts("org.apache.maven.its.mng4590"); + verifier.filterFile("settings-template.xml", "settings.xml", "UTF-8"); + verifier.setEnvironmentVariable("MAVEN_OPTS", "-Dtest.file=pom.xml"); + verifier.addCliArgument("-Dtest.dir=" + testDir.getAbsolutePath()); + verifier.addCliArgument("--settings"); + verifier.addCliArgument("settings.xml"); + verifier.addCliArgument("validate"); + verifier.addCliArgument("-Dmaven.model.dependencyInterpolation.full=true"); verifier.execute(); verifier.verifyErrorFreeLog();