Repository navigation
Edit the .idea XML files with the JDK's DOM instead of Groovy's XmlParser - #266
Merged
abashev merged 1 commit intoNov 23, 2026
Merged
Conversation
…rser
XmlUtils and ConfigureJavaFormatterXml read and wrote
.idea/open-java-format.xml, workspace.xml and externalDependencies.xml
with Groovy's XmlParser, XmlNodePrinter and groovy.util.Node. The
plugin does not declare Groovy: it came with gradleApi() at compile
time and, at run time, from the Groovy that the build's Gradle
bundles, which once already dropped groovy.util.XmlParser.
They parse with the JDK's DocumentBuilder now and edit the DOM. The
DOM keeps an element's attributes sorted by name, so a second pass
with SAX records the order of the file. A printer of the plugin's own
writes the files as IntelliJ does: the XML declaration, two spaces of
indentation, a space before "/>", the attributes in the order of the
file and those added after them, and no line break at the end. Text
and CDATA come out as they are. The files are written in UTF-8, which
IntelliJ reads, rather than in the JVM's default charset.
A file is written only when what the printer makes of it changes, so
a file with nothing to change keeps its bytes, however it was written.
Before, the plugin rewrote each file every time its task ran.
A min-version="" counts as none now; Version.parse("") failed the
task.
Fixes #262.
abashev
deleted the
abashev/edit-the-.idea-xml-files-with-the-jdks-dom-inste
branch
November 23, 2026 19:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #262. Based on
21.X.X; there are no other open pull requests.XmlUtilsandConfigureJavaFormatterXmlread and wrote.idea/open-java-format.xml,workspace.xmlandexternalDependencies.xmlwith Groovy'sXmlParser,XmlNodePrinterandgroovy.util.Node. The plugin does not declare Groovy: the classes came withgradleApi()at compile time and, at run time, from the Groovy that the build's Gradle bundles, which once already droppedgroovy.util.XmlParser(palantir#1536). The plugin's classes now reference nogroovyclass at all.How the files are read and written
DocumentBuilderFactory.newDefaultInstance(), the JDK's own parser even when a build brings another one, and the plugin edits the DOM. DTDs are refused, as Groovy'sXmlParserrefused them./>,"in text, and	in attributes, and no line break at the end. Whitespace between elements gives way to that indentation; text and CDATA come out as they are, and so does the rest of their element. The JDK'sTransformer, tried in Edit the .idea XML files with the JDK's DOM instead of Groovy's XmlParser #262, indents on top of the whitespace the parser kept, sorts the attributes and writesstandalone="no".Charset.defaultCharset().open-java-format.xml, whose classpath listconfigureJavaFormatempties and fills again on every sync.What changes for users
/>.min-version=""on the plugin's entry inexternalDependencies.xmlcounts as nomin-version;Version.parse("")failed the task before.Tests
XmlUtilsTest, new, works on files:externalDependencies.xmlwith nothing to change keeps its bytes when written by IntelliJ, by the plugin before, or by hand with four spaces, CRLF, a comment and single quotes; so does anopen-java-format.xmlwith the same classpath;OptimizeOnSaveOptionsto an IntelliJworkspace.xmlwith CDATA,"in text, in an attribute and non-ASCII text leaves the rest of the file byte for byte;ConfigureJavaFormatterXmlTestruns on the DOM, and its expected text has the space before/>and no line break at the end.RequiredIdeaPluginTestexpects the space too.workspace.xml,open-java-format.xml,palantir-java-format.xmlandexternalDependencies.xmlin the.ideadirectories on my machine, 42 files. The 38 that IntelliJ wrote come out byte for byte, CDATA and character references included. The 4 that differ are ones the plugin wrote before../gradlew :gradle-open-java-format:checkpasses on JDK 21: 156 tests, Checkstyle and forbidden-apis.PalantirJavaFormatPluginTest,PalantirJavaFormatSpotlessPluginTestandFormatDiffTestneed the native image and are left to CI'snativejobs.Not tried in a running IDE.