Skip to content

Commit

Permalink
Fix: Use MavenResolutionResult.parentPomIsProjectPom() to detect whet…
Browse files Browse the repository at this point in the history
…her a parent pom is local, and thus updateable, or notUse

Co-authored-by: Sam Snyder <sam@moderne.io>
  • Loading branch information
dpozinen and sambsnyd committed Nov 21, 2024
1 parent ead663e commit 02c1a54
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

@Value
Expand Down Expand Up @@ -88,10 +89,7 @@ public Xml.Document visitDocument(Xml.Document document, ExecutionContext ctx) {
Xml.Document d = super.visitDocument(document, ctx);

// Return early if the parent appears to be within the current repository, as properties defined there will be updated
if (d.getRoot().getChild("parent")
.flatMap(parent -> parent.getChild("relativePath"))
.flatMap(Xml.Tag::getValue)
.isPresent()) {
if (getResolutionResult().parentPomIsProjectPom()) {
return d;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.openrewrite.Issue;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.SourceSpec;

import static org.openrewrite.java.Assertions.mavenProject;
import static org.openrewrite.maven.Assertions.pomXml;
Expand Down Expand Up @@ -123,74 +122,64 @@ void basicWithVariables() {
}

@Test
void overrideRemoteParent() {
void updateLocalParent() {
rewriteRun(
//language=xml
pomXml(
"""
<project>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>
<version>1.0.0</version>
<modelVersion>4.0</modelVersion>
<properties>
<java.version>11</java.version>
<jdk.version>11</jdk.version>
<javaVersion>11</javaVersion>
<jdkVersion>11</jdkVersion>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<release.version>11</release.version>
</properties>
</project>
""",
SourceSpec::skip),
mavenProject("example-child",
//language=xml
pomXml(
"""
<project>
<parent>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>
<version>1.0.0</version>
<!-- lookup parent from remote repository -->
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>example-child</artifactId>
<version>1.0.0</version>
<modelVersion>4.0</modelVersion>
</project>
""",
"""
"""
<project>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>
<version>1.0.0</version>
<modelVersion>4.0</modelVersion>
<properties>
<java.version>11</java.version>
<jdk.version>11</jdk.version>
<javaVersion>11</javaVersion>
<jdkVersion>11</jdkVersion>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<release.version>11</release.version>
</properties>
</project>
""",
"""
<project>
<parent>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>
<version>1.0.0</version>
<!-- lookup parent from remote repository -->
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>example-child</artifactId>
<artifactId>example-parent</artifactId>
<version>1.0.0</version>
<modelVersion>4.0</modelVersion>
<properties>
<java.version>17</java.version>
<javaVersion>17</javaVersion>
<jdk.version>17</jdk.version>
<javaVersion>17</javaVersion>
<jdkVersion>17</jdkVersion>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<release.version>17</release.version>
</properties>
</project>
"""
"""),
mavenProject("example-child",
//language=xml
pomXml(
"""
<project>
<parent>
<groupId>com.example</groupId>
<artifactId>example-parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.example</groupId>
<artifactId>example-child</artifactId>
<version>1.0.0</version>
<modelVersion>4.0</modelVersion>
</project>
"""
)
)
)
);
}

Expand Down Expand Up @@ -270,7 +259,7 @@ void springBoot3ParentToJava17() {
<version>3.3.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
Expand All @@ -295,7 +284,7 @@ void springBoot3ParentToJava21() {
<version>3.3.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
Expand All @@ -311,7 +300,7 @@ void springBoot3ParentToJava21() {
<version>3.3.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
Expand Down

0 comments on commit 02c1a54

Please sign in to comment.