Skip to content

Commit

Permalink
RemoveProperty now updates the maven model afterward, and, removes th…
Browse files Browse the repository at this point in the history
…e `properties` section if left empty
  • Loading branch information
nmck257 committed Feb 14, 2024
1 parent ababd3e commit 9fed57a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openrewrite.Option;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.xml.RemoveContentVisitor;
import org.openrewrite.xml.tree.Xml;

@Value
Expand Down Expand Up @@ -51,7 +52,8 @@ private class RemovePropertyVisitor extends MavenVisitor<ExecutionContext> {
@Override
public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
if (isPropertyTag() && propertyName.equals(tag.getName())) {
return null;
doAfterVisit(new RemoveContentVisitor<>(tag, true));
maybeUpdateModel();
}
return super.visitTag(tag, ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,34 @@ void removeProperty() {
)
);
}

@Test
void removeOnlyProperty() {
rewriteRun(
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<bla.version>b</bla.version>
</properties>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
"""
)
);
}
}

0 comments on commit 9fed57a

Please sign in to comment.