This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch maven-deploy-plugin-4.x in repository https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git
commit 6ec98a31e8ede36655500bef54cf32c49ced896c Author: Efe Gökdemir <[email protected]> AuthorDate: Fri Sep 25 21:43:13 2026 +0300 #649: harden pom.properties coordinate resolution Signed-off-by: Efe Gökdemir <[email protected]> --- .../maven/plugins/deploy/DeployFileMojo.java | 25 ++++++--- .../plugins/deploy/DeployFileMojoUnitTest.java | 61 ++++++++++++++++++++++ 2 files changed, 78 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java index 03d12a1..78c1be9 100644 --- a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java +++ b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java @@ -603,16 +603,25 @@ public class DeployFileMojo extends AbstractDeployMojo { } } + /** + * Completes coordinates that remain unresolved after processing the embedded POM. Only pure property references + * are supported; compound expressions such as {@code 1.0-${changelist}} are intentionally left unchanged. The + * replacement values are read from the adjacent {@code pom.properties} file. + * + * @param properties the properties read from the adjacent {@code pom.properties} file + */ void processPomProperties(Properties properties) { - if (isUnresolvedProperty(groupId)) { - groupId = properties.getProperty("groupId", groupId); - } - if (isUnresolvedProperty(artifactId)) { - artifactId = properties.getProperty("artifactId", artifactId); - } - if (isUnresolvedProperty(version)) { - version = properties.getProperty("version", version); + groupId = resolveProperty(properties, "groupId", groupId); + artifactId = resolveProperty(properties, "artifactId", artifactId); + version = resolveProperty(properties, "version", version); + } + + private static String resolveProperty(Properties properties, String name, String currentValue) { + if (!isUnresolvedProperty(currentValue)) { + return currentValue; } + String resolvedValue = properties.getProperty(name); + return resolvedValue == null || resolvedValue.isBlank() ? currentValue : resolvedValue; } private static boolean isUnresolvedProperty(String value) { diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java index 76d6962..7095158 100644 --- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java +++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java @@ -121,6 +121,67 @@ class DeployFileMojoUnitTest { assertEquals("1.2.3", mojo.getVersion()); } + @Test + void processPomPropertiesLeavesResolvedCoordinatesUnchanged() { + mojo.setGroupId("org.original"); + mojo.setArtifactId("original"); + mojo.setVersion("1.0.0"); + Properties properties = new Properties(); + properties.setProperty("groupId", "org.other"); + properties.setProperty("artifactId", "other"); + properties.setProperty("version", "2.0.0"); + + mojo.processPomProperties(properties); + + assertEquals("org.original", mojo.getGroupId()); + assertEquals("original", mojo.getArtifactId()); + assertEquals("1.0.0", mojo.getVersion()); + } + + @Test + void processPomPropertiesResolvesOnlyUnresolvedCoordinates() { + mojo.setGroupId("org.original"); + mojo.setArtifactId("original"); + mojo.setVersion("${revision}"); + Properties properties = new Properties(); + properties.setProperty("groupId", "org.other"); + properties.setProperty("artifactId", "other"); + properties.setProperty("version", "2.0.0"); + + mojo.processPomProperties(properties); + + assertEquals("org.original", mojo.getGroupId()); + assertEquals("original", mojo.getArtifactId()); + assertEquals("2.0.0", mojo.getVersion()); + } + + @Test + void processPomPropertiesLeavesMissingAndBlankValuesUnresolved() { + mojo.setGroupId("${group}"); + mojo.setArtifactId("${artifact}"); + mojo.setVersion("${revision}"); + Properties properties = new Properties(); + properties.setProperty("groupId", "org.example"); + properties.setProperty("version", " "); + + mojo.processPomProperties(properties); + + assertEquals("org.example", mojo.getGroupId()); + assertEquals("${artifact}", mojo.getArtifactId()); + assertEquals("${revision}", mojo.getVersion()); + } + + @Test + void processPomPropertiesLeavesCompoundExpressionsUnchanged() { + mojo.setVersion("1.0-${changelist}"); + Properties properties = new Properties(); + properties.setProperty("version", "2.0.0"); + + mojo.processPomProperties(properties); + + assertEquals("1.0-${changelist}", mojo.getVersion()); + } + private void checkMojoProperties( final String expectedGroup, final String expectedArtifact,
