Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,24 @@ String doCallback(
return new MavenBuildTimestamp(request.getSession().getStartTime(), model.getProperties())
.formattedTimestamp();
}
// prefixed model reflection
for (String prefix : getProjectPrefixes(request)) {
if (expression.startsWith(prefix)) {
String subExpr = expression.substring(prefix.length());
String v = projectProperty(model, projectDir, subExpr, true);
if (v != null) {
return v;
}
}
}
// user properties
String value = request.getUserProperties().get(expression);
// model properties
// model properties (check before prefixed model reflection to avoid recursion)
if (value == null) {
value = model.getProperties().get(expression);
}
// prefixed model reflection
if (value == null) {
for (String prefix : getProjectPrefixes(request)) {
if (expression.startsWith(prefix)) {
String subExpr = expression.substring(prefix.length());
value = projectProperty(model, projectDir, subExpr, true);
if (value != null) {
return value;
}
}
}
}
// system properties
if (value == null) {
value = request.getSystemProperties().get(expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,26 @@ void shouldIgnorePropertiesWithPomPrefix() throws Exception {
assertEquals(uninterpolatedName, out.getName());
}

@Test
void testProjectUrlPropertyDoesNotCauseRecursion() throws Exception {
// GH-11384: ${project.url} should resolve to the property "project.url" before
// trying to resolve via model reflection, which would cause recursion
Map<String, String> modelProperties = new HashMap<>();
modelProperties.put("project.url", "https://github.com/slackapi/java-slack-sdk");

Model model = Model.newBuilder()
.url("${project.url}")
.properties(modelProperties)
.build();

SimpleProblemCollector collector = new SimpleProblemCollector();
Model out = interpolator.interpolateModel(
model, null, createModelBuildingRequest(context).build(), collector);

assertProblemFree(collector);
assertEquals("https://github.com/slackapi/java-slack-sdk", out.getUrl());
}

@Provides
@Priority(10)
@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.Path;

import org.junit.jupiter.api.Test;

/**
* This is a test set for <a href="https://github.com/apache/maven/issues/11384">GH-11384</a>.
*
* Verifies that ${project.url} can refer to a property named "project.url" without causing
* a recursive variable reference error. This pattern is used by slack-sdk-parent.
*
* @since 4.0.0-rc-4
*/
class MavenITgh11384RecursiveVariableReferenceTest extends AbstractMavenIntegrationTestCase {

/**
* Verify that ${project.url} in the url field can reference a property named project.url
* without causing a recursive variable reference error.
*/
@Test
void testIt() throws Exception {
Path basedir = extractResources("/gh-11384").getAbsoluteFile().toPath();

Verifier verifier = newVerifier(basedir.toString());
verifier.addCliArgument("help:effective-pom");
verifier.execute();
verifier.verifyErrorFreeLog();

// Verify that the URL was correctly interpolated from the property
verifier.verifyTextInLog("<url>https://github.com/slackapi/java-slack-sdk</url>");
}
}

18 changes: 18 additions & 0 deletions its/core-it-suite/src/test/resources/gh-11384/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.1.0" root="true">
<groupId>org.apache.maven.its.mng11384</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<name>Maven Integration Test :: GH-11384</name>
<description>Test that project.url can refer to a property named project.url without causing recursion</description>

<!-- This pattern is used by slack-sdk-parent and should not cause a recursive variable reference error -->
<url>${project.url}</url>

<properties>
<project.url>https://github.com/slackapi/java-slack-sdk</project.url>
</properties>
</project>