Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore newArtifactId property in ChangePluginGroupIdAndArtifactId #4421

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ public class ChangePluginGroupIdAndArtifactId extends Recipe {
example = "my-new-maven-plugin",
required = false)
@Nullable
String newArtifactId;

/**
* Mistakenly introduced, we restored newArtifactId but let's not break recipes abruptly.
*/
@Option(displayName = "New artifact ID",
description = "The new artifact ID to use. Defaults to the existing artifact ID. This property is deprecated, use newArtifactId instead.",
example = "my-new-maven-plugin",
required = false)
@Nullable
@Deprecated
@SuppressWarnings("DeprecatedIsStillUsed")
String newArtifact;
Comment on lines +64 to 71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the extra effort to remain backwards compatible; I ran a quick search to see if anything used the constructor, but thankfully that does not seem to be the case. https://app.moderne.io/results/MSJWn0HY8
Via a run of org.openrewrite.java.search.FindMethods with methodPattern *..ChangePluginGroupIdAndArtifactId <constructor>(..) against the OpenRewrite GitHub org.


@Override
Expand All @@ -65,7 +77,7 @@ public String getDisplayName() {

@Override
public String getInstanceNameSuffix() {
return String.format("`%s:%s`", newGroupId, newArtifact);
return String.format("`%s:%s`", newGroupId, newArtifactId);
}

@Override
Expand All @@ -84,7 +96,9 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
if (newGroupId != null) {
t = changeChildTagValue(t, "groupId", newGroupId, ctx);
}
if (newArtifact != null) {
if (newArtifactId != null) {
t = changeChildTagValue(t, "artifactId", newArtifactId, ctx);
} else if (newArtifact != null) {
t = changeChildTagValue(t, "artifactId", newArtifact, ctx);
}
if (t != tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,85 @@ void changePluginGroupIdAndArtifactId() {
"io.quarkus",
"quarkus-bootstrap-maven-plugin",
null,
"quarkus-extension-maven-plugin",
null
)),
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
<version>3.0.0.Beta1</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>profile</id>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
<version>3.0.0.Beta1</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<version>3.0.0.Beta1</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>profile</id>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<version>3.0.0.Beta1</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
"""
)
);
}

@DocumentExample
@Test
void changePluginGroupIdAndArtifactIdDeprecatedNewArtifact() {
rewriteRun(
spec -> spec.recipe(new ChangePluginGroupIdAndArtifactId(
"io.quarkus",
"quarkus-bootstrap-maven-plugin",
null,
null,
"quarkus-extension-maven-plugin"
)),
pomXml(
Expand Down Expand Up @@ -107,7 +186,8 @@ void changePluginGroupIdAndArtifactIdNoChange() {
"io.quarkus",
"quarkus-bootstrap-maven-plugin",
null,
"quarkus-extension-maven-plugin"
"quarkus-extension-maven-plugin",
null
)),
pomXml(
"""
Expand Down Expand Up @@ -152,7 +232,8 @@ void changeManagedPluginGroupIdAndArtifactId() {
"io.quarkus",
"quarkus-bootstrap-maven-plugin",
null,
"quarkus-extension-maven-plugin"
"quarkus-extension-maven-plugin",
null
)),
pomXml(
"""
Expand Down Expand Up @@ -262,7 +343,8 @@ void changeManagedPluginGroupIdAndArtifactIdNoChange() {
"io.quarkus",
"quarkus-bootstrap-maven-plugin",
null,
"quarkus-extension-maven-plugin"
"quarkus-extension-maven-plugin",
null
)),
pomXml(
"""
Expand Down