From 0a17f40f92a93c9c4a3ba3028706d3568d082a48 Mon Sep 17 00:00:00 2001 From: Didier Loiseau Date: Wed, 16 Oct 2024 18:57:17 +0200 Subject: [PATCH 1/2] UpgradeParentVersion: option to only upgrade external parents --- .../openrewrite/maven/ChangeParentPom.java | 27 +- .../maven/UpgradeParentVersion.java | 8 +- .../org/openrewrite/maven/tree/Parent.java | 2 + .../openrewrite/maven/AddRepositoryTest.java | 2 +- .../maven/ChangeParentPomTest.java | 406 ++++++++++++------ .../maven/MavenDependencyFailuresTest.java | 2 +- .../maven/UpgradeParentVersionTest.java | 78 +++- 7 files changed, 392 insertions(+), 133 deletions(-) diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeParentPom.java b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeParentPom.java index 317095c54b2..eb103bbef43 100755 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeParentPom.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeParentPom.java @@ -26,6 +26,7 @@ import org.openrewrite.maven.tree.*; import org.openrewrite.semver.Semver; import org.openrewrite.semver.VersionComparator; +import org.openrewrite.xml.AddOrUpdateChild; import org.openrewrite.xml.AddToTagVisitor; import org.openrewrite.xml.ChangeTagValueVisitor; import org.openrewrite.xml.TagNameComparator; @@ -38,6 +39,7 @@ import static java.util.Collections.emptyList; import static org.openrewrite.internal.StringUtils.matchesGlob; +import static org.openrewrite.maven.tree.Parent.DEFAULT_RELATIVE_PATH; @Value @EqualsAndHashCode(callSuper = false) @@ -74,7 +76,8 @@ public class ChangeParentPom extends Recipe { String newVersion; @Option(displayName = "Old relative path", - description = "The relativePath of the maven parent pom to be changed away from.", + description = "The relativePath of the maven parent pom to be changed away from. " + + "Use an empty String to match ``, use `../pom.xml` to match the default value.", example = "../../pom.xml", required = false) @Nullable @@ -158,7 +161,7 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { if (matchesGlob(resolvedPom.getValue(tag.getChildValue("groupId").orElse(null)), oldGroupId) && matchesGlob(resolvedPom.getValue(tag.getChildValue("artifactId").orElse(null)), oldArtifactId) && - (oldRelativePath == null || matchesGlob(resolvedPom.getValue(tag.getChildValue("relativePath").orElse(null)), oldRelativePath))) { + (oldRelativePath == null || matchesGlob(determineRelativePath(tag, resolvedPom), oldRelativePath))) { String oldVersion = resolvedPom.getValue(tag.getChildValue("version").orElse(null)); assert oldVersion != null; String currentGroupId = tag.getChildValue("groupId").orElse(oldGroupId); @@ -211,9 +214,15 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { } // Update or add relativePath - if (oldRelativePath != null && !oldRelativePath.equals(targetRelativePath)) { - changeParentTagVisitors.add(new ChangeTagValueVisitor<>(t.getChild("relativePath").get(), targetRelativePath)); - } else if (mismatches(tag.getChild("relativePath").orElse(null), targetRelativePath)) { + Optional existingRelativePath = t.getChild("relativePath"); + if (oldRelativePath != null && !oldRelativePath.equals(targetRelativePath) && existingRelativePath.isPresent()) { + if (StringUtils.isBlank(targetRelativePath)) { + // ChangeTagValueVisitor would keep the closing tag + changeParentTagVisitors.add(new AddOrUpdateChild<>(t, Xml.Tag.build(""))); + } else { + changeParentTagVisitors.add(new ChangeTagValueVisitor<>(existingRelativePath.get(), targetRelativePath)); + } + } else if (mismatches(existingRelativePath.orElse(null), targetRelativePath)) { final Xml.Tag relativePathTag; if (StringUtils.isBlank(targetRelativePath)) { relativePathTag = Xml.Tag.build(""); @@ -281,6 +290,14 @@ private Optional findAcceptableVersion(String groupId, String artifactId }); } + private static @Nullable String determineRelativePath(Xml.Tag tag, ResolvedPom resolvedPom) { + Optional relativePath = tag.getChild("relativePath"); + if (relativePath.isPresent()) { + return resolvedPom.getValue(relativePath.get().getValue().orElse("")); + } + return DEFAULT_RELATIVE_PATH; + } + private static final Pattern PROPERTY_PATTERN = Pattern.compile("\\$\\{([^}]+)}"); private static Map getPropertiesInUse(Xml.Document pomXml, ExecutionContext ctx) { diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/UpgradeParentVersion.java b/rewrite-maven/src/main/java/org/openrewrite/maven/UpgradeParentVersion.java index e05b8741578..72a7d124914 100755 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/UpgradeParentVersion.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/UpgradeParentVersion.java @@ -50,6 +50,12 @@ public class UpgradeParentVersion extends Recipe { @Nullable String versionPattern; + @Option(displayName = "Only external", + description = "Only upgrade `` if external to the project, i.e. it has an empty ``. Defaults to `false`.", + required = false) + @Nullable + Boolean onlyExternal; + @Override public String getDisplayName() { return "Upgrade Maven parent project version"; @@ -82,7 +88,7 @@ public TreeVisitor getVisitor() { } private ChangeParentPom changeParentPom() { - return new ChangeParentPom(groupId, null, artifactId, null, newVersion, null, null, + return new ChangeParentPom(groupId, null, artifactId, null, newVersion, Boolean.TRUE.equals(onlyExternal) ? "" : null, null, versionPattern, false); } } diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Parent.java b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Parent.java index 4bcbe9c3814..d071ee624c0 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Parent.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/tree/Parent.java @@ -22,6 +22,8 @@ @Value @With public class Parent { + public static final String DEFAULT_RELATIVE_PATH = "../pom.xml"; + GroupArtifactVersion gav; @Nullable diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/AddRepositoryTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/AddRepositoryTest.java index 2dc106fa1a5..a277d56bb99 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/AddRepositoryTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/AddRepositoryTest.java @@ -312,7 +312,7 @@ void updateToSpringBoot30Snapshot() { new AddRepository("boot-snapshots", "https://repo.spring.io/snapshot", null, null, true, null, null, null, null, null, null), - new UpgradeParentVersion("org.springframework.boot", "spring-boot-starter-parent", "3.0.0-SNAPSHOT", null) + new UpgradeParentVersion("org.springframework.boot", "spring-boot-starter-parent", "3.0.0-SNAPSHOT", null, null) ), pomXml( """ diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeParentPomTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeParentPomTest.java index dff6b556ee5..f08e60b642f 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeParentPomTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeParentPomTest.java @@ -18,8 +18,11 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.openrewrite.DocumentExample; import org.openrewrite.Issue; +import org.openrewrite.internal.StringUtils; import org.openrewrite.test.RewriteTest; import static org.openrewrite.java.Assertions.mavenProject; @@ -230,130 +233,205 @@ void changeParentAddRelativePathNonEmptyValue() { @RepeatedTest(10) void multiModuleRelativePath() { - ChangeParentPom recipe = new ChangeParentPom("org.springframework.boot", null, "spring-boot-starter-parent", null, "2.6.7", null, "", null, false); - rewriteRun( - spec -> spec.recipe(recipe), - mavenProject("parent", - pomXml( - """ - - - 4.0.0 - org.sample - sample - 1.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.5.0 - - - - module1 - module2 - - - """, - """ - - - 4.0.0 - org.sample - sample - 1.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.6.7 - - - - - module1 - module2 - - - """ - ), - mavenProject("module1", + ChangeParentPom recipe = new ChangeParentPom("org.springframework.boot", null, "spring-boot-starter-parent", null, "2.6.7", null, "", null, false); + rewriteRun( + spec -> spec.recipe(recipe), + mavenProject("parent", pomXml( """ 4.0.0 + org.sample + sample + 1.0.0 + - org.sample - sample - 1.0.0 + org.springframework.boot + spring-boot-starter-parent + 2.5.0 - module1 + + + module1 + module2 + - """ - )), - mavenProject("module2", - pomXml( + """, """ 4.0.0 + org.sample + sample + 1.0.0 + - org.sample - sample - 1.0.0 + org.springframework.boot + spring-boot-starter-parent + 2.6.7 + - module2 + + + module1 + module2 + """ + ), + mavenProject("module1", + pomXml( + """ + + + 4.0.0 + + org.sample + sample + 1.0.0 + + module1 + + """ + )), + mavenProject("module2", + pomXml( + """ + + + 4.0.0 + + org.sample + sample + 1.0.0 + + module2 + + """ + ) ) ) - ) - ); - } + ); + } - @RepeatedTest(10) - void multiModuleRelativePathChangeChildrens() { - ChangeParentPom recipe = new ChangeParentPom("org.sample", "org.springframework.boot", "sample", "spring-boot-starter-parent", "2.5.0", null, "", null, true); - rewriteRun( - spec -> spec.recipe(recipe), - mavenProject("parent", - pomXml( - """ - - - 4.0.0 - org.sample - sample - 1.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.5.0 - - - - module1 - module2 - - - """ - ), - mavenProject("module1", - pomXml( - """ - - - 4.0.0 - + @RepeatedTest(10) + void multiModuleRelativePathChangeChildren() { + ChangeParentPom recipe = new ChangeParentPom("org.sample", "org.springframework.boot", "sample", "spring-boot-starter-parent", "2.5.0", null, "", null, true); + rewriteRun( + spec -> spec.recipe(recipe), + mavenProject("parent", + pomXml( + """ + + + 4.0.0 org.sample sample 1.0.0 - - module1 - - """, + + + org.springframework.boot + spring-boot-starter-parent + 2.5.0 + + + + module1 + module2 + + + """ + ), + mavenProject("module1", + pomXml( + """ + + + 4.0.0 + + org.sample + sample + 1.0.0 + + module1 + + """, + """ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.5.0 + + + module1 + + """ + )), + mavenProject("module2", + pomXml( + """ + + + 4.0.0 + + org.sample + sample + 1.0.0 + + module2 + + """, + """ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.5.0 + + + module2 + + """ + ) + ) + ) + ); + } + + @ParameterizedTest + @CsvSource({ + "../pom.xml,'',,", // self-closing tag gets added + "../pom.xml,,../pom.xml,../pom.xml", // no change, targetRelativePath is null + "../pom.xml,../../pom.xml,,../../pom.xml", // tag gets added + "../pom.xml,../../pom.xml,../pom.xml,../../pom.xml", // tag gets updated + "../*,'',,", // self-closing tag gets added + "../*,,../pom.xml,../pom.xml", // no change, targetRelativePath is null + "../*,../../pom.xml,,../../pom.xml", // tag gets added + "../*,../../pom.xml,../pom.xml,../../pom.xml", // tag gets updated + "../../pom.xml,'',../../pom.xml,", // tag converted to self-closing + "'','',,", // matches but new = old, left untouched + "'','',,", // matches but new = old, left untouched + "'','../pom.xml',,../pom.xml", // tag gets updated + "'','../pom.xml',,../pom.xml", // tag gets expanded and updated + }) + void multiModuleChangeChildrenBasedOnRelativePath(String oldRelativePath, String newRelativePath, String oldRelativePathTag, String expectedNewRelativePathTag) { + ChangeParentPom recipe = new ChangeParentPom( + "org.sample", "org.springframework.boot", + "sample", "spring-boot-starter-parent", + "2.5.0", + oldRelativePath, newRelativePath, + null, + true); + rewriteRun( + spec -> spec.recipe(recipe), + mavenProject("parent", + pomXml( """ @@ -362,26 +440,86 @@ void multiModuleRelativePathChangeChildrens() { org.springframework.boot spring-boot-starter-parent 2.5.0 - - module1 - - """ - )), - mavenProject("module2", - pomXml( - """ - - - 4.0.0 - org.sample sample 1.0.0 - - module2 - - """, + + + module1 + module2 + + + """ + ), + mavenProject("module1", + pomXml( + """ + + + 4.0.0 + + org.sample + sample + 1.0.0%s + + module1 + + """.formatted(StringUtils.isBlank(oldRelativePathTag) ? "" : "\n " + oldRelativePathTag), + """ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.5.0%s + + module1 + + """.formatted(StringUtils.isBlank(expectedNewRelativePathTag) ? "" : "\n " + expectedNewRelativePathTag) + ) + ), + mavenProject("module2", + // “control” module: same parent gav but different relativePath should not be affected + pomXml( + """ + + + 4.0.0 + + org.sample + sample + 1.0.0 + .. + + module3 + + """ + ) + ) + ) + ); + } + + @ParameterizedTest + @CsvSource({ + "../pom.xml,", // self-closing means empty string + "../pom.xml,../../pom.xml", // different value + "..,,", // absent tag means '../pom.xml' not '..' + }) + void multiModuleRelativePathNotMatching(String oldRelativePath, String oldRelativePathTag) { + ChangeParentPom recipe = new ChangeParentPom( + "org.sample", "org.springframework.boot", + "sample", "spring-boot-starter-parent", + "2.5.0", + oldRelativePath, "invalid", + null, + true); + rewriteRun( + spec -> spec.recipe(recipe), + mavenProject("parent", + pomXml( """ @@ -390,16 +528,36 @@ void multiModuleRelativePathChangeChildrens() { org.springframework.boot spring-boot-starter-parent 2.5.0 - - module2 + org.sample + sample + 1.0.0 + + + module1 + """ + ), + mavenProject("module1", + pomXml( + """ + + + 4.0.0 + + org.sample + sample + 1.0.0%s + + module1 + + """.formatted(StringUtils.isBlank(oldRelativePathTag) ? "" : "\n " + oldRelativePathTag) + ) + ) ) - ) - ) - ); -} + ); + } @Test void upgradeVersion() { diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/MavenDependencyFailuresTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/MavenDependencyFailuresTest.java index 1a179b991a4..e79efee8f22 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/MavenDependencyFailuresTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/MavenDependencyFailuresTest.java @@ -86,7 +86,7 @@ void unresolvableMavenMetadata() { void unresolvableParent() { // Dad said he was heading to the corner store for cigarettes, and hasn't been resolvable for the past 20 years :'( rewriteRun( spec -> spec - .recipe(new UpgradeParentVersion("*", "*", "latest.patch", null)) + .recipe(new UpgradeParentVersion("*", "*", "latest.patch", null, null)) .executionContext(MavenExecutionContextView.view(new InMemoryExecutionContext()) .setRepositories(List.of(MavenRepository.builder().id("jenkins").uri("https://repo.jenkins-ci.org/public").knownToExist(true).build()))) .recipeExecutionContext(new InMemoryExecutionContext()) diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/UpgradeParentVersionTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/UpgradeParentVersionTest.java index e248627b44c..91ac1ab9b93 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/UpgradeParentVersionTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/UpgradeParentVersionTest.java @@ -16,6 +16,8 @@ package org.openrewrite.maven; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.openrewrite.DocumentExample; import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.Issue; @@ -36,6 +38,7 @@ void doesNotDowngradeVersion() { "org.springframework.boot", "spring-boot-starter-parent", "~1.5", + null, null )), pomXml( @@ -61,7 +64,7 @@ void doesNotDowngradeVersion() { void nonMavenCentralRepository() { rewriteRun( spec -> spec - .recipe(new UpgradeParentVersion("org.jenkins-ci.plugins", "plugin", "4.40", null)) + .recipe(new UpgradeParentVersion("org.jenkins-ci.plugins", "plugin", "4.40", null, null)) .executionContext( MavenExecutionContextView .view(new InMemoryExecutionContext()) @@ -103,6 +106,7 @@ void upgradeVersion() { "org.springframework.boot", "spring-boot-starter-parent", "~1.5", + null, null )), pomXml( @@ -136,6 +140,77 @@ void upgradeVersion() { ); } + @ParameterizedTest + @ValueSource(strings = {"", ""}) + void onlyExternalWhenActuallyExternal(String relativePathTag) { + rewriteRun( + spec -> spec.recipe(new UpgradeParentVersion( + "org.springframework.boot", + "spring-boot-starter-parent", + "~1.5", + null, + true + )), + pomXml( + """ + + + org.springframework.boot + spring-boot-starter-parent + 1.5.12.RELEASE + %s + + com.mycompany.app + my-app + 1 + + """.formatted(relativePathTag), + """ + + + org.springframework.boot + spring-boot-starter-parent + 1.5.22.RELEASE + %s + + com.mycompany.app + my-app + 1 + + """.formatted(relativePathTag) + ) + ); + } + + @ParameterizedTest + @ValueSource(strings = {"", "..", "../pom.xml", "../../pom.xml"}) + void onlyExternalWhenNotExternal(String relativePathTag) { + rewriteRun( + spec -> spec.recipe(new UpgradeParentVersion( + "org.springframework.boot", + "spring-boot-starter-parent", + "~1.5", + null, + true + )), + pomXml( + """ + + + org.springframework.boot + spring-boot-starter-parent + 1.5.12.RELEASE + %s + + com.mycompany.app + my-app + 1 + + """.formatted(relativePathTag) + ) + ); + } + @Test void upgradeToExactVersion() { rewriteRun( @@ -143,6 +218,7 @@ void upgradeToExactVersion() { "org.springframework.boot", "spring-boot-starter-parent", "1.5.22.RELEASE", + null, null )), pomXml( From 976ba54a463537811a944db56ae6fb72c9456e33 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 27 Oct 2024 01:25:11 +0200 Subject: [PATCH 2/2] Apply formatter to ChangeParentPomTest --- .../maven/ChangeParentPomTest.java | 564 +++++++++--------- 1 file changed, 282 insertions(+), 282 deletions(-) diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeParentPomTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeParentPomTest.java index f08e60b642f..4746e3e0718 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeParentPomTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeParentPomTest.java @@ -49,13 +49,13 @@ void changeParent() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.12.RELEASE - + com.mycompany.app my-app 1 @@ -64,13 +64,13 @@ void changeParent() { """ 4.0.0 - + com.fasterxml.jackson jackson-parent 2.12 - + com.mycompany.app my-app 1 @@ -98,14 +98,14 @@ void changeParentWithRelativePath() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.12.RELEASE - + com.mycompany.app my-app 1 @@ -114,14 +114,14 @@ void changeParentWithRelativePath() { """ 4.0.0 - + com.fasterxml.jackson jackson-parent 2.12 ../../pom.xml - + com.mycompany.app my-app 1 @@ -149,13 +149,13 @@ void changeParentAddRelativePathEmptyValue() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.12.RELEASE - + com.mycompany.app my-app 1 @@ -164,14 +164,14 @@ void changeParentAddRelativePathEmptyValue() { """ 4.0.0 - + com.fasterxml.jackson jackson-parent 2.12 - + com.mycompany.app my-app 1 @@ -199,13 +199,13 @@ void changeParentAddRelativePathNonEmptyValue() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.12.RELEASE - + com.mycompany.app my-app 1 @@ -214,14 +214,14 @@ void changeParentAddRelativePathNonEmptyValue() { """ 4.0.0 - + com.fasterxml.jackson jackson-parent 2.12 ../pom.xml - + com.mycompany.app my-app 1 @@ -577,14 +577,14 @@ void upgradeVersion() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.12.RELEASE - + com.mycompany.app my-app 1 @@ -593,14 +593,14 @@ void upgradeVersion() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.22.RELEASE - + com.mycompany.app my-app 1 @@ -628,14 +628,14 @@ void upgradeToExactVersion() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.12.RELEASE - + com.mycompany.app my-app 1 @@ -644,14 +644,14 @@ void upgradeToExactVersion() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.22.RELEASE - + com.mycompany.app my-app 1 @@ -679,14 +679,14 @@ void doNotDowngradeToLowerVersionWhenArtifactsAreTheSame() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.22.RELEASE - + com.mycompany.app my-app 1 @@ -714,14 +714,14 @@ void downgradeToLowerVersionWhenFlagIsSet() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.22.RELEASE - + com.mycompany.app my-app 1 @@ -730,14 +730,14 @@ void downgradeToLowerVersionWhenFlagIsSet() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.12.RELEASE - + com.mycompany.app my-app 1 @@ -765,14 +765,14 @@ void wildcardVersionUpdate() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.12.RELEASE - + com.mycompany.app my-app 1 @@ -781,14 +781,14 @@ void wildcardVersionUpdate() { """ 4.0.0 - + org.springframework.boot spring-boot-starter-parent 1.5.22.RELEASE - + com.mycompany.app my-app 1 @@ -816,18 +816,18 @@ void removesRedundantExplicitVersionsMatchingOldParent() { """ 4.0.0 - + org.junit junit-bom 5.9.0 - + com.mycompany.app my-app 1 - + org.junit.jupiter @@ -840,18 +840,18 @@ void removesRedundantExplicitVersionsMatchingOldParent() { """ 4.0.0 - + org.junit junit-bom 5.9.1 - + com.mycompany.app my-app 1 - + org.junit.jupiter @@ -882,18 +882,18 @@ void removesRedundantExplicitVersionsMatchingNewParent() { """ 4.0.0 - + org.junit junit-bom 5.9.0 - + com.mycompany.app my-app 1 - + org.junit.jupiter @@ -906,18 +906,18 @@ void removesRedundantExplicitVersionsMatchingNewParent() { """ 4.0.0 - + org.junit junit-bom 5.9.1 - + com.mycompany.app my-app 1 - + org.junit.jupiter @@ -948,18 +948,18 @@ void takesNewVersionFromParent() { """ 4.0.0 - + org.junit junit-bom 5.9.0 - + com.mycompany.app my-app 1 - + org.junit.jupiter @@ -972,18 +972,18 @@ void takesNewVersionFromParent() { """ 4.0.0 - + org.junit junit-bom 5.9.1 - + com.mycompany.app my-app 1 - + org.junit.jupiter @@ -1008,7 +1008,7 @@ void upgradeNonSemverVersion() { org.sample sample 1.0.0 - + org.springframework.cloud spring-cloud-starter-parent @@ -1023,7 +1023,7 @@ void upgradeNonSemverVersion() { org.sample sample 1.0.0 - + org.springframework.cloud spring-cloud-starter-parent @@ -1106,13 +1106,13 @@ void preservesExplicitVersionIfNotRequested() { org.sample sample 1.0.0 - + org.springframework.cloud spring-cloud-dependencies 2020.0.1 - + org.springframework.cloud @@ -1129,13 +1129,13 @@ void preservesExplicitVersionIfNotRequested() { org.sample sample 1.0.0 - + org.springframework.cloud spring-cloud-dependencies 2021.0.5 - + org.springframework.cloud @@ -1159,49 +1159,49 @@ void bringsDownRemovedProperty() { "3.2.4", null, null, null, null)), pomXml( - """ - - 4.0.0 - com.mycompany - child - 1.0.0-SNAPSHOT - - org.springframework.boot - spring-boot-dependencies - 2.4.0 - - - - javax.servlet - javax.servlet-api - ${servlet-api.version} - - - - """, """ - - 4.0.0 - com.mycompany - child - 1.0.0-SNAPSHOT - - org.springframework.boot - spring-boot-dependencies - 3.2.4 - - - 4.0.1 - - - - javax.servlet - javax.servlet-api - ${servlet-api.version} - - - - """) + + 4.0.0 + com.mycompany + child + 1.0.0-SNAPSHOT + + org.springframework.boot + spring-boot-dependencies + 2.4.0 + + + + javax.servlet + javax.servlet-api + ${servlet-api.version} + + + + """, + """ + + 4.0.0 + com.mycompany + child + 1.0.0-SNAPSHOT + + org.springframework.boot + spring-boot-dependencies + 3.2.4 + + + 4.0.1 + + + + javax.servlet + javax.servlet-api + ${servlet-api.version} + + + + """) ); } @@ -1214,53 +1214,53 @@ void bringsDownRemovedManagedVersion() { "3.2.4", null, null, null, null)), pomXml( - """ - - 4.0.0 - com.mycompany - child - 1.0.0-SNAPSHOT - - org.springframework.boot - spring-boot-dependencies - 2.4.0 - - - - javax.servlet - javax.servlet-api - - - - """, """ - - 4.0.0 - com.mycompany - child - 1.0.0-SNAPSHOT - - org.springframework.boot - spring-boot-dependencies - 3.2.4 - - - - - javax.servlet - javax.servlet-api - 4.0.1 - - - - - - javax.servlet - javax.servlet-api - - - - """) + + 4.0.0 + com.mycompany + child + 1.0.0-SNAPSHOT + + org.springframework.boot + spring-boot-dependencies + 2.4.0 + + + + javax.servlet + javax.servlet-api + + + + """, + """ + + 4.0.0 + com.mycompany + child + 1.0.0-SNAPSHOT + + org.springframework.boot + spring-boot-dependencies + 3.2.4 + + + + + javax.servlet + javax.servlet-api + 4.0.1 + + + + + + javax.servlet + javax.servlet-api + + + + """) ); } } @@ -1280,13 +1280,13 @@ void multiModule() { org.sample sample 1.0.0 - + org.springframework.boot spring-boot-starter-parent 2.5.0 - + module1 module2 @@ -1300,13 +1300,13 @@ void multiModule() { org.sample sample 1.0.0 - + org.springframework.boot spring-boot-starter-parent 2.6.7 - + module1 module2 @@ -1361,7 +1361,7 @@ void changeParentToSameVersion() { org.sample sample 1.0.0 - + org.springframework.boot spring-boot-dependencies @@ -1376,7 +1376,7 @@ void changeParentToSameVersion() { org.sample sample 1.0.0 - + org.springframework.boot spring-boot-starter-parent @@ -1395,44 +1395,44 @@ void doNotAddUnnecessaryManagedVersion() { "spring-boot-starter-parent", "spring-boot-starter-parent", "2.3.12.RELEASE", null, null, null, null)), pomXml( - """ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.13.RELEASE - - com.example - acme - 0.0.1-SNAPSHOT - - - org.springframework.boot - spring-boot-starter-web - - - - """, """ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.12.RELEASE - - com.example - acme - 0.0.1-SNAPSHOT - - - org.springframework.boot - spring-boot-starter-web - - - - """) + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.13.RELEASE + + com.example + acme + 0.0.1-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-web + + + + """, + """ + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.12.RELEASE + + com.example + acme + 0.0.1-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-web + + + + """) ); } @@ -1442,95 +1442,95 @@ void shouldNotAddToDependencyManagement() { spec -> spec.recipe(new ChangeParentPom("org.jenkins-ci.plugins", "org.jenkins-ci.plugins", "plugin", "plugin", "4.81", null, null, null, null)), // language=xml pomXml( - """ - - example - 4.0.0 - - org.jenkins-ci.plugins - plugin - 4.75 - - - - 2.387.3 - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - + """ + + example + 4.0.0 + + org.jenkins-ci.plugins + plugin + 4.75 + + + + 2.387.3 + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + + io.jenkins.tools.bom + bom-2.387.x + 2516.v113cb_3d00317 + pom + import + + + - io.jenkins.tools.bom - bom-2.387.x - 2516.v113cb_3d00317 - pom - import + org.jenkins-ci.plugins + junit - - - - org.jenkins-ci.plugins - junit - - - - """, - """ - - example - 4.0.0 - - org.jenkins-ci.plugins - plugin - 4.81 - - - - 2.387.3 - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - + + """, + """ + + example + 4.0.0 + + org.jenkins-ci.plugins + plugin + 4.81 + + + + 2.387.3 + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + + io.jenkins.tools.bom + bom-2.387.x + 2516.v113cb_3d00317 + pom + import + + + - io.jenkins.tools.bom - bom-2.387.x - 2516.v113cb_3d00317 - pom - import + org.jenkins-ci.plugins + junit - - - - org.jenkins-ci.plugins - junit - - - - """ - )); + + """ + )); } @Test @@ -1545,13 +1545,13 @@ void doesNotAddMavenDefaultProperties() { org.sample sample 1.0.0 - + org.springframework.boot spring-boot-starter-parent 2.7.17 - + ${project.build.directory} @@ -1564,13 +1564,13 @@ void doesNotAddMavenDefaultProperties() { org.sample sample 1.0.0 - + org.springframework.boot spring-boot-starter-parent 2.7.18 - + ${project.build.directory} @@ -1592,13 +1592,13 @@ void doesNotAddGrandparentProperties() { org.sample sample 1.0.0 - + org.springframework.boot spring-boot-starter-parent 2.7.17 - + ${junit.version} @@ -1611,13 +1611,13 @@ void doesNotAddGrandparentProperties() { org.sample sample 1.0.0 - + org.springframework.boot spring-boot-starter-parent 2.7.18 - + ${junit.version} @@ -1639,13 +1639,13 @@ void doesNotAddGlobalProperties() { org.sample sample 1.0.0 - + org.springframework.boot spring-boot-starter-parent 2.7.17 - + ${basedir} ${project.basedir} @@ -1663,13 +1663,13 @@ void doesNotAddGlobalProperties() { org.sample sample 1.0.0 - + org.springframework.boot spring-boot-starter-parent 2.7.18 - + ${basedir} ${project.basedir}