Skip to content

Commit

Permalink
Restore newArtifactId property in ChangePluginGroupIdAndArtifactId (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet authored Aug 15, 2024
1 parent 3672f4a commit e18cf17
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 5 deletions.
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;

@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

0 comments on commit e18cf17

Please sign in to comment.