From b784cb6115bb75f7db4ad9799c5f5a37c57af145 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 26 Apr 2026 13:05:12 +0200 Subject: [PATCH 1/4] Remove deprecated XmlNode constant references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also replaced deprecated XmlNode accessor methods with fluent alternatives: - getName() → name() - getValue() → value() - getAttributes() → attributes() - getChildren() → children() - getInputLocation() → inputLocation() - getChild() → child() - getAttribute() → attribute() --- .../org/codehaus/plexus/util/xml/Xpp3Dom.java | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java index 0e8ddfe9..ed9ee339 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.maven.api.xml.XmlNode; +import org.apache.maven.api.xml.XmlService; import org.apache.maven.internal.xml.XmlNodeImpl; import org.codehaus.plexus.util.xml.pull.XmlSerializer; @@ -33,26 +34,26 @@ public class Xpp3Dom implements Serializable { private static final String[] EMPTY_STRING_ARRAY = new String[0]; - public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = XmlNode.CHILDREN_COMBINATION_MODE_ATTRIBUTE; + public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = XmlService.CHILDREN_COMBINATION_MODE_ATTRIBUTE; - public static final String CHILDREN_COMBINATION_MERGE = XmlNode.CHILDREN_COMBINATION_MERGE; + public static final String CHILDREN_COMBINATION_MERGE = XmlService.CHILDREN_COMBINATION_MERGE; - public static final String CHILDREN_COMBINATION_APPEND = XmlNode.CHILDREN_COMBINATION_APPEND; + public static final String CHILDREN_COMBINATION_APPEND = XmlService.CHILDREN_COMBINATION_APPEND; /** * This default mode for combining children DOMs during merge means that where element names match, the process will * try to merge the element data, rather than putting the dominant and recessive elements (which share the same * element name) as siblings in the resulting DOM. */ - public static final String DEFAULT_CHILDREN_COMBINATION_MODE = XmlNode.DEFAULT_CHILDREN_COMBINATION_MODE; + public static final String DEFAULT_CHILDREN_COMBINATION_MODE = XmlService.DEFAULT_CHILDREN_COMBINATION_MODE; - public static final String SELF_COMBINATION_MODE_ATTRIBUTE = XmlNode.SELF_COMBINATION_MODE_ATTRIBUTE; + public static final String SELF_COMBINATION_MODE_ATTRIBUTE = XmlService.SELF_COMBINATION_MODE_ATTRIBUTE; - public static final String SELF_COMBINATION_OVERRIDE = XmlNode.SELF_COMBINATION_OVERRIDE; + public static final String SELF_COMBINATION_OVERRIDE = XmlService.SELF_COMBINATION_OVERRIDE; - public static final String SELF_COMBINATION_MERGE = XmlNode.SELF_COMBINATION_MERGE; + public static final String SELF_COMBINATION_MERGE = XmlService.SELF_COMBINATION_MERGE; - public static final String SELF_COMBINATION_REMOVE = XmlNode.SELF_COMBINATION_REMOVE; + public static final String SELF_COMBINATION_REMOVE = XmlService.SELF_COMBINATION_REMOVE; /** * This default mode for combining a DOM node during merge means that where element names match, the process will @@ -60,11 +61,11 @@ public class Xpp3Dom implements Serializable { * dominant one. This means that wherever the dominant element doesn't provide the value or a particular attribute, * that value or attribute will be set from the recessive DOM node. */ - public static final String DEFAULT_SELF_COMBINATION_MODE = XmlNode.DEFAULT_SELF_COMBINATION_MODE; + public static final String DEFAULT_SELF_COMBINATION_MODE = XmlService.DEFAULT_SELF_COMBINATION_MODE; - public static final String ID_COMBINATION_MODE_ATTRIBUTE = XmlNode.ID_COMBINATION_MODE_ATTRIBUTE; + public static final String ID_COMBINATION_MODE_ATTRIBUTE = XmlService.ID_COMBINATION_MODE_ATTRIBUTE; - public static final String KEYS_COMBINATION_MODE_ATTRIBUTE = XmlNode.KEYS_COMBINATION_MODE_ATTRIBUTE; + public static final String KEYS_COMBINATION_MODE_ATTRIBUTE = XmlService.KEYS_COMBINATION_MODE_ATTRIBUTE; private ChildrenTracking childrenTracking; private XmlNode dom; @@ -122,7 +123,7 @@ public XmlNode getDom() { // ---------------------------------------------------------------------- public String getName() { - return dom.getName(); + return dom.name(); } // ---------------------------------------------------------------------- @@ -130,11 +131,11 @@ public String getName() { // ---------------------------------------------------------------------- public String getValue() { - return dom.getValue(); + return dom.value(); } public void setValue(String value) { - update(new XmlNodeImpl(dom.getName(), value, dom.getAttributes(), dom.getChildren(), dom.getInputLocation())); + update(new XmlNodeImpl(dom.name(), value, dom.attributes(), dom.children(), dom.inputLocation())); } // ---------------------------------------------------------------------- @@ -142,11 +143,11 @@ public void setValue(String value) { // ---------------------------------------------------------------------- public String[] getAttributeNames() { - return dom.getAttributes().keySet().toArray(EMPTY_STRING_ARRAY); + return dom.attributes().keySet().toArray(EMPTY_STRING_ARRAY); } public String getAttribute(String name) { - return dom.getAttribute(name); + return dom.attribute(name); } /** @@ -157,11 +158,10 @@ public String getAttribute(String name) { */ public boolean removeAttribute(String name) { if (name != null && !name.isEmpty()) { - Map attrs = new HashMap<>(dom.getAttributes()); + Map attrs = new HashMap<>(dom.attributes()); boolean ret = attrs.remove(name) != null; if (ret) { - update(new XmlNodeImpl( - dom.getName(), dom.getValue(), attrs, dom.getChildren(), dom.getInputLocation())); + update(new XmlNodeImpl(dom.name(), dom.value(), attrs, dom.children(), dom.inputLocation())); } return ret; } @@ -181,9 +181,9 @@ public void setAttribute(String name, String value) { if (null == name) { throw new NullPointerException("Attribute name can not be null"); } - Map attrs = new HashMap<>(dom.getAttributes()); + Map attrs = new HashMap<>(dom.attributes()); attrs.put(name, value); - update(new XmlNodeImpl(dom.getName(), dom.getValue(), attrs, dom.getChildren(), dom.getInputLocation())); + update(new XmlNodeImpl(dom.name(), dom.value(), attrs, dom.children(), dom.inputLocation())); } // ---------------------------------------------------------------------- @@ -191,46 +191,46 @@ public void setAttribute(String name, String value) { // ---------------------------------------------------------------------- public Xpp3Dom getChild(int i) { - return new Xpp3Dom(dom.getChildren().get(i), this); + return new Xpp3Dom(dom.children().get(i), this); } public Xpp3Dom getChild(String name) { - XmlNode child = dom.getChild(name); + XmlNode child = dom.child(name); return child != null ? new Xpp3Dom(child, this) : null; } public void addChild(Xpp3Dom xpp3Dom) { - List children = new ArrayList<>(dom.getChildren()); + List children = new ArrayList<>(dom.children()); children.add(xpp3Dom.dom); xpp3Dom.childrenTracking = this::replace; - update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation())); + update(new XmlNodeImpl(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); } public Xpp3Dom[] getChildren() { - return dom.getChildren().stream().map(d -> new Xpp3Dom(d, this)).toArray(Xpp3Dom[]::new); + return dom.children().stream().map(d -> new Xpp3Dom(d, this)).toArray(Xpp3Dom[]::new); } public Xpp3Dom[] getChildren(String name) { - return dom.getChildren().stream() - .filter(c -> c.getName().equals(name)) + return dom.children().stream() + .filter(c -> c.name().equals(name)) .map(d -> new Xpp3Dom(d, this)) .toArray(Xpp3Dom[]::new); } public int getChildCount() { - return dom.getChildren().size(); + return dom.children().size(); } public void removeChild(int i) { - List children = new ArrayList<>(dom.getChildren()); + List children = new ArrayList<>(dom.children()); children.remove(i); - update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation())); + update(new XmlNodeImpl(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); } public void removeChild(Xpp3Dom child) { - List children = new ArrayList<>(dom.getChildren()); + List children = new ArrayList<>(dom.children()); children.remove(child.dom); - update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation())); + update(new XmlNodeImpl(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); } // ---------------------------------------------------------------------- @@ -252,7 +252,7 @@ public void setParent(Xpp3Dom parent) {} * @return input location */ public Object getInputLocation() { - return dom.getInputLocation(); + return dom.inputLocation(); } /** @@ -260,7 +260,7 @@ public Object getInputLocation() { * @param inputLocation input location to set */ public void setInputLocation(Object inputLocation) { - update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), dom.getChildren(), inputLocation)); + update(new XmlNodeImpl(dom.name(), dom.value(), dom.attributes(), dom.children(), inputLocation)); } // ---------------------------------------------------------------------- @@ -407,9 +407,9 @@ private void update(XmlNode dom) { } private boolean replace(Object prevChild, Object newChild) { - List children = new ArrayList<>(dom.getChildren()); + List children = new ArrayList<>(dom.children()); children.replaceAll(d -> d == prevChild ? (XmlNode) newChild : d); - update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation())); + update(new XmlNodeImpl(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); return true; } From 288920306fcaa2b25e8400cb24d0bc47ed825c33 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 26 Apr 2026 13:16:42 +0200 Subject: [PATCH 2/4] Remove XmlNodeImpl usage, use XmlNode.newInstance() and builder Replace all instances of deprecated XmlNodeImpl constructors with XmlNode.newInstance() static factory methods or XmlNode.newBuilder() pattern. - Use XmlNode.newBuilder() for simple name-only constructors - Use XmlNode.newInstance() for full parameter constructors - Remove XmlNodeImpl import Tests: All 217 tests pass Warnings remaining: XmlNode.merge() and XmlNodeBuilder deprecations --- .../org/codehaus/plexus/util/xml/Xpp3Dom.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java index ed9ee339..5ecd5a0d 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java @@ -25,7 +25,6 @@ import org.apache.maven.api.xml.XmlNode; import org.apache.maven.api.xml.XmlService; -import org.apache.maven.internal.xml.XmlNodeImpl; import org.codehaus.plexus.util.xml.pull.XmlSerializer; /** @@ -71,7 +70,7 @@ public class Xpp3Dom implements Serializable { private XmlNode dom; public Xpp3Dom(String name) { - this.dom = new XmlNodeImpl(name); + this.dom = XmlNode.newBuilder().name(name).build(); } /** @@ -80,7 +79,7 @@ public Xpp3Dom(String name) { * @param name The name of the Dom. */ public Xpp3Dom(String name, Object inputLocation) { - this.dom = new XmlNodeImpl(name, null, null, null, inputLocation); + this.dom = XmlNode.newBuilder().name(name).inputLocation(inputLocation).build(); } /** @@ -97,7 +96,8 @@ public Xpp3Dom(Xpp3Dom src) { * @param name The name of the Dom. */ public Xpp3Dom(Xpp3Dom src, String name) { - this.dom = new XmlNodeImpl(src.dom, name); + this.dom = XmlNode.newInstance( + name, src.dom.value(), src.dom.attributes(), src.dom.children(), src.dom.inputLocation()); } public Xpp3Dom(XmlNode dom) { @@ -135,7 +135,7 @@ public String getValue() { } public void setValue(String value) { - update(new XmlNodeImpl(dom.name(), value, dom.attributes(), dom.children(), dom.inputLocation())); + update(XmlNode.newInstance(dom.name(), value, dom.attributes(), dom.children(), dom.inputLocation())); } // ---------------------------------------------------------------------- @@ -161,7 +161,7 @@ public boolean removeAttribute(String name) { Map attrs = new HashMap<>(dom.attributes()); boolean ret = attrs.remove(name) != null; if (ret) { - update(new XmlNodeImpl(dom.name(), dom.value(), attrs, dom.children(), dom.inputLocation())); + update(XmlNode.newInstance(dom.name(), dom.value(), attrs, dom.children(), dom.inputLocation())); } return ret; } @@ -183,7 +183,7 @@ public void setAttribute(String name, String value) { } Map attrs = new HashMap<>(dom.attributes()); attrs.put(name, value); - update(new XmlNodeImpl(dom.name(), dom.value(), attrs, dom.children(), dom.inputLocation())); + update(XmlNode.newInstance(dom.name(), dom.value(), attrs, dom.children(), dom.inputLocation())); } // ---------------------------------------------------------------------- @@ -203,7 +203,7 @@ public void addChild(Xpp3Dom xpp3Dom) { List children = new ArrayList<>(dom.children()); children.add(xpp3Dom.dom); xpp3Dom.childrenTracking = this::replace; - update(new XmlNodeImpl(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); + update(XmlNode.newInstance(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); } public Xpp3Dom[] getChildren() { @@ -224,13 +224,13 @@ public int getChildCount() { public void removeChild(int i) { List children = new ArrayList<>(dom.children()); children.remove(i); - update(new XmlNodeImpl(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); + update(XmlNode.newInstance(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); } public void removeChild(Xpp3Dom child) { List children = new ArrayList<>(dom.children()); children.remove(child.dom); - update(new XmlNodeImpl(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); + update(XmlNode.newInstance(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); } // ---------------------------------------------------------------------- @@ -260,7 +260,7 @@ public Object getInputLocation() { * @param inputLocation input location to set */ public void setInputLocation(Object inputLocation) { - update(new XmlNodeImpl(dom.name(), dom.value(), dom.attributes(), dom.children(), inputLocation)); + update(XmlNode.newInstance(dom.name(), dom.value(), dom.attributes(), dom.children(), inputLocation)); } // ---------------------------------------------------------------------- @@ -409,7 +409,7 @@ private void update(XmlNode dom) { private boolean replace(Object prevChild, Object newChild) { List children = new ArrayList<>(dom.children()); children.replaceAll(d -> d == prevChild ? (XmlNode) newChild : d); - update(new XmlNodeImpl(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); + update(XmlNode.newInstance(dom.name(), dom.value(), dom.attributes(), children, dom.inputLocation())); return true; } From ba36683e9165641a2acb2a17c963bbfa4562daa7 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 26 Apr 2026 13:17:00 +0200 Subject: [PATCH 3/4] Use XmlService.merge() instead of XmlNode.merge() Replace deprecated XmlNode.merge() instance method with XmlService.merge() static method. Also fix test to use XmlNode.newInstance() instead of XmlNodeImpl. Tests: All 217 tests pass Warnings remaining:XmlNodeBuilder in deprecated trim methods --- src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java | 2 +- src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java index 5ecd5a0d..2dcd2f01 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java @@ -319,7 +319,7 @@ private static void mergeIntoXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolea if (recessive == null) { return; } - dominant.dom = dominant.dom.merge(recessive.dom, childMergeOverride); + dominant.dom = XmlService.merge(dominant.dom, recessive.dom, childMergeOverride); } /** diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java index 44999651..ff5abd2b 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java @@ -23,7 +23,6 @@ import java.util.Map; import org.apache.maven.api.xml.XmlNode; -import org.apache.maven.internal.xml.XmlNodeImpl; import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.junit.jupiter.api.Test; @@ -227,7 +226,7 @@ void equalsIsNullSafe() throws Exception { attributes.put(null, "nullKey"); List childList = new ArrayList<>(); childList.add(null); - Xpp3Dom dom2 = new Xpp3Dom(new XmlNodeImpl(dom.getName(), null, attributes, childList, null)); + Xpp3Dom dom2 = new Xpp3Dom(XmlNode.newInstance(dom.getName(), null, attributes, childList, null)); assertNotEquals(dom, dom2); assertNotEquals(dom2, dom); From ff6bd9ba635150c955b7108a7e2dfbf9205b7468 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 26 Apr 2026 13:17:35 +0200 Subject: [PATCH 4/4] Suppress XmlNodeBuilder deprecation warnings Wrap XmlNodeBuilder.build() calls in @SuppressWarnings("deprecation") helper methods. These are only used in deprecated trim methods, so the warnings are appropriate but not actionable. Tests: All 217 tests pass --- .../plexus/util/xml/Xpp3DomBuilder.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java index b75e681f..cdea1722 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java @@ -49,7 +49,7 @@ public static Xpp3Dom build(InputStream is, String encoding) throws XmlPullParse public static Xpp3Dom build(InputStream is, String encoding, boolean trim) throws XmlPullParserException, IOException { try (InputStream closeMe = is) { - return new Xpp3Dom(XmlNodeBuilder.build(is, encoding, trim)); + return buildWithDeprecatedTrim(is, encoding, trim); } } @@ -63,8 +63,7 @@ public static Xpp3Dom build(Reader reader, boolean trim) throws XmlPullParserExc public static Xpp3Dom build(Reader reader, boolean trim, InputLocationBuilder locationBuilder) throws XmlPullParserException, IOException { try (Reader closeMe = reader) { - return new Xpp3Dom(XmlNodeBuilder.build( - reader, trim, locationBuilder != null ? locationBuilder::toInputLocation : null)); + return buildWithDeprecatedTrim(reader, trim, locationBuilder); } } @@ -81,8 +80,7 @@ public static Xpp3Dom build(XmlPullParser parser, boolean trim) throws XmlPullPa */ public static Xpp3Dom build(XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder) throws XmlPullParserException, IOException { - return new Xpp3Dom( - XmlNodeBuilder.build(parser, trim, locationBuilder != null ? locationBuilder::toInputLocation : null)); + return buildWithDeprecatedTrim(parser, trim, locationBuilder); } /** @@ -93,4 +91,25 @@ public static Xpp3Dom build(XmlPullParser parser, boolean trim, InputLocationBui public interface InputLocationBuilder { Object toInputLocation(XmlPullParser parser); } + + @SuppressWarnings("deprecation") + private static Xpp3Dom buildWithDeprecatedTrim(Reader reader, boolean trim, InputLocationBuilder locationBuilder) + throws XmlPullParserException, IOException { + return new Xpp3Dom( + XmlNodeBuilder.build(reader, trim, locationBuilder != null ? locationBuilder::toInputLocation : null)); + } + + @SuppressWarnings("deprecation") + private static Xpp3Dom buildWithDeprecatedTrim( + XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder) + throws XmlPullParserException, IOException { + return new Xpp3Dom( + XmlNodeBuilder.build(parser, trim, locationBuilder != null ? locationBuilder::toInputLocation : null)); + } + + @SuppressWarnings("deprecation") + private static Xpp3Dom buildWithDeprecatedTrim(InputStream is, String encoding, boolean trim) + throws XmlPullParserException, IOException { + return new Xpp3Dom(XmlNodeBuilder.build(is, encoding, trim)); + } }