diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ResolvedPom.java b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ResolvedPom.java index e970abd798f..a900ba4a057 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ResolvedPom.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/ResolvedPom.java @@ -278,6 +278,10 @@ private String getProperty(@Nullable String property) { if (property == null) { return null; } + String propVal = properties.get(property); + if (propVal != null) { + return propVal; + } switch (property) { case "groupId": case "project.groupId": @@ -302,7 +306,7 @@ private String getProperty(@Nullable String property) { return requested.getParent() != null ? requested.getParent().getVersion() : null; } - return System.getProperty(property, properties.get(property)); + return System.getProperty(property); } @Nullable diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java index 05d37789d11..791f5d3208e 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/MavenParserTest.java @@ -55,7 +55,7 @@ void rangeVersion() { com.mycompany.app my-app 1 - + junit @@ -79,7 +79,7 @@ void skipDependencyResolution() { com.mycompany.app my-app 1 - + foo @@ -128,7 +128,7 @@ void invalidRange() { com.mycompany.app my-app 1 - + junit @@ -517,7 +517,7 @@ void parse() { """ 4.0.0 - + com.mycompany.app my-app 1 @@ -527,7 +527,7 @@ void parse() { Trygve Laugstøl - + org.junit.jupiter @@ -583,11 +583,11 @@ void handlesRepositories() { """ 4.0.0 - + org.openrewrite.maven single-project 0.1.0-SNAPSHOT - + com.google.guava @@ -595,7 +595,7 @@ void handlesRepositories() { 29.0-jre - + jcenter @@ -617,15 +617,15 @@ void handlesPropertiesInDependencyScope() { """ 4.0.0 - + org.openrewrite.maven single-project 0.1.0-SNAPSHOT - + compile - + com.google.guava @@ -677,11 +677,11 @@ void selfRecursiveParent() { """ 4.0.0 - + com.mycompany.app my-app 1 - + com.mycompany.app my-app @@ -701,11 +701,11 @@ void selfRecursiveDependency() { """ 4.0.0 - + com.mycompany.app my-app 1 - + com.mycompany.app @@ -893,11 +893,11 @@ public MockResponse dispatch(RecordedRequest request) { resp.setBody(""" 4.0.0 - + com.foo bar 1.0.0 - + """ ); @@ -940,11 +940,11 @@ public MockResponse dispatch(RecordedRequest request) { """ 4.0.0 - + org.openrewrite.test foo 0.1.0-SNAPSHOT - + com.foo @@ -1130,17 +1130,17 @@ void indirectBomImportedFromParent() { """ 4.0.0 - + b org.openrewrite.maven 0.1.0-SNAPSHOT pom - + 1.8 1.8 - + @@ -1161,12 +1161,12 @@ void indirectBomImportedFromParent() { """ 4.0.0 - + c org.openrewrite.maven 0.1.0-SNAPSHOT pom - + @@ -1185,11 +1185,11 @@ void indirectBomImportedFromParent() { """ 4.0.0 - + org.openrewrite.maven d 0.1.0-SNAPSHOT - + 1.8 1.8 @@ -1406,7 +1406,7 @@ void dependencyManagementPropagatesToDependencies() { a-parent 0.1.0-SNAPSHOT pom - + @@ -1429,9 +1429,9 @@ void dependencyManagementPropagatesToDependencies() { 0.1.0-SNAPSHOT - + a - + org.openrewrite.maven @@ -1490,9 +1490,9 @@ void dependencyManagementPropagatesToDependencies() { 0.1.0-SNAPSHOT - + b - + org.openrewrite.maven @@ -1532,7 +1532,7 @@ void managedDependencyInTransitiveAndPom() { a 1.0.0 jar - + @@ -1542,7 +1542,7 @@ void managedDependencyInTransitiveAndPom() { - + junit @@ -1606,7 +1606,7 @@ void profileNoJdkActivation() { com.mycompany.app my-app 1 - + old-jdk @@ -1812,11 +1812,11 @@ void ciFriendlyVersionWithParent() { sample ${revision} pom - + sample-rest - + """, spec -> spec.path("pom.xml")), pomXml( @@ -1824,11 +1824,11 @@ void ciFriendlyVersionWithParent() { - + 4.0.0 sample-rest jar - + net.sample sample @@ -1854,14 +1854,14 @@ void canConnectProjectPomsWhenUsingCiFriendlyVersions() { sample ${revision} pom - + sample-parent sample-app sample-rest sample-web - + 0.0.0-SNAPSHOT @@ -1877,11 +1877,11 @@ void canConnectProjectPomsWhenUsingCiFriendlyVersions() { net.sample ${revision} pom - + 0.0.0-SNAPSHOT - + @@ -1903,24 +1903,24 @@ void canConnectProjectPomsWhenUsingCiFriendlyVersions() { - + 4.0.0 sample-app jar - + net.sample sample-parent ${revision} ../parent/pom.xml - + net.sample sample-rest - + net.sample sample-web @@ -1933,11 +1933,11 @@ void canConnectProjectPomsWhenUsingCiFriendlyVersions() { - + 4.0.0 sample-rest jar - + net.sample sample-parent @@ -1951,11 +1951,11 @@ void canConnectProjectPomsWhenUsingCiFriendlyVersions() { - + 4.0.0 sample-web jar - + net.sample sample-parent @@ -1982,14 +1982,14 @@ void ciFriendlyVersionsStillWorkAfterUpdateMavenModel() { sample ${revision} pom - + sample-parent sample-app sample-rest sample-web - + 0.0.0-SNAPSHOT @@ -2005,11 +2005,11 @@ void ciFriendlyVersionsStillWorkAfterUpdateMavenModel() { net.sample ${revision} pom - + 0.0.0-SNAPSHOT - + @@ -2031,29 +2031,29 @@ void ciFriendlyVersionsStillWorkAfterUpdateMavenModel() { - + 4.0.0 sample-app jar - + net.sample sample-parent ${revision} ../parent/pom.xml - + net.sample sample-rest - + net.sample sample-web - + junit junit @@ -2065,29 +2065,29 @@ void ciFriendlyVersionsStillWorkAfterUpdateMavenModel() { - + 4.0.0 sample-app jar - + net.sample sample-parent ${revision} ../parent/pom.xml - + net.sample sample-rest - + net.sample sample-web - + junit junit @@ -2101,11 +2101,11 @@ void ciFriendlyVersionsStillWorkAfterUpdateMavenModel() { - + 4.0.0 sample-rest jar - + net.sample sample-parent @@ -2119,11 +2119,11 @@ void ciFriendlyVersionsStillWorkAfterUpdateMavenModel() { - + 4.0.0 sample-web jar - + net.sample sample-parent @@ -2144,16 +2144,16 @@ void multipleCiFriendlyVersionPlaceholders() { 4.0.0 - + bogus.example parent ${revision}${changelist} pom - + sub - + 99999.0 -SNAPSHOT @@ -2166,13 +2166,13 @@ void multipleCiFriendlyVersionPlaceholders() { 4.0.0 - + bogus.example parent ${revision}${changelist} - + sub """, spec -> spec.path("sub/pom.xml")) @@ -2337,7 +2337,7 @@ void malformedPom() { com.mycompany.app my-app 1 - + junit @@ -2360,7 +2360,7 @@ void plugins() { org.openrewrite.maven a 0.1.0-SNAPSHOT - + @@ -2393,7 +2393,7 @@ void pluginWithoutConfig() { org.openrewrite.maven a 0.1.0-SNAPSHOT - + @@ -2444,9 +2444,9 @@ void pluginsFromParent() { org.openrewrite.maven b 0.1.0-SNAPSHOT - + pom - + @@ -2474,7 +2474,7 @@ void pluginManagement() { org.openrewrite.maven a 0.1.0-SNAPSHOT - + @@ -2529,9 +2529,9 @@ void pluginManagementFromParent() { org.openrewrite.maven b 0.1.0-SNAPSHOT - + pom - + @@ -2581,9 +2581,9 @@ void notInheritedPluginFromParent() { org.openrewrite.maven b 0.1.0-SNAPSHOT - + pom - + @@ -2613,9 +2613,9 @@ void mergePluginConfig() { org.openrewrite.maven b 0.1.0-SNAPSHOT - + pom - + @@ -2643,7 +2643,7 @@ void mergePluginConfig() { a - + @@ -2678,9 +2678,9 @@ void mergePluginConfigListOverride() { org.openrewrite.maven b 0.1.0-SNAPSHOT - + pom - + @@ -2710,7 +2710,7 @@ void mergePluginConfigListOverride() { a - + @@ -2750,9 +2750,9 @@ void mergePluginConfigListAppend() { org.openrewrite.maven b 0.1.0-SNAPSHOT - + pom - + @@ -2782,7 +2782,7 @@ void mergePluginConfigListAppend() { a - + @@ -2825,9 +2825,9 @@ void mergePluginConfigListAppendOverride() { org.openrewrite.maven b 0.1.0-SNAPSHOT - + pom - + @@ -2857,7 +2857,7 @@ void mergePluginConfigListAppendOverride() { a - + @@ -3107,4 +3107,54 @@ void circularImportDependency() { ) ); } + + @Test + void circularMavenProperty() { + rewriteRun( + mavenProject("root", + pomXml( + """ + + example + example-root + pom + 1.0.0 + + + 1.0.1 + + + + example-child + + + """, + spec -> spec.afterRecipe(pomXml -> assertThat( + pomXml.getMarkers().findFirst(MavenResolutionResult.class).orElseThrow() + .getPom().getProperties().get("project.version")) + .isEqualTo("1.0.1")) + ), + mavenProject("circular-example-child", + pomXml( + """ + + + example + example-root + 1.0.0 + + + example-child + ${project.version} + + """, + spec -> spec.afterRecipe(pomXml -> assertThat( + pomXml.getMarkers().findFirst(MavenResolutionResult.class).orElseThrow() + .getPom().getVersion()) + .isEqualTo("1.0.1")) + ) + ) + ) + ); + } }