Skip to content

Commit 127929a

Browse files
committed
Fix integration tests to properly validate unresolved repository expressions
- Remove premature expression validation from model validator - Allow expressions to pass through model validation and fail at repository resolution time - Update integration tests to use dependency:resolve instead of validate to trigger repository usage - Add -e flag to integration tests to capture suppressed exception messages - Update test expectations to match the corrected validation flow The previous approach was rejecting expressions during model validation, but the correct behavior is to allow expressions to pass through and fail when repositories are actually used during dependency resolution. This matches the intended design where the MavenValidator in the resolver catches uninterpolated expressions with the proper error message.
1 parent 8ffdecd commit 127929a

File tree

4 files changed

+21
-31
lines changed

4 files changed

+21
-31
lines changed

impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,29 +1590,18 @@ private void validateRawRepository(
15901590
validateStringNotEmpty(
15911591
prefix, prefix2, "id", problems, Severity.ERROR, Version.V20, repository.getId(), null, repository);
15921592

1593-
if (!allowEmptyUrl
1594-
&& validateStringNotEmpty(
1595-
prefix,
1596-
prefix2,
1597-
"[" + repository.getId() + "].url",
1598-
problems,
1599-
Severity.ERROR,
1600-
Version.V20,
1601-
repository.getUrl(),
1602-
null,
1603-
repository)) {
1604-
// Check for uninterpolated expressions - these should have been interpolated by now
1605-
Matcher matcher = EXPRESSION_NAME_PATTERN.matcher(repository.getUrl());
1606-
if (matcher.find()) {
1607-
addViolation(
1608-
problems,
1609-
Severity.ERROR,
1610-
Version.V40,
1611-
prefix + prefix2 + "[" + repository.getId() + "].url",
1612-
null,
1613-
"contains an uninterpolated expression.",
1614-
repository);
1615-
}
1593+
if (!allowEmptyUrl) {
1594+
validateStringNotEmpty(
1595+
prefix,
1596+
prefix2,
1597+
"[" + repository.getId() + "].url",
1598+
problems,
1599+
Severity.ERROR,
1600+
Version.V20,
1601+
repository.getUrl(),
1602+
null,
1603+
repository);
1604+
// Repository URL interpolation is allowed; unresolved placeholders will fail later during resolution
16161605
}
16171606
}
16181607

impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelValidatorTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -895,16 +895,15 @@ void repositoryWithExpression() throws Exception {
895895
@Test
896896
void repositoryWithBasedirExpression() throws Exception {
897897
SimpleProblemCollector result = validateRaw("raw-model/repository-with-basedir-expression.xml");
898-
// This test runs on raw model without interpolation, so all expressions appear uninterpolated
899-
// In the real flow, supported expressions would be interpolated before validation
900-
assertViolations(result, 0, 3, 0);
898+
// Repository URL interpolation is allowed; unresolved placeholders will fail later during resolution
899+
assertViolations(result, 0, 0, 0);
901900
}
902901

903902
@Test
904903
void repositoryWithUnsupportedExpression() throws Exception {
905904
SimpleProblemCollector result = validateRaw("raw-model/repository-with-unsupported-expression.xml");
906-
// Unsupported expressions should cause validation errors
907-
assertViolations(result, 0, 1, 0);
905+
// Repository URL interpolation is allowed; unresolved placeholders will fail later during resolution
906+
assertViolations(result, 0, 0, 0);
908907
}
909908

910909
@Test

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11140RepoDmUnresolvedTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ void testFailsOnUnresolvedPlaceholders() throws Exception {
3737
Verifier verifier = newVerifier(testDir.getAbsolutePath());
3838

3939
try {
40-
verifier.addCliArgument("validate");
40+
verifier.addCliArgument("-e");
41+
verifier.addCliArgument("dependency:resolve");
4142
verifier.execute();
4243
} catch (VerificationException expected) {
43-
// Expected to fail
44+
// Expected to fail due to unresolved placeholders reaching repository construction
4445
}
4546
// We expect some error mentioning 'Not fully interpolated remote repository' or similar
4647
verifier.verifyTextInLog("Not fully interpolated remote repository");

its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh11140RepoInterpolationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ void testUnresolvedPlaceholderFailsResolution() throws Exception {
7878
Verifier verifier = newVerifier(testDir.getAbsolutePath());
7979

8080
// Do NOT set env vars, so placeholders stay
81-
verifier.addCliArgument("validate");
81+
verifier.addCliArgument("-e");
82+
verifier.addCliArgument("dependency:resolve");
8283
try {
8384
verifier.execute();
8485
} catch (VerificationException expected) {

0 commit comments

Comments
 (0)