Repository navigation
8.0 (fix): preserve list properties and formatting on incremental grails-plugin.xml updates - #17320
codeconsole wants to merge 6 commits into
Conversation
jdaugherty
left a comment
There was a problem hiding this comment.
Approving: the fix is correct. On 8.0.x a descriptor recompile over an existing file turns <loadAfter>[x, y]</loadAfter> into <loadAfter>xy</loadAfter> and collapses the file to one line; with this change both the descriptor-recompile path and the artefact-only path keep the list text and the multi-line layout.
One thing that does not hold as described: the artefact-only update (pluginClassNode == null) is not byte-for-byte identical to a clean build in two cases. The descriptor-recompile path matches in both.
| Plugin property | Clean build | After an artefact-only update |
|---|---|---|
A map with more than one key, e.g. dependsOn = [zeta: '1.0 > *', core: '8.0 > *', alpha: '2.0'] |
<dependsOn zeta='1.0 > *' core='8.0 > *' alpha='2.0' /> (declaration order) |
<dependsOn alpha='2.0' core='8.0 > *' zeta='1.0 > *' /> (sorted by orderedAttributes) |
An empty string, e.g. def author = '' |
<author></author> |
<author /> |
Both parse to the same thing, so this is cosmetic, but it means the form of the generated file still depends on whether an artefact source unit was compiled after the descriptor. The new test does not see it because its dependsOn has a single key and none of its properties is empty.
This does not need to hold up the PR. It can be fixed here if you are willing, with those two cases added to the byte-for-byte test, or tracked as a follow-up issue.
matrei
left a comment
There was a problem hiding this comment.
Review at 88b3fb3. The base is 8.0.x at 281bcb6, which is also the merge base. The changed files are the same on 8.1.x and 9.0.x, and the branch merges into both without conflicts.
The fix is right, and it fixes more than the description says. On 8.0.x, a descriptor compiled again over its own output turns [services, dataSource, hibernate] into servicesdataSourcehibernate and puts the whole file on one line. An artefact compiled after a descriptor that was written without artefacts is lost: there is no <resources> element to add it to, so it never gets into the descriptor, and PluginXmlHandler reads only <type> and <resource>. With this pull request, the list text, the layout and the artefact are all kept.
Following #17274, each point says whether it is a defect of the code this pull request adds, a case that behaves the same on 8.0.x, or a change from 8.0.x.
A defect of the new code
- The new
<resources>element ignores the plugin's excludes (GlobalGrailsClassInjectorTransformation.groovy:890-898). Say the descriptor, withpluginExcludes = ['**/Excluded*'], is compiled first in a compilation and written without artefacts. A later source unit withcom.example.ExcludedServiceandcom.example.KeptServicethen writes both. A clean build writes onlyKeptService, becausewritePluginXmlWithDescriptorchecks each name withisResourceExcludedByPlugin.handleExcludescan't remove it: a node added withappendNodeis not visible topluginXml.resources.resourceuntil the document is parsed again. On 8.0.x neither name gets into the descriptor. This only happens when the descriptor comes first in a compilation, so it is rare. The change under the next point fixes it in the same lines.
The same on 8.0.x (optional)
-
Two new resources in one artefact-only update (
:901-908). EachappendNode { resource(className) }closure runs when the document is written, after the loop has finished, and they all share the loop variable. Addingcom.example.Authorandcom.example.Publisherto a descriptor that listscom.example.BookgivesBook, Publisher, Publisher:Authoris lost andPublisheris there twice. 8.0.x and 7.0.x give the same. A source file with two domain classes is enough to hit it. On 8.0.x, compiling the descriptor again had the same problem. This pull request fixes it there, because that path now writes the merged names throughwritePluginXmlWithDescriptor. The new branch for a missing<resources>element runs its loop inside the closure, so it is correct. Doing the same in the other branch fixes it, and checking the names there against the excludes fixes the point above as well:@CompileDynamic private boolean updatePluginXmlResources(GPathResult pluginXml, Collection<String> artefactClassNames) { def existingResources = pluginXml.resources Collection<String> missingNames = artefactClassNames.findAll { String className -> !isResourceExcludedByPlugin(className) && !existingResources.resource.find { it.text() == className } } if (!missingNames) { return false } if (existingResources.isEmpty()) { pluginXml.appendNode { resources { for (def className : missingNames) { resource(className) } } } } else { existingResources.appendNode { for (def className : missingNames) { resource(className) } } } true }
With this change,
GlobalGrailsClassInjectorTransformationSpecpasses (61 tests), and both cases give the clean output. A feature that adds two names in one call, and one that adds an excluded name to a descriptor without<resources>, would cover them. -
jdaugherty's two cases are common in this repository. 21 plugin descriptors declare
authorEmail = '', among themMailGrailsPlugin,GebGrailsPluginandSpringSecurityCoreGrailsPlugin. After an artefact-only update they get<authorEmail />, where a clean build writes<authorEmail></authorEmail>.MimeTypesGrailsPlugindeclaresdependsOn = [core: version, controllers: version], so its keys are sorted the other way round. A value of only spaces, such asauthor = ' ', loses its spaces there (<author />), as on 8.0.x. Whether these are fixed here or in an issue, the "byte-for-byte" in the description holds only when the descriptor is compiled again.
Changes from 8.0.x worth a line in the description
- Compiling the descriptor again drops a property that was removed from the plugin class. On 8.0.x, removing
loadAfter = ['services']left<loadAfter>[services]</loadAfter>in the descriptor until a clean build. I think the new result is right, but the description doesn't mention it and no test covers it. - An artefact-only update that adds and removes nothing no longer writes the file, so its modification time stays the same. That's fine.
Neither changes what an application gets, as only <type> and <resource> are read.
Target branch
7.0.x has the same bugs. Its updatePluginXml also assigns the property values to the parsed document. The same probes there give the one-line descriptor with servicesdataSourcehibernate, the lost artefact after a descriptor without <resources>, and Publisher twice. CorePluginFinder reads the <resource> elements there. The transformation was rewritten for 8.0.x, and 8.0.x adds 676 lines to the file and removes 225 compared with 7.0.x, so this diff doesn't apply there and a 7.0.x fix would be a separate change. 8.0.x is fine for this pull request. Could you open an issue for 7.0.x, so that branch isn't forgotten?
The update path runs on incremental compilations (the IDE, or Gradle with options.incremental = true) and in full builds of a module with more than one descriptor, such as grails-test-examples/beans-dsl-plugin. Its built descriptor is on one line on 8.0.x.
Nits
- The Javadoc of
updatePluginXmlResources(:877-883) has no@returnfor the new result. The Javadoc ofupdatePluginXml(:702-711) still says that it updates the descriptor, while with a plugin class it now writes the descriptor again. The new private methods have no Javadoc, unlike the ones around them. writeFormattedPluginXmlwrites the document out, parses it and walks it. A one-line comment saying why would help the next reader: nodes added or replaced through aGPathResultshow up only after parsing again.
What I ran
GlobalGrailsClassInjectorTransformationSpecat 88b3fb3: 61 tests, no failures. CI: 89 checks pass, 7 skipped.- The two new features on the main code of 8.0.x: both fail. The first fails with the one-line descriptor and
servicesdataSourcehibernate, the second with the one-line descriptor without the resource. - Eight probes of
generatePluginXml, run at this head, on the main code of 8.0.x, and on 7.0.x (4e77c69). They cover:- a descriptor compiled again over its own output;
- artefact-only updates with one and two new names, with and without
<resources>, and with excludes; - a property removed from the plugin class;
- an update that adds nothing;
- the descriptor compiled again with two new names.
- The change suggested above: the 61 tests and the probes.
- What reads and writes the descriptor:
PluginXmlHandler(8.0.x) andCorePluginFinder(7.0.x) read only<type>and<resource>. Nothing else in the repository writes the file.
Verified as correct
- Compiling the descriptor again gives the same bytes as a clean build. This includes a description over several lines,
&,<, quotes and non-ASCII characters in a value, empty values and values of only spaces, and adependsOnwith three keys in declaration order. - An artefact compiled after a descriptor without
<resources>is kept. - Excludes still apply when the descriptor is compiled again, and to resources that are already in the file during an artefact-only update. The existing exclude features pass.
- Malformed descriptors, and descriptors with a doctype, are still written again from scratch.
sbglasius
left a comment
There was a problem hiding this comment.
The fix does what it says for the descriptor recompile: list values and the multi-line layout survive, and the output matches a clean build.
One thing in the new code: the branch that creates a missing <resources> element (updatePluginXmlResources, around line 890) adds every name without checking isResourceExcludedByPlugin. hasExcludedResources and handleExcludes can't remove it afterwards, because a node added with appendNode isn't visible through pluginXml.resources.resource until the document is parsed again. So if the descriptor with pluginExcludes is compiled first in a compilation without artefacts, a later excluded artefact ends up in the descriptor, while a clean build leaves it out. Filtering the names before appending fixes it. A test that adds an excluded name to a descriptor without <resources> would cover it.
The description says the artefact-only update matches a clean build byte-for-byte. That holds except for empty values (<author /> vs <author></author>) and maps with more than one key (attributes sorted instead of declaration order), as jdaugherty noted. Please either cover those in the test or adjust the description.
Small things: add @return to updatePluginXmlResources, update the updatePluginXml Javadoc to say it rewrites the descriptor when a plugin class is present, and add a short comment in writeFormattedPluginXml on why it serializes and parses again.
… fix multi-resource append
|
Thanks @jdaugherty and @matrei for the thorough reviews and probes — I addressed all of the findings in the follow-up commit and updated the PR description:
|
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An excluded class can still be written when the descriptor has no resources block, and an artefact-only update still drops text and attributes that are not class names.
|
|
||
| List<String> missingNames = [] | ||
| for (String className : artefactClassNames) { | ||
| if (!isResourceExcludedByPlugin(className) && existingNames.add(className)) { |
There was a problem hiding this comment.
A fresh compilation that adds com.example.ExcludedService to a descriptor with pluginExcludes [**/Excluded*] and no resources block still writes that class. The exclusion list in memory is empty, so the new block is created and the excluded class is written. The previous update did not add it when the block was absent. Apply the stored excludes before writing the new block.
There was a problem hiding this comment.
Fixed in 8902a52 — resolvePluginExcludePatterns now falls back to parsing <pluginExcludes> stored in grails-plugin.xml whenever in-memory pluginExcludePatterns is empty (such as a fresh incremental compilation), so excluded classes are filtered before creating or updating <resources>. Added a regression test using a fresh GlobalGrailsClassInjectorTransformation instance.
| private static void writeXmlNode(Node node, MarkupBuilder builder) { | ||
| String elementName = node.name().toString() | ||
| Map attributes = node.attributes() | ||
| List<Node> elementChildren = node.children().findAll { it instanceof Node } as List<Node> |
There was a problem hiding this comment.
Adding an artefact to a descriptor that contains Use this now drops the text around the child element. The writer keeps only element children when any are present. The previous writer kept Use and now. Keep the text.
There was a problem hiding this comment.
Fixed in 8902a52 — writeXmlNode now detects mixed content and renders text and child element nodes inline in order without injecting extra indentation or newlines (preserving <description>Use <b>this</b> now</description> verbatim). Added a regression test.
| if (grailsVersion) { | ||
| pluginXml.@grailsVersion = grailsVersion | ||
| private static void writeXmlNode(Node node, MarkupBuilder builder) { | ||
| String elementName = node.name().toString() |
There was a problem hiding this comment.
Adding a resource to a descriptor with Text writes the attribute as {http://www.w3.org/XML/1998/namespace}lang, which is not a valid attribute name. The descriptor can no longer be read. Write the name the parser understood.
There was a problem hiding this comment.
Fixed in 8902a52 — added PluginXmlParser (subclassing XmlParser) to preserve qualified element/attribute names (such as xml:lang) and SAX namespace prefix declarations, and normalized QName keys via QName.qualifiedName as a fallback. Added a regression test verifying <description xml:lang='en'> round-trips cleanly.
| if (text) { | ||
| builder."$elementName"(attributes, text) | ||
| } else { | ||
| builder."$elementName"(attributes) |
There was a problem hiding this comment.
Adding a resource to a descriptor that contains drops that element. The empty-element call invokes equals(Object) instead of writing a tag. The previous writer kept it. Write the tag even when its name is a builder method.
There was a problem hiding this comment.
Fixed in 8902a52 — added PluginXmlMarkupBuilder calling BuilderSupport.doInvokeMethod directly instead of Groovy MetaClass dispatch, so element names colliding with Object or MarkupBuilder methods (such as <equals label="preserve"/>) are written as XML tags. Added a regression test.
| */ | ||
| private static Set<String> extractResourceClassNames(Node pluginXml) { | ||
| Set<String> resourceNames = new LinkedHashSet<>() | ||
| Node resourcesNode = findChildElement(pluginXml, 'resources') |
There was a problem hiding this comment.
If AService is in the first resources block and BService is in a second, an artefact-only compile of BService adds a duplicate to the first block. Recompiling only the plugin class drops BService. The previous update saw both blocks. Read every resources block.
There was a problem hiding this comment.
Fixed in 8902a52 — updatePluginXmlResources now scans every <resources> block via findChildElements(pluginXml, 'resources') for both deduplication and exclusion removal, and plugin-class recompiles preserve all <resources> blocks in place. Added a regression test covering both artefact-only and plugin-class recompiles with two <resources> blocks.
|
|
||
| pluginXmlFile.withWriter(StandardCharsets.UTF_8.name()) { | ||
| createMarkup(pluginXml).writeTo(it) | ||
| Set<String> mergedResources = extractResourceClassNames(pluginXml) |
There was a problem hiding this comment.
Recompiling the plugin class for AServicekeep me keeps AService and drops the attributes and detail. It rebuilds from class names instead of the existing resource nodes. Keep the nodes this rewrite does not own. A subclass override of handleExcludes is also skipped on this path, so an existing InternalService that the override used to remove stays in the output.
There was a problem hiding this comment.
Fixed in 8902a52 — plugin-class recompiles now update the parsed Node tree in place, preserving all existing <resources> blocks, their attributes, <resource> attributes, and non-resource children such as <detail>keep me</detail>. When a subclass overrides handleExcludes(GPathResult), updatePluginXml now runs the override on a GPathResult view on both the plugin-class and artefact-only paths before writing formatted output. Added a regression test covering attributes, <detail>, and a subclass handleExcludes override removing InternalService.
…ndleExcludes overrides
jdaugherty
left a comment
There was a problem hiding this comment.
One regression in the latest commit needs fixing: reading pluginExcludes back from the old descriptor drops an artefact that the plugin class no longer excludes, which 8.0.x and a clean build keep (details inline).
The two cases from my earlier review are fixed and tested: with a three-key dependsOn, authorEmail = '', a value of only spaces, escaped characters and a multi-line description, an artefact-only update and a descriptor recompile give the same bytes as a clean build. I also ran eleven of the repository's plugin descriptors and the three in beans-dsl-plugin through a clean build, an artefact-only update and a recompile; all match. A map key with the xml: prefix, or an xmlns key, now round-trips as well.
| updatePluginXmlProperties(pluginClassNode, pluginVersion, pluginXml) | ||
| modified = true | ||
| } | ||
| Collection<String> excludePatterns = resolvePluginExcludePatterns(pluginXml) |
There was a problem hiding this comment.
Reading the excludes back from the descriptor drops an artefact that the plugin class no longer excludes. The descriptor has pluginExcludes = ['**/Excluded*'] and lists com.example.Book. The class is changed to drop pluginExcludes, and one incremental compilation compiles com.example.ExcludedService before the descriptor. The artefact-only update reads [**/Excluded*] from the old file and skips the service. When the descriptor is compiled next, the name is no longer pending, so the descriptor lists only Book until a clean build. A clean build and 8.0.x list Book and ExcludedService.
The same fallback differs from a clean build in two other cases:
- When
pluginExcludesis a String ('**/Foo*'): the clean build and the runtime ignore it, but the fallback applies it and dropsFooService. - When a pattern contains a comma:
'**/Foo,Bar*'is split into**/FooandBar*, which excludescom.example.Foo.
The case this was added for, an excluded artefact written by an update in a compilation that did not compile the descriptor, behaves the same on 8.0.x whenever <resources> exists: 8.0.x writes ExcludedService there too. So that case is pre-existing and optional for this PR. Please take resolvePluginExcludePatterns out and keep the in-memory list; excludes in a fresh compilation can go to an issue.
There was a problem hiding this comment.
Good catch — removed resolvePluginExcludePatterns in 64ed7a7 so only the in-memory pluginExcludePatterns list is used, matching 8.0.x and clean builds. I replaced the fallback test with a regression test covering dropping pluginExcludes and compiling ExcludedService before recompiling the descriptor.
|
|
||
| List<Node> existingResourcesNodes = findChildElements(pluginXml, 'resources') | ||
| List<Object> children = pluginXml.children() | ||
| children.clear() |
There was a problem hiding this comment.
When a recompiled plugin class excludes every resource already in the descriptor, the update leaves the indentation behind: <resources>\n \n </resources>, where a clean build writes <resources />. Steps: a descriptor with com.example.Book, then the class gets pluginExcludes = ['**/Book*']. It parses the same, so this is cosmetic; dropping the whitespace-only text when the last <resource> is removed would make it match.
There was a problem hiding this comment.
Fixed in 64ed7a7 — when the last <resource> is removed from a <resources> element and only whitespace text remains, updatePluginXmlResources now clears those whitespace children so it emits <resources />. Added a regression test for this case.
|
|
||
| List<Node> existingResourcesNodes = findChildElements(pluginXml, 'resources') | ||
| List<Object> children = pluginXml.children() | ||
| children.clear() |
There was a problem hiding this comment.
A question for the wider group, because this line decides it: a plugin can describe itself in its plugin class or in grails-plugin.xml, and with this children.clear() a recompile of the plugin class makes the class the only source. Whatever the existing descriptor holds that the class does not declare is removed. That covers a property that was removed from the class, and also an element that was added to the file by hand.
Measured on a descriptor recompile (the plugin class compiled over an existing file):
| In the file, not in the class | 8.0.x | Here |
|---|---|---|
<customNote>keep me</customNote> added by hand, at the end or between <type> and <loadAfter> |
kept, in place | dropped |
| a property that was removed from the class | kept until a clean build | dropped |
An artefact-only update keeps the hand-added element on both, and an attribute added to <plugin> and a hand-added <resource> are kept on both paths.
The file does not record which elements were generated, so the two rows cannot be told apart: it is one rule or the other. I am fine with the descriptor holding only what the class declares. A descriptor that is checked in under src/main/resources, as grails-core has, is not affected, since the transformation only writes the one in the compiler output directory. But it is a change from 8.0.x, so I would like @matrei, @sbglasius and @jamesfredley to weigh in before it merges. If we keep it, it needs an upgrade note.
There was a problem hiding this comment.
To avoid introducing a behavioral change on 8.0.x (or holding this PR for an upgrade note and wider sign-off), in d60775a I switched updatePluginXmlProperties to upsert <type> and declared plugin properties in place—inserting newly declared ones before <resources> and leaving unowned top-level elements and any existing grailsVersion untouched—matching 8.0.x behavior while keeping the clean-build byte fidelity fix.
jdaugherty
left a comment
There was a problem hiding this comment.
Re-reviewed at d60775a against 8.0.x. Two compatibility regressions remain, detailed inline: prefixed descriptor elements are no longer matched during updates, and a handleExcludes override receives resources after the default policy has already removed entries. Both were reproduced against this head and the base transformation.
The stale descriptor-excludes regression from my last review is fixed. The list/formatting cases, multiple-resource append, mixed-content and attribute preservation, empty-resource cleanup, and preservation of undeclared top-level elements are also addressed.
Verification: GlobalGrailsClassInjectorTransformationSpec passes all 67 tests on JDK 21; the attached CLI tests pass, and git diff --check passes. Five targeted base/head probes were run, including checking the resulting descriptors through the public runtime scanner. The latest-head GitHub checks are still queued or skipped; the full repository suites, codeStyle and buildHealth were not rerun locally.
The description also needs a small update: it still says removed class properties are dropped and describes rewriting through writePluginXmlWithDescriptor, while the latest implementation updates in place and preserves undeclared elements.
| private static List<Node> findChildElements(Node parent, String name) { | ||
| List<Node> matches = [] | ||
| for (Object child : parent.children()) { | ||
| if (child instanceof Node && formatXmlName(((Node) child).name()) == name) { |
There was a problem hiding this comment.
[P2] Match descriptor elements by local name while preserving prefixes when writing
The parser now retains qualified names, so this comparison does not recognize a valid <p:resources> element as resources. The same issue affects the resource comparison and upsertChildElement for type. With a declared p namespace, an existing prefixed resource block containing com.example.ExcludedService and com.example.Book, and a descriptor recompile declaring pluginExcludes = ['**/Excluded*'] and supplying Book, the base leaves only Book. This head leaves the excluded resource in the prefixed block and appends Book again in a new unprefixed block. The public runtime scanner reads both blocks, yielding ExcludedService, Book, Book. A prefixed old type is likewise retained beside the new type, and both are discovered at runtime.
Please retain the previous local-name matching semantics for these updates while preserving qualified names for serialization, and cover prefixed resources/type elements in the regression tests. This changes which classes are discovered, not just the descriptor's formatting.
There was a problem hiding this comment.
Fixed in 8edf2ef — findChildElements, upsertChildElement, and updatePluginXmlResources now match descriptor elements by local name via localXmlName(...) while preserving existing namespace prefixes when updating or appending (<p:type>, <p:resources>, <p:resource>). Added a regression test covering a p-prefixed descriptor across both descriptor recompile with pluginExcludes and artefact-only append.
| if (updatePluginXmlResources(pluginXml, artefactClassNames)) { | ||
| modified = true | ||
| } | ||
| if (isHandleExcludesOverridden()) { | ||
| Node updatedByOverride = applyOverriddenHandleExcludes(pluginXml) |
There was a problem hiding this comment.
[P2] Let handleExcludes overrides retain their replacement-policy semantics
The override is called again, but updatePluginXmlResources has already applied the default exclusions before it runs. Previously the virtual handleExcludes call owned that filtering decision, so an override could replace the policy without calling super. Reproduced with an existing descriptor containing ExcludedService and Book, pluginExcludes = ['**/Excluded*'], and an override that retains the existing resources: the base preserves both entries, while this head removes ExcludedService before the override sees it. A subclass implementing exemptions therefore cannot preserve an entry it previously kept.
Please avoid unconditionally applying the default removal policy ahead of a replacement override. The added override test calls super and only removes additional entries; add coverage for an override that deliberately retains an otherwise excluded existing resource.
There was a problem hiding this comment.
Fixed in 8edf2ef — when isHandleExcludesOverridden() is true, updatePluginXmlResources skips applying the default pluginExcludePatterns filter so the overridden handleExcludes(GPathResult) sees all existing and newly added resources and retains full replacement-policy semantics (with whitespace cleanup after the override runs). Added a regression test with a replacement override that deliberately retains both existing and newly added excluded resources.
jdaugherty
left a comment
There was a problem hiding this comment.
Requesting changes for the two compatibility regressions detailed in #17320 (review): prefixed descriptor elements are no longer matched during updates, and handleExcludes overrides receive resources after the default policy has already removed entries. Both were reproduced against the base and this head. The earlier stale descriptor-excludes issue is fixed.
…es overrides replace defaults
✅ All tests passed ✅🏷️ Commit: 8edf2ef Learn more about TestLens at testlens.app/docs. |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. An artefact-only update still drops attributes, and it still drops an empty namespace reset.
| if (child instanceof Node && localXmlName(((Node) child).name()) == localName) { | ||
| if (firstMatch < 0) { | ||
| firstMatch = i | ||
| children.set(i, createPropertyNode(formatXmlName(((Node) child).name()), value)) |
There was a problem hiding this comment.
Recompiling a descriptor that contains <p:type xmlns:p="urn:plugin" label="custom">OldPlugin</p:type> writes <p:type>NewPlugin</p:type>. The attributes are gone and the prefix is unbound. The previous update kept the attributes. Keep them when the element is replaced.
|
|
||
| @Override | ||
| void startPrefixMapping(String prefix, String uri) throws SAXException { | ||
| if (uri) { |
There was a problem hiding this comment.
Adding an artefact to keep me drops xmlns="". The detail element moves into urn:plugin. The empty namespace reset has to be written back.
Summary
GlobalGrailsClassInjectorTransformation.updatePluginXml(...)so incremental updates to an existingMETA-INF/grails-plugin.xmlpreserve list values (e.g.,loadAfter,watchedResources,pluginExcludes), map attributes in declaration order (e.g.,dependsOn), whitespace-only leaf values, empty tags, mixed content, namespaced elements/attributes, builder-colliding tag names, and multi-lineMarkupBuilderformatting.updatePluginXmlto parse via a hardenedPluginXmlParser(XmlParserbacked byIOUtils.newSAXParser()rejectingDOCTYPE/XXE while preserving qualified names, SAX namespace bindings, lexical attribute order, and whitespace-only leaf values) and update theNodetree in place:pluginClassNode != null,updatePluginXmlPropertiesupdates<plugin>attributes,<type>, and declared plugin properties in place (matching by local name while preserving any existing namespace prefixes), inserts newly declared properties before<resources>, and leaves undeclared/hand-added top-level elements,<resources>attributes,<resource>attributes, and extra<resources>children untouched—matching8.0.xsemantics.updatePluginXmlResourcesinspects every<resources>block (matched by local name), appends multiple new artefacts directly without the lazyappendNodeclosure-capture bug (creating<resources>when absent), collapses whitespace-only<resources>elements to<resources />when the last<resource>is excluded, and skips rewriting the file when nothing changed.protected void handleExcludes(GPathResult),updatePluginXmldefers exclusion filtering to the override on aGPathResultview so replacement policies can retain or filter entries without the default policy removing them first.'') to self-closing elements (<authorEmail />) and usedPluginXmlMarkupBuilder(callingBuilderSupport.doInvokeMethoddirectly) so clean builds and incremental updates produce identical formatted XML even for tag names colliding withObject/MarkupBuildermethods.GlobalGrailsClassInjectorTransformationSpeccovering clean-vs-incremental byte parity, list properties, multi-key maps, empty/whitespace values, missing<resources>withpluginExcludes, droppingpluginExcludes, collapsing empty<resources />, mixed content,xml:lang,<equals>, multiple<resources>blocks, prefixed<p:type>/<p:resources>/<p:resource>, preserved undeclared elements and<resources>attributes/<detail>, and subclasshandleExcludesoverrides (both extending and replacing the default policy).Motivation
During incremental compilation (or multi-descriptor builds) of a Grails plugin module, updating an existing
META-INF/grails-plugin.xmlrewrote the descriptor on one line, flattened list-valued properties (loadAfter,watchedResources, etc.), lost artefacts when<resources>was absent, and duplicated the last resource when adding multiple artefacts in one update.I targeted
8.0.xso this fix merges cleanly forward to8.1.xand9.0.x(whereGlobalGrailsClassInjectorTransformation.groovyis identical), and opened #17323 to track the separate backport needed for7.0.x.Verification
./gradlew :grails-core:codeStyle :grails-core:testin the8.0.xcheckout — all style checks and tests passed.