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

Fixes #3144 RenamePropertyKey and ChangePropertyValue running together #3226

Merged
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 @@ -73,6 +73,7 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
Xml.Tag t = super.visitTag(tag, ctx);
if (isPropertyTag() && oldKey.equals(t.getName())) {
t = t.withName(newKey);
maybeUpdateModel();
Copy link
Contributor Author

@ge0ffrey ge0ffrey May 10, 2023

Choose a reason for hiding this comment

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

I verified that adding this change fixes the issue, by using local SNAPSHOT builds (and without it, the issue reproduces). See screenshots above.

But... the test below seems to NOT fail if this line isn't there (TDD:it should fail if the test environment matches a real environment).

}
if (t.getChildren().isEmpty()) {
Optional<String> value = t.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,53 @@ void propertyInProperty() {
)
);
}

@Test
void renamePropertyAndValue() {
String yamlRecipe = """
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.RenamePropertyAndValue
displayName: RenamePropertyAndValue
description: RenamePropertyAndValue description
recipeList:
- org.openrewrite.maven.RenamePropertyKey:
oldKey: "abc"
newKey: "def"
- org.openrewrite.maven.ChangePropertyValue:
key: "def"
newValue: "2.0"
""";
rewriteRun(
spec -> spec.recipeFromYaml(yamlRecipe, "org.openrewrite.RenamePropertyAndValue"),
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>

<properties>
<abc>1.0</abc>
</properties>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>

<properties>
<def>2.0</def>
</properties>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
"""
)
);
}
}