Let users choose which files `XmlParser` parses as XML
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with XmlParser.accept(Path), ACCEPTED_FILE_EXTENSIONS, and XmlParser.Builder; the issue describes the parser API change and names plainTextMasks as a model for build tool integration. Trace how the Maven and Gradle integrations configure parsing, then check whether the Moderne CLI option is in scope. Done means users can configure additional XML file patterns and those files reach XML recipes during a real build.
Written by the indexing model from the issue text.
Description
Problem
XmlParser.accept(Path) decides what is XML from a hard-coded set, ACCEPTED_FILE_EXTENSIONS, plus a few file names such as nuget.config. Neither XmlParser.Builder nor the build tool integrations offer a way to extend it. Any XML file with an extension outside the list is passed to the plain-text parser, so XML recipes never see it.
Every new format so far has needed its own issue and an OpenRewrite release (for example jrxml, #6512). Projects use many XML dialects with their own extensions, and the list can't keep up.
Our case: eXist-db is a native XML database, and its ecosystem uses many XML formats with their own file extensions. For example, collection configuration lives in collection.xconf files. Recipes targeting these files pass in RewriteTest, because xml(…) parses explicitly. In a real mod build / rewriteRun, though, the files come through as PlainText, and the recipes silently do nothing. Adding one extension at a time to OpenRewrite wouldn't cover them.
Proposal
-
Parser: add an option to
XmlParser.Builderthat adds to the defaults rather than replacing them, for example:XmlParser.builder() .additionalFileExtensions("xconf") .build();acceptwould check these after the built-in set. An optional path-glob variant (additionalPathMatchers("**/*.xconf")) could also cover specific file names, as the special-casing ofnuget.configdoes today. -
Build tool integrations: expose the option where the code model is built, otherwise the parser API alone can't be used. For example:
- rewrite-maven-plugin:
<xmlMasks>/-Drewrite.xmlMasks=**/*.xconf, mirroring the existingplainTextMasks - rewrite-gradle-plugin:
rewrite { xmlMasks = ["**/*.xconf"] } - Moderne CLI: the equivalent
mod buildoption or config entry
Masks would make XML consistent with how
plainTextMasksalready lets users pull files into plain-text parsing. - rewrite-maven-plugin:
Alternatives considered
- Adding each extension to
ACCEPTED_FILE_EXTENSIONS. This works case by case but doesn't scale, and every project with custom formats has to wait for an OpenRewrite release. - Copying or renaming files to
.xmlbefore building the code model. This needs a script outside OpenRewrite in every user's repository. Diffs and data tables then show the wrong path, and it's impossible on the Moderne platform, where users don't control the build step. - Re-parsing the
PlainTextas XML inside a recipe. This works as a bridge, but every recipe author has to do it again, and search markers have to be translated back.
Happy to contribute
We can open a PR for the XmlParser.Builder part if the API shape works for you.
- Dominant language
- Java
- Stars
- 3.9k
- Forks
- 599
- Avg merge
- 9h 38m
- Merged PRs (30d)
- 557
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openrewrite/rewrite
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
openrewrite/rewrite#9835 ·
Maintainers usually reply within 1 day
-
bug gradle
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openrewrite/rewrite#7576 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
openrewrite/rewrite#9834 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
openrewrite/rewrite#9819 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 55/100
openrewrite/rewrite#9817 ·
Maintainers usually reply within 1 day
All issues in openrewrite/rewrite
Similar issues
-
Four TestConstraintBasedAlgorithm tests pass when nothing is thrownPossibly taken @sharanggupta claimed this today. Open
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
-
bug documentation good first issue help wanted priority low size XS
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
martin-francois/symphony-trello#1351 ·
Maintainers usually reply within 1 day
-
Add test coverage for ConvertUtil.parseDate() with NULL inputPossibly taken @mirajul-mollah7 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 78/100
eclipse-sw360/sw360#4792 · 1 comment ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
aws/aws-emulator#30 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 4 days