diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java index bd1dedafcb6..ed2faa43130 100755 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java @@ -94,11 +94,11 @@ public class ChangeDependencyGroupIdAndArtifactId extends Recipe { @Nullable Boolean changeManagedDependency; - @Option(displayName = "Update dependency management", - description = "Also update the dependency management section. The default for this flag is `true`.", + @Option(displayName = "Change property version name", + description = "Allows property version name to be changed to best practice naming convention. The default for this flag is `false`.", required = false) @Nullable - Boolean changePropertyVersionNames; + Boolean changePropertyVersionName; public ChangeDependencyGroupIdAndArtifactId(String oldGroupId, String oldArtifactId, @Nullable String newGroupId, @Nullable String newArtifactId, @Nullable String newVersion, @Nullable String versionPattern) { this(oldGroupId, oldArtifactId, newGroupId, newArtifactId, newVersion, versionPattern, false, true, false); @@ -109,7 +109,7 @@ public ChangeDependencyGroupIdAndArtifactId(String oldGroupId, String oldArtifac } @JsonCreator - public ChangeDependencyGroupIdAndArtifactId(String oldGroupId, String oldArtifactId, @Nullable String newGroupId, @Nullable String newArtifactId, @Nullable String newVersion, @Nullable String versionPattern, @Nullable Boolean overrideManagedVersion, @Nullable Boolean changeManagedDependency, @Nullable Boolean changePropertyVersionNames) { + public ChangeDependencyGroupIdAndArtifactId(String oldGroupId, String oldArtifactId, @Nullable String newGroupId, @Nullable String newArtifactId, @Nullable String newVersion, @Nullable String versionPattern, @Nullable Boolean overrideManagedVersion, @Nullable Boolean changeManagedDependency, @Nullable Boolean changePropertyVersionName) { this.oldGroupId = oldGroupId; this.oldArtifactId = oldArtifactId; this.newGroupId = newGroupId; @@ -118,7 +118,7 @@ public ChangeDependencyGroupIdAndArtifactId(String oldGroupId, String oldArtifac this.versionPattern = versionPattern; this.overrideManagedVersion = overrideManagedVersion; this.changeManagedDependency = changeManagedDependency; - this.changePropertyVersionNames = changePropertyVersionNames; + this.changePropertyVersionName = changePropertyVersionName != null && changePropertyVersionName; // False by default } @Override @@ -173,7 +173,7 @@ public Xml visitDocument(Xml.Document document, ExecutionContext ctx) { oldGroupId, oldArtifactId, Optional.ofNullable(newGroupId).orElse(oldGroupId), Optional.ofNullable(newArtifactId).orElse(oldArtifactId), - newVersion, versionPattern, changePropertyVersionNames).getVisitor()); + newVersion, versionPattern, changePropertyVersionName).getVisitor()); } return super.visitDocument(document, ctx); } @@ -213,7 +213,7 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) { if (!configuredToOverrideManageVersion && newDependencyManaged || (oldDependencyManaged && configuredToChangeManagedDependency)) { t = (Xml.Tag) new RemoveContentVisitor<>(versionTag.get(), false).visit(t, ctx); } else { - doAfterVisit(new ChangeVersionValue(groupId, artifactId, newVersion, versionPattern, ChangeVersionValue.Changes.DEPENDENCY.name()).getVisitor()); + doAfterVisit(new ChangeDependencyVersionValue(groupId, artifactId, newVersion, versionPattern, changePropertyVersionName, ChangeDependencyVersionValue.VersionLocation.DEPENDENCY.name()).getVisitor()); } } else if (!(newDependencyManaged && configuredToChangeManagedDependency)) { diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeVersionValue.java b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyVersionValue.java similarity index 62% rename from rewrite-maven/src/main/java/org/openrewrite/maven/ChangeVersionValue.java rename to rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyVersionValue.java index e3ee6b2a0a5..ac9419254b4 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeVersionValue.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyVersionValue.java @@ -36,8 +36,8 @@ @Value @EqualsAndHashCode(callSuper = false) -public class ChangeVersionValue extends Recipe { - private static final Logger log = LoggerFactory.getLogger(ChangeVersionValue.class); +public class ChangeDependencyVersionValue extends Recipe { + private static final Logger log = LoggerFactory.getLogger(ChangeDependencyVersionValue.class); @EqualsAndHashCode.Exclude MavenMetadataFailures metadataFailures = new MavenMetadataFailures(this); @@ -46,14 +46,14 @@ public class ChangeVersionValue extends Recipe { "${version}", "${project.version}", "${pom.version}", "${project.parent.version}" )); - public enum Changes { + public enum VersionLocation { DEPENDENCY ("DEPENDENCY"), MANAGED_DEPENDENCY ("MANAGED_DEPENDENCY"), PLUGIN_DEPENDENCY ("PLUGIN_DEPENDENCY"); private final String name; - Changes(String name) { + VersionLocation(String name) { this.name = name; } @@ -88,36 +88,45 @@ public String toString() { @Nullable String versionPattern; - @Option(displayName = "Change property version names", - description = "Allows property version names to be changed to best practice naming convention", - example = "-jre", + @Option(displayName = "Change property version name", + description = "Allows property version name to be changed to best practice naming convention or what ever is in the newPropertyVersionName option. The default for this flag is `false`.", required = false) @Nullable - Boolean changePropertyVersionNames; + Boolean changePropertyVersionName; - @Option(displayName = "Change property version names", - description = "Allows property version names to be changed to best practice naming convention", - example = "-jre", + @Option(displayName = "New property version name", + description = "The new property version name used as property variable name. If it is set it will be changed. No need to set the changePropertyVersionName to true.", + example = "example.property.version", + required = false) + @Nullable + String newPropertyVersionName; + + @Option(displayName = "Declare the location where the dependency should be changed.", + description = "Changes dependency version right where you want it. The default is set to change it everywhere." + + "But you can also specifically target `DEPENDENCY`, `MANAGED_DEPENDENCY` or `PLUGIN_DEPENDENCY`." + + "It also doesn't matter if they are in a profile or not.", + example = "DEPENDENCY", required = false) @Nullable - Changes versionChangePlace; + ChangeDependencyVersionValue.VersionLocation versionLocation; - public ChangeVersionValue(String groupId, String artifactId, @Nullable String newVersion, @Nullable String versionChangePlace) { - this(groupId, artifactId, newVersion, null, false, versionChangePlace); + public ChangeDependencyVersionValue(String groupId, String artifactId, @Nullable String newVersion, @Nullable String versionLocation) { + this(groupId, artifactId, newVersion, null, false, null, versionLocation); } - public ChangeVersionValue(String groupId, String artifactId, @Nullable String newVersion, @Nullable String versionPattern, @Nullable String versionChangePlace) { - this(groupId, artifactId, newVersion, versionPattern, false, versionChangePlace); + public ChangeDependencyVersionValue(String groupId, String artifactId, @Nullable String newVersion, @Nullable String versionPattern, @Nullable Boolean changePropertyVersionName, @Nullable String versionLocation) { + this(groupId, artifactId, newVersion, versionPattern, changePropertyVersionName, null, versionLocation); } @JsonCreator - public ChangeVersionValue(String groupId, String artifactId, @Nullable String newVersion, @Nullable String versionPattern, @Nullable Boolean changePropertyVersionNames, @Nullable String versionChangePlace) { + public ChangeDependencyVersionValue(String groupId, String artifactId, @Nullable String newVersion, @Nullable String versionPattern, @Nullable Boolean changePropertyVersionName, @Nullable String newPropertyVersionName, @Nullable String versionLocation) { this.groupId = groupId; this.artifactId = artifactId; this.newVersion = newVersion; this.versionPattern = versionPattern; - this.changePropertyVersionNames = changePropertyVersionNames; - this.versionChangePlace = versionChangePlace != null ? Changes.valueOf(versionChangePlace) : null; + this.changePropertyVersionName = changePropertyVersionName != null && changePropertyVersionName; // False by default + this.newPropertyVersionName = newPropertyVersionName; + this.versionLocation = versionLocation != null ? VersionLocation.valueOf(versionLocation) : null; } @Override @@ -142,12 +151,13 @@ public Validated validate() { @Override public String getDisplayName() { - return "Change the version or the referenced property version of dependencies or plugins"; + return "Change Maven dependency version"; } @Override public String getDescription() { - return "Change the version or the referenced property version of dependencies or plugins."; + return "Change a Maven dependency version. Declare `groupId` and `artifactId` of the dependency in which the version should be changed. " + + "By adding `versionLocation`, a set of dependencies can be targeted such as managed Dependencies with `MANAGED_DEPENDENCY`."; } @Override @@ -163,30 +173,37 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { Xml.Tag t = super.visitTag(tag, ctx); - String artifact = artifactId == null ? t.getChildValue("artifactId").orElse(null) : artifactId; + if (artifactId != null){ + if (matchesGlob(tag.getChildValue("groupId").orElse(null), groupId) && (artifactId == null || matchesGlob(tag.getChildValue("artifactId").orElse(null), artifactId))) { + String artifact = artifactId == null ? t.getChildValue("artifactId").orElse(null) : artifactId; - if (matchesGlob(tag.getChildValue("groupId").orElse(null), groupId) && (artifactId == null || matchesGlob(tag.getChildValue("artifactId").orElse(null), artifactId))) { - if (versionChangePlace == null){ - return changeVersion(t, ctx, groupId, artifact, newVersion, changePropertyVersionNames); - } - switch (Objects.requireNonNull(versionChangePlace)) { - case DEPENDENCY: - if (isDependencyTag() || PROFILE_DEPENDENCY_MATCHER.matches(getCursor())){ - return changeVersion(t, ctx, groupId, artifact, newVersion, changePropertyVersionNames); - } - break; - case MANAGED_DEPENDENCY: - if (isManagedDependencyTag() || PROFILE_MANAGED_DEPENDENCY_MATCHER.matches(getCursor())){ - return changeVersion(t, ctx, groupId, artifact, newVersion, changePropertyVersionNames); + if (newVersion != null){ + if (versionLocation == null){ + return changeVersion(t, ctx); } - break; - case PLUGIN_DEPENDENCY: - if (isPluginDependencyTag(groupId, artifact) || PROFILE_PLUGIN_DEPENDENCY_MATCHER.matches(getCursor())){ - return changeVersion(t, ctx, groupId, artifact, newVersion, changePropertyVersionNames); + switch (Objects.requireNonNull(versionLocation)) { + case DEPENDENCY: + if (isDependencyTag() || PROFILE_DEPENDENCY_MATCHER.matches(getCursor())){ + return changeVersion(t, ctx); + } + break; + case MANAGED_DEPENDENCY: + if (isManagedDependencyTag() || PROFILE_MANAGED_DEPENDENCY_MATCHER.matches(getCursor())){ + return changeVersion(t, ctx); + } + break; + case PLUGIN_DEPENDENCY: + if (isPluginDependencyTag(groupId, artifact) || PROFILE_PLUGIN_DEPENDENCY_MATCHER.matches(getCursor())){ + return changeVersion(t, ctx); + } + break; } - break; + } + } } + + return t; } @@ -222,7 +239,7 @@ private String resolveSemverVersion(ExecutionContext ctx, String groupId, String return availableVersions.isEmpty() ? newVersion : Collections.max(availableVersions, versionComparator); } - public Xml.Tag changeVersion(Xml.Tag t, ExecutionContext ctx, String groupId, String artifactId, String newVersion, Boolean changePropertyVersionNames) { + public Xml.Tag changeVersion(Xml.Tag t, ExecutionContext ctx) { boolean changed = false; if (newVersion != null) { @@ -235,14 +252,18 @@ public Xml.Tag changeVersion(Xml.Tag t, ExecutionContext ctx, String groupId, St String propertyVariable = version.substring(2, version.length() - 1); String newPropertyVariable = propertyVariable; if (!matchesGlob(getResolutionResult().getPom().getProperties().get(propertyVariable), resolvedNewVersion)) { - if (Boolean.TRUE.equals(changePropertyVersionNames)) { - newPropertyVariable = artifactId + ".version"; - doAfterVisit(new RenamePropertyKey(propertyVariable, newPropertyVariable).getVisitor()); - t = changeChildTagValue(t, "version", "${" + newPropertyVariable + "}", ctx); - } doAfterVisit(new ChangePropertyValue(newPropertyVariable, resolvedNewVersion, false, false).getVisitor()); changed = true; } + newPropertyVariable = artifactId + ".version"; + if (newPropertyVersionName != null) { + newPropertyVariable = newPropertyVersionName; + } + if (!getResolutionResult().getPom().getProperties().containsKey(newPropertyVariable) && (Boolean.TRUE.equals(changePropertyVersionName) || newPropertyVersionName != null)) { + doAfterVisit(new RenamePropertyKey(propertyVariable, newPropertyVariable).getVisitor()); + t = changeChildTagValue(t, "version", "${" + newPropertyVariable + "}", ctx); + changed = true; + } } else { if (!matchesGlob(t.getChildValue("version").orElse(null), resolvedNewVersion)){ t = changeChildTagValue(t, "version", resolvedNewVersion, ctx); diff --git a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java index c0f8a854cdb..790e35e42fe 100644 --- a/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java +++ b/rewrite-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java @@ -76,12 +76,11 @@ public class ChangeManagedDependencyGroupIdAndArtifactId extends Recipe { @Nullable String versionPattern; - @Option(displayName = "Change property version names", - description = "Allows property version names to be changed to best practice naming convention", - example = "-jre", + @Option(displayName = "Change property version name", + description = "Allows property version name to be changed to best practice naming convention. The default for this flag is `false`.", required = false) @Nullable - Boolean changePropertyVersionNames; + Boolean changePropertyVersionName; public ChangeManagedDependencyGroupIdAndArtifactId(String oldGroupId, String oldArtifactId, String newGroupId, String newArtifactId, @Nullable String newVersion) { this(oldGroupId, oldArtifactId, newGroupId, newArtifactId, newVersion, null, false); @@ -92,14 +91,14 @@ public ChangeManagedDependencyGroupIdAndArtifactId(String oldGroupId, String old } @JsonCreator - public ChangeManagedDependencyGroupIdAndArtifactId(String oldGroupId, String oldArtifactId, String newGroupId, String newArtifactId, @Nullable String newVersion, @Nullable String versionPattern, @Nullable Boolean changePropertyVersionNames) { + public ChangeManagedDependencyGroupIdAndArtifactId(String oldGroupId, String oldArtifactId, String newGroupId, String newArtifactId, @Nullable String newVersion, @Nullable String versionPattern, @Nullable Boolean changePropertyVersionName) { this.oldGroupId = oldGroupId; this.oldArtifactId = oldArtifactId; this.newGroupId = newGroupId; this.newArtifactId = newArtifactId; this.newVersion = newVersion; this.versionPattern = versionPattern; - this.changePropertyVersionNames = changePropertyVersionNames; + this.changePropertyVersionName = changePropertyVersionName != null && changePropertyVersionName; // False by default } @Override @@ -154,7 +153,7 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) { } Optional versionTag = t.getChild("version"); if (versionTag.isPresent() && newVersion != null && !newVersion.equals(versionTag.get().getValue().orElse(null))) { - doAfterVisit(new ChangeVersionValue(newGroupId, newArtifactId, newVersion, versionPattern, ChangeVersionValue.Changes.MANAGED_DEPENDENCY.name()).getVisitor()); + doAfterVisit(new ChangeDependencyVersionValue(newGroupId, newArtifactId, newVersion, versionPattern, changePropertyVersionName, ChangeDependencyVersionValue.VersionLocation.MANAGED_DEPENDENCY.name()).getVisitor()); changed = true; } if (changed) { diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java index 4980351bc11..6cf15b5a4ab 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java @@ -1522,7 +1522,7 @@ void changePropertyVersionProfileDependency() { } @Test - void changePropertyVersionProfileDependencyWithChangePropertyNamesFalse() { + void changePropertyVersionProfileDependencyWithChangePropertyNameTrue() { rewriteRun( spec -> spec.recipe(new ChangeDependencyGroupIdAndArtifactId( "javax.activation", @@ -1533,7 +1533,7 @@ void changePropertyVersionProfileDependencyWithChangePropertyNamesFalse() { null, false, true, - false + true )), pomXml( """ @@ -1566,7 +1566,7 @@ void changePropertyVersionProfileDependencyWithChangePropertyNamesFalse() { my-app 1 - 2.1.0 + 2.1.0 @@ -1575,7 +1575,7 @@ void changePropertyVersionProfileDependencyWithChangePropertyNamesFalse() { jakarta.activation jakarta.activation-api - ${javax.activation.version} + ${jakarta.activation-api.version} diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeVersionValueTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyVersionValueTest.java similarity index 53% rename from rewrite-maven/src/test/java/org/openrewrite/maven/ChangeVersionValueTest.java rename to rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyVersionValueTest.java index c2a32e7e482..6604b9097e3 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeVersionValueTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyVersionValueTest.java @@ -7,17 +7,17 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.openrewrite.maven.Assertions.pomXml; -class ChangeVersionValueTest implements RewriteTest { +class ChangeDependencyVersionValueTest implements RewriteTest { @DocumentExample @Test void changeVersionValue() { rewriteRun( - spec -> spec.recipe(new ChangeVersionValue( + spec -> spec.recipe(new ChangeDependencyVersionValue( "jakarta.activation", "jakarta.activation-api", "2.1.0", - ChangeVersionValue.Changes.MANAGED_DEPENDENCY.name() + ChangeDependencyVersionValue.VersionLocation.MANAGED_DEPENDENCY.name() )), pomXml( """ @@ -61,11 +61,11 @@ void changeVersionValue() { @Test void changeVersionValueWithDynamicVersion() { rewriteRun( - spec -> spec.recipe(new ChangeVersionValue( + spec -> spec.recipe(new ChangeDependencyVersionValue( "jakarta.activation", "jakarta.activation-api", "2.1.x", - ChangeVersionValue.Changes.MANAGED_DEPENDENCY.name() + ChangeDependencyVersionValue.VersionLocation.MANAGED_DEPENDENCY.name() )), pomXml( """ @@ -96,12 +96,13 @@ void changeVersionValueWithDynamicVersion() { @Test void latestPatchVersionValue() { rewriteRun( - spec -> spec.recipe(new ChangeVersionValue( + spec -> spec.recipe(new ChangeDependencyVersionValue( "jakarta.activation", "jakarta.activation-api", "latest.patch", null, - ChangeVersionValue.Changes.MANAGED_DEPENDENCY.name() + false, + ChangeDependencyVersionValue.VersionLocation.MANAGED_DEPENDENCY.name() )), pomXml( """ @@ -145,11 +146,11 @@ void latestPatchVersionValue() { @Test void changePropertyVersionValue() { rewriteRun( - spec -> spec.recipe(new ChangeVersionValue( + spec -> spec.recipe(new ChangeDependencyVersionValue( "jakarta.activation", "jakarta.activation-api", "2.1.0", - ChangeVersionValue.Changes.MANAGED_DEPENDENCY.name() + ChangeDependencyVersionValue.VersionLocation.MANAGED_DEPENDENCY.name() )), pomXml( """ @@ -199,11 +200,11 @@ void changePropertyVersionValue() { @Test void changeProfileManagedDependencyVersionValue() { rewriteRun( - spec -> spec.recipe(new ChangeVersionValue( + spec -> spec.recipe(new ChangeDependencyVersionValue( "jakarta.activation", "jakarta.activation-api", "2.1.0", - ChangeVersionValue.Changes.MANAGED_DEPENDENCY.name() + ChangeDependencyVersionValue.VersionLocation.MANAGED_DEPENDENCY.name() )), pomXml( """ @@ -255,11 +256,11 @@ void changeProfileManagedDependencyVersionValue() { @Test void changePropertyVersionProfileManagedDependency() { rewriteRun( - spec -> spec.recipe(new ChangeVersionValue( + spec -> spec.recipe(new ChangeDependencyVersionValue( "jakarta.activation", "jakarta.activation-api", "2.1.0", - ChangeVersionValue.Changes.MANAGED_DEPENDENCY.name() + ChangeDependencyVersionValue.VersionLocation.MANAGED_DEPENDENCY.name() )), pomXml( """ @@ -319,12 +320,13 @@ void changePropertyVersionProfileManagedDependency() { @Test void changeEveryVersionOfEveryDependencyWithChangePropertyVersionName() { rewriteRun( - spec -> spec.recipe(new ChangeVersionValue( + spec -> spec.recipe(new ChangeDependencyVersionValue( "jakarta.activation", "jakarta.activation-api", "2.1.0", null, true, + null, null )), pomXml( @@ -425,12 +427,13 @@ void changeEveryVersionOfEveryDependencyWithChangePropertyVersionName() { @Test void changeOnlyTheVersionOfProfileManagedDependencyWithChangePropertyVersionName() { rewriteRun( - spec -> spec.recipe(new ChangeVersionValue( + spec -> spec.recipe(new ChangeDependencyVersionValue( "jakarta.activation", "jakarta.activation-api", "2.1.0", null, true, + null, "MANAGED_DEPENDENCY" )), pomXml( @@ -527,4 +530,392 @@ void changeOnlyTheVersionOfProfileManagedDependencyWithChangePropertyVersionName ) ); } + + @Test + void changeOnlyTheVersionOfDependencyWithChangePropertyVersionName() { + rewriteRun( + spec -> spec.recipe(new ChangeDependencyVersionValue( + "jakarta.activation", + "jakarta.activation-api", + "2.1.0", + null, + true, + null, + "DEPENDENCY" + )), + pomXml( + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + 1.2.0 + + + + test + + + jakarta.activation + jakarta.activation-api + ${javax.activation.version} + + + + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + + + + """, + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + 2.1.0 + + + + test + + + jakarta.activation + jakarta.activation-api + ${jakarta.activation-api.version} + + + + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + + + + """ + ) + ); + } + + @Test + void changeOnlyTheVersionOfPluginDependencyWithChangePropertyVersionName() { + rewriteRun( + spec -> spec.recipe(new ChangeDependencyVersionValue( + "jakarta.activation", + "jakarta.activation-api", + "2.1.0", + null, + true, + null, + "PLUGIN_DEPENDENCY" + )), + pomXml( + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + 1.2.0 + + + + test + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + + + + jakarta.activation + jakarta.activation-api + ${javax.activation.version} + + + + + + + + + """, + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + 2.1.0 + + + + test + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + + + + jakarta.activation + jakarta.activation-api + ${jakarta.activation-api.version} + + + + + + + + + """ + ) + ); + } + + @Test + void changeOnlyTheVersionOfProfileManagedDependencyWithNewPropertyVersionName() { + rewriteRun( + spec -> spec.recipe(new ChangeDependencyVersionValue( + "jakarta.activation", + "jakarta.activation-api", + "2.1.0", + null, + false, + "test", + "MANAGED_DEPENDENCY" + )), + pomXml( + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + 1.2.0 + + + + test + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + jakarta.activation + jakarta.activation-api + ${javax.activation.version} + + + + + + + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + + + + """, + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + 2.1.0 + + + + test + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + jakarta.activation + jakarta.activation-api + ${test} + + + + + + + + + jakarta.activation + jakarta.activation-api + 1.2.0 + + + + + + + + + """ + ) + ); + } + + @Test + void alreadyLatestVersionButWithPropertyChange() { + rewriteRun( + spec -> spec.recipe(new ChangeDependencyVersionValue( + "jakarta.activation", + "jakarta.activation-api", + "2.1.0", + null, + true, + "test", + null + )), + pomXml( + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + 2.1.0 + + + + test + + + + jakarta.activation + jakarta.activation-api + ${jakarta.activation-api.version} + + + + + + + """, + """ + + 4.0.0 + com.mycompany.app + my-app + 1 + + 2.1.0 + + + + test + + + + jakarta.activation + jakarta.activation-api + ${test} + + + + + + + """ + ) + ); + } } \ No newline at end of file diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactIdTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactIdTest.java index 05a5e49ea19..e799e6544c4 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactIdTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactIdTest.java @@ -355,7 +355,7 @@ void changePropertyVersionProfileManagedDependency() { } @Test - void changePropertyVersionProfileManagedDependencyWithChangePropertyVersionName() { + void changePropertyVersionProfileManagedDependencyWithChangePropertyVersionNameTrue() { rewriteRun( spec -> spec.recipe(new ChangeManagedDependencyGroupIdAndArtifactId( "javax.activation", @@ -364,7 +364,7 @@ void changePropertyVersionProfileManagedDependencyWithChangePropertyVersionName( "jakarta.activation-api", "2.1.0", null, - false + true )), pomXml( """ @@ -399,7 +399,7 @@ void changePropertyVersionProfileManagedDependencyWithChangePropertyVersionName( my-app 1 - 2.1.0 + 2.1.0 @@ -409,7 +409,7 @@ void changePropertyVersionProfileManagedDependencyWithChangePropertyVersionName( jakarta.activation jakarta.activation-api - ${javax.activation.version} + ${jakarta.activation-api.version}