Skip to content

Commit

Permalink
Fix: Remove comments associated with deleted properties in pom.xml
Browse files Browse the repository at this point in the history
Fixes #35

Enhance the `removeOffendingProperties` method in `PomModifier.java` to remove comments associated with deleted properties.

* Identify comments directly above the properties `jenkins-test-harness.version` and `java.level` and remove them along with the properties.
* Update unit tests in `PomModifierTest.java` to verify the removal of comments associated with deleted properties.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/gounthar/plugin-modernizer-tool/issues/35?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
gounthar committed Oct 11, 2024
1 parent 9c7e63d commit 4028ec7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public void removeOffendingProperties() {
if (node.getNodeType() == Node.ELEMENT_NODE) {
String nodeName = node.getNodeName();
if (nodeName.equals("jenkins-test-harness.version") || nodeName.equals("java.level")) {
// Remove associated comments
Node previousSibling = node.getPreviousSibling();
while (previousSibling != null && previousSibling.getNodeType() == Node.COMMENT_NODE) {
propertiesNode.removeChild(previousSibling);
previousSibling = node.getPreviousSibling();
}
propertiesNode.removeChild(node);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public void testRemoveOffendingProperties() throws Exception {
.getLength()
== 0);
logger.info("Offending properties removed successfully");

// Verify that comments associated with the removed properties are also removed
String pomContent = new String(Files.readAllBytes(Paths.get(OUTPUT_POM_PATH)));
assertTrue(!pomContent.contains("<!-- Java Level to use. Java 7 required when using core >= 1.612 -->"));
assertTrue(!pomContent.contains("<!-- Jenkins Test Harness version you use to test the plugin. -->"));
}

@Test
Expand Down

0 comments on commit 4028ec7

Please sign in to comment.