You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/05/19 13:33:45 UTC

(maven) branch maven-4.0.x updated: fix: restore buildConfiguration() callback in deprecated build() methods (#12094)

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/maven-4.0.x by this push:
     new be7d73b2c5 fix: restore buildConfiguration() callback in deprecated build() methods (#12094)
be7d73b2c5 is described below

commit be7d73b2c5d2e28b450675c05861c816434c4cbb
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue May 19 15:33:27 2026 +0200

    fix: restore buildConfiguration() callback in deprecated build() methods (#12094)
    
    The MNG-7947 refactoring changed the deprecated build(Reader, String) and
    build(InputStream, String) methods to delegate to the new
    build(ReaderSupplier/StreamSupplier, String) methods, which bypassed the
    overridable buildConfiguration() method. This broke subclasses (such as
    EnhancedPluginDescriptorBuilder in maven-plugin-tools) that override
    buildConfiguration() to intercept the parsed configuration.
    
    Restore the buildConfiguration() callback in the legacy code path while
    still supporting PLUGIN 2.0.0 namespace detection.
    
    Co-authored-by: Claude Opus 4.6 <no...@anthropic.com>
---
 .../plugin/descriptor/PluginDescriptorBuilder.java | 38 ++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/compat/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/compat/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
index b6edfc04c1..086a49daaf 100644
--- a/compat/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
+++ b/compat/maven-plugin-api/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
@@ -71,7 +71,24 @@ public PluginDescriptor build(Reader reader) throws PlexusConfigurationException
      */
     @Deprecated
     public PluginDescriptor build(Reader reader, String source) throws PlexusConfigurationException {
-        return build(() -> reader, source);
+        try {
+            BufferedReader br = new BufferedReader(reader, BUFFER_SIZE);
+            br.mark(BUFFER_SIZE);
+            XMLStreamReader xsr = XMLInputFactory.newFactory().createXMLStreamReader(br);
+            xsr.nextTag();
+            String nsUri = xsr.getNamespaceURI();
+            br.reset();
+            if (PLUGIN_2_0_0.equals(nsUri)) {
+                xsr = XMLInputFactory.newFactory().createXMLStreamReader(br);
+                return new PluginDescriptor(new PluginDescriptorStaxReader().read(xsr, true));
+            } else {
+                // Call buildConfiguration() for backward compatibility with subclasses that override it
+                PlexusConfiguration cfg = buildConfiguration(br);
+                return build(source, cfg);
+            }
+        } catch (XMLStreamException | IOException e) {
+            throw new PlexusConfigurationException(e.getMessage(), e);
+        }
     }
 
     public PluginDescriptor build(ReaderSupplier readerSupplier) throws PlexusConfigurationException {
@@ -98,7 +115,24 @@ public PluginDescriptor build(ReaderSupplier readerSupplier, String source) thro
      */
     @Deprecated
     public PluginDescriptor build(InputStream input, String source) throws PlexusConfigurationException {
-        return build(() -> input, source);
+        try {
+            BufferedInputStream bis = new BufferedInputStream(input, BUFFER_SIZE);
+            bis.mark(BUFFER_SIZE);
+            XMLStreamReader xsr = XMLInputFactory.newFactory().createXMLStreamReader(bis);
+            xsr.nextTag();
+            String nsUri = xsr.getNamespaceURI();
+            bis.reset();
+            if (PLUGIN_2_0_0.equals(nsUri)) {
+                xsr = XMLInputFactory.newFactory().createXMLStreamReader(bis);
+                return new PluginDescriptor(new PluginDescriptorStaxReader().read(xsr, true));
+            } else {
+                // Call buildConfiguration() for backward compatibility with subclasses that override it
+                PlexusConfiguration cfg = buildConfiguration(bis);
+                return build(source, cfg);
+            }
+        } catch (XMLStreamException | IOException e) {
+            throw new PlexusConfigurationException(e.getMessage(), e);
+        }
     }
 
     public PluginDescriptor build(StreamSupplier inputSupplier) throws PlexusConfigurationException {