#943: rework combine of text nodes in XML merger - #2324
Conversation
Coverage Report for CI Build 32475768641Coverage increased (+0.05%) to 73.021%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions2 previously-covered lines in 1 file lost coverage.
Coverage Stats💛 - Coveralls |
|
All tests cases pass. combine-text-nodes-mixed and combine-text-nodes cover what is needed. About trim behavior, it is now consistent. As it overwrite and append path trim. Because of getText() method trim, append path now matches overwrite path. Good work! |
|
Successfully tested with 2026.08.002-08_27_12-SNAPSHOT on Windows. Retested against a fresh project ( The merged workspace file matches
|
|
Also verified idempotency, ran ide -d vscode three times in a row without restoring the workspace file. Output is byte-identical after every iteration and still matches result.xml, so repeated merges no longer drift. |
This PR fixes #943
Implemented changes:
XmlMergeStrategy.replaceTextNodeso that it no longer restarts its search at the first child of the result element on every call. It now receives the index to start searching from and returns the index to continue from, so the n-th textual child of the template is merged into the n-th textual child of the result.XmlMergeStrategy.combineChildNodesto carry that index across loop iterations instead of callingreplaceTextNodewith no position information.combine-text-nodesandcombine-text-nodes-mixed.This only affects elements that have more than one textual child, which is why it went unnoticed. Almost all configuration files handled by the merger use a single text node per element, and that case was and still is merged correctly. Multiple textual children occur when a CDATA section sits next to plain text, for example in formatter or file header templates.
Note that the code referenced in the issue has been moved since the issue was written. It is now in
cli/src/main/java/com/devonfw/tools/ide/merge/xml/XmlMergeStrategy.javaand the reported behaviour was unchanged by that move.Testing instructions
Please add conscise, understandable instructions on how a reviewer can test/verify the functionality of your contribution here:
com.devonfw.tools.ide.merge.xml.XmlMergerTestfrom your IDE. The relevant test method istestMerger, which is a parameterized test with one execution per subfolder ofcli/src/test/resources/xmlmerger. All 21 executions should pass, 19 of which existed before this PR.combine-text-nodesandcombine-text-nodes-mixed. Each test folder containstemplate.xmlas the merge template,target.xmlas the existing workspace file, andresult.xmlas the expected merge output.cli/src/test/resources/xmlmerger/combine-text-nodesonto a checkout without the change inXmlMergeStrategy.javaand runXmlMergerTestagain. Thecombine-text-nodesexecution then fails withexpected:<...text1<![CDATA[text2]]>text3...> but was:<...text3<![CDATA[text5]]>text6...>.The test cases cover the following:
combine-text-nodeselem1combine-text-nodeselem2combine-text-nodeselem3combine-text-nodeselem4combine-text-nodes-mixedelem1Checklist for this PR
Make sure everything is checked before merging this PR. For further info please also see
our DoD.
mvn clean testlocally all tests pass and build is successful#«issue-id»: «brief summary»(e.g.#921: fixed setup.batand notfeature/921 fixed setup.bat). If no issue ID exists, title only.In Progressand assigned to you or there is no issue (might happen for very small PRs)with
internalpom.xmlfiles or otherwise if runtime dependencies changed, you have updated our LICENSE.asciidoc