diff --git a/api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java b/api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java index a78357a09109..04ba26946a50 100644 --- a/api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java +++ b/api/maven-api-xml/src/main/java/org/apache/maven/api/xml/XmlNode.java @@ -109,73 +109,6 @@ public interface XmlNode { @Deprecated(since = "4.0.0", forRemoval = true) String DEFAULT_SELF_COMBINATION_MODE = XmlService.DEFAULT_SELF_COMBINATION_MODE; - /** - * Returns the local name of this XML node. - * - * @return the node name, never {@code null} - */ - @Nonnull - String name(); - - /** - * Returns the namespace URI of this XML node. - * - * @return the namespace URI, never {@code null} (empty string if no namespace) - */ - @Nonnull - String namespaceUri(); - - /** - * Returns the namespace prefix of this XML node. - * - * @return the namespace prefix, never {@code null} (empty string if no prefix) - */ - @Nonnull - String prefix(); - - /** - * Returns the text content of this XML node. - * - * @return the node's text value, or {@code null} if none exists - */ - @Nullable - String value(); - - /** - * Returns an immutable map of all attributes defined on this XML node. - * - * @return map of attribute names to values, never {@code null} - */ - @Nonnull - Map attributes(); - - /** - * Returns the value of a specific attribute. - * - * @param name the name of the attribute to retrieve - * @return the attribute value, or {@code null} if the attribute doesn't exist - * @throws NullPointerException if name is null - */ - @Nullable - String attribute(@Nonnull String name); - - /** - * Returns an immutable list of all child nodes. - * - * @return list of child nodes, never {@code null} - */ - @Nonnull - List children(); - - /** - * Returns the first child node with the specified name. - * - * @param name the name of the child node to find - * @return the first matching child node, or {@code null} if none found - */ - @Nullable - XmlNode child(String name); - /** * Returns the input location information for this node, if available. * This can be useful for error reporting and debugging. @@ -185,60 +118,32 @@ public interface XmlNode { @Nullable Object inputLocation(); - // Deprecated methods that delegate to new ones - @Deprecated(since = "4.0.0", forRemoval = true) @Nonnull - default String getName() { - return name(); - } + String getName(); - @Deprecated(since = "4.0.0", forRemoval = true) @Nonnull - default String getNamespaceUri() { - return namespaceUri(); - } + String getNamespaceUri(); - @Deprecated(since = "4.0.0", forRemoval = true) @Nonnull - default String getPrefix() { - return prefix(); - } + String getPrefix(); - @Deprecated(since = "4.0.0", forRemoval = true) @Nullable - default String getValue() { - return value(); - } + String getValue(); - @Deprecated(since = "4.0.0", forRemoval = true) @Nonnull - default Map getAttributes() { - return attributes(); - } + Map getAttributes(); - @Deprecated(since = "4.0.0", forRemoval = true) @Nullable - default String getAttribute(@Nonnull String name) { - return attribute(name); - } + String getAttribute(@Nonnull String name); - @Deprecated(since = "4.0.0", forRemoval = true) @Nonnull - default List getChildren() { - return children(); - } + List getChildren(); - @Deprecated(since = "4.0.0", forRemoval = true) @Nullable - default XmlNode getChild(String name) { - return child(name); - } + XmlNode getChild(String name); - @Deprecated(since = "4.0.0", forRemoval = true) @Nullable - default Object getInputLocation() { - return inputLocation(); - } + Object getInputLocation(); /** * @deprecated use {@link XmlService#merge(XmlNode, XmlNode, Boolean)} instead @@ -477,17 +382,47 @@ private record Impl( } @Override - public String attribute(@Nonnull String name) { + public String getName() { + return name(); + } + + @Override + public String getNamespaceUri() { + return namespaceUri(); + } + + @Override + public String getPrefix() { + return prefix(); + } + + @Override + public String getValue() { + return value(); + } + + @Override + public Map getAttributes() { + return attributes(); + } + + @Override + public String getAttribute(@Nonnull String name) { return attributes.get(name); } @Override - public XmlNode child(String name) { + public List getChildren() { + return children(); + } + + @Override + public XmlNode getChild(String name) { if (name != null) { ListIterator it = children.listIterator(children.size()); while (it.hasPrevious()) { XmlNode child = it.previous(); - if (name.equals(child.name())) { + if (name.equals(child.getName())) { return child; } } @@ -495,14 +430,19 @@ public XmlNode child(String name) { return null; } + @Override + public Object getInputLocation() { + return inputLocation(); + } + @Override public boolean equals(Object o) { return this == o || o instanceof XmlNode that - && Objects.equals(this.name, that.name()) - && Objects.equals(this.value, that.value()) - && Objects.equals(this.attributes, that.attributes()) - && Objects.equals(this.children, that.children()); + && Objects.equals(this.name, that.getName()) + && Objects.equals(this.value, that.getValue()) + && Objects.equals(this.attributes, that.getAttributes()) + && Objects.equals(this.children, that.getChildren()); } @Override diff --git a/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/DefaultXmlService.java b/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/DefaultXmlService.java index e97a2213805e..f45cd1a18deb 100644 --- a/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/DefaultXmlService.java +++ b/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/DefaultXmlService.java @@ -160,17 +160,17 @@ public void doWrite(XmlNode node, Writer writer) throws IOException { } private void writeNode(XMLStreamWriter xmlWriter, XmlNode node) throws XMLStreamException { - xmlWriter.writeStartElement(node.prefix(), node.name(), node.namespaceUri()); + xmlWriter.writeStartElement(node.getPrefix(), node.getName(), node.getNamespaceUri()); - for (Map.Entry attr : node.attributes().entrySet()) { + for (Map.Entry attr : node.getAttributes().entrySet()) { xmlWriter.writeAttribute(attr.getKey(), attr.getValue()); } - for (XmlNode child : node.children()) { + for (XmlNode child : node.getChildren()) { writeNode(xmlWriter, child); } - String value = node.value(); + String value = node.getValue(); if (value != null) { xmlWriter.writeCharacters(value); } @@ -233,22 +233,22 @@ public XmlNode doMerge(XmlNode dominant, XmlNode recessive, Boolean childMergeOv if (mergeSelf) { - String value = dominant.value(); + String value = dominant.getValue(); Object location = dominant.inputLocation(); - Map attrs = dominant.attributes(); + Map attrs = dominant.getAttributes(); List children = null; - for (Map.Entry attr : recessive.attributes().entrySet()) { + for (Map.Entry attr : recessive.getAttributes().entrySet()) { String key = attr.getKey(); if (isEmpty(attrs.get(key))) { - if (attrs == dominant.attributes()) { + if (attrs == dominant.getAttributes()) { attrs = new HashMap<>(attrs); } attrs.put(key, attr.getValue()); } } - if (!recessive.children().isEmpty()) { + if (!recessive.getChildren().isEmpty()) { boolean mergeChildren = true; if (childMergeOverride != null) { mergeChildren = childMergeOverride; @@ -261,26 +261,26 @@ public XmlNode doMerge(XmlNode dominant, XmlNode recessive, Boolean childMergeOv Map> commonChildren = new HashMap<>(); Set names = - recessive.children().stream().map(XmlNode::name).collect(Collectors.toSet()); + recessive.getChildren().stream().map(XmlNode::getName).collect(Collectors.toSet()); for (String name : names) { - List dominantChildren = dominant.children().stream() - .filter(n -> n.name().equals(name)) + List dominantChildren = dominant.getChildren().stream() + .filter(n -> n.getName().equals(name)) .toList(); if (!dominantChildren.isEmpty()) { commonChildren.put(name, dominantChildren.iterator()); } } - String keysValue = recessive.attribute(KEYS_COMBINATION_MODE_ATTRIBUTE); + String keysValue = recessive.getAttribute(KEYS_COMBINATION_MODE_ATTRIBUTE); int recessiveChildIndex = 0; - for (XmlNode recessiveChild : recessive.children()) { - String idValue = recessiveChild.attribute(ID_COMBINATION_MODE_ATTRIBUTE); + for (XmlNode recessiveChild : recessive.getChildren()) { + String idValue = recessiveChild.getAttribute(ID_COMBINATION_MODE_ATTRIBUTE); XmlNode childDom = null; if (!isEmpty(idValue)) { - for (XmlNode dominantChild : dominant.children()) { - if (idValue.equals(dominantChild.attribute(ID_COMBINATION_MODE_ATTRIBUTE))) { + for (XmlNode dominantChild : dominant.getChildren()) { + if (idValue.equals(dominantChild.getAttribute(ID_COMBINATION_MODE_ATTRIBUTE))) { childDom = dominantChild; // we have a match, so don't append but merge mergeChildren = true; @@ -290,12 +290,12 @@ public XmlNode doMerge(XmlNode dominant, XmlNode recessive, Boolean childMergeOv String[] keys = keysValue.split(","); Map> recessiveKeyValues = Stream.of(keys) .collect(Collectors.toMap( - k -> k, k -> Optional.ofNullable(recessiveChild.attribute(k)))); + k -> k, k -> Optional.ofNullable(recessiveChild.getAttribute(k)))); - for (XmlNode dominantChild : dominant.children()) { + for (XmlNode dominantChild : dominant.getChildren()) { Map> dominantKeyValues = Stream.of(keys) .collect(Collectors.toMap( - k -> k, k -> Optional.ofNullable(dominantChild.attribute(k)))); + k -> k, k -> Optional.ofNullable(dominantChild.getAttribute(k)))); if (recessiveKeyValues.equals(dominantKeyValues)) { childDom = dominantChild; @@ -304,14 +304,14 @@ public XmlNode doMerge(XmlNode dominant, XmlNode recessive, Boolean childMergeOv } } } else { - childDom = dominant.child(recessiveChild.name()); + childDom = dominant.getChild(recessiveChild.getName()); } if (mergeChildren && childDom != null) { - String name = recessiveChild.name(); + String name = recessiveChild.getName(); Iterator it = - commonChildren.computeIfAbsent(name, n1 -> Stream.of(dominant.children().stream() - .filter(n2 -> n2.name().equals(n1)) + commonChildren.computeIfAbsent(name, n1 -> Stream.of(dominant.getChildren().stream() + .filter(n2 -> n2.getName().equals(n1)) .collect(Collectors.toList())) .filter(l -> !l.isEmpty()) .findFirst() @@ -319,7 +319,7 @@ public XmlNode doMerge(XmlNode dominant, XmlNode recessive, Boolean childMergeOv .orElse(null)); if (it == null) { if (children == null) { - children = new ArrayList<>(dominant.children()); + children = new ArrayList<>(dominant.getChildren()); } children.add(recessiveChild); } else if (it.hasNext()) { @@ -328,15 +328,15 @@ public XmlNode doMerge(XmlNode dominant, XmlNode recessive, Boolean childMergeOv String dominantChildCombinationMode = getSelfCombinationMode(dominantChild); if (SELF_COMBINATION_REMOVE.equals(dominantChildCombinationMode)) { if (children == null) { - children = new ArrayList<>(dominant.children()); + children = new ArrayList<>(dominant.getChildren()); } children.remove(dominantChild); } else { - int idx = dominant.children().indexOf(dominantChild); + int idx = dominant.getChildren().indexOf(dominantChild); XmlNode merged = merge(dominantChild, recessiveChild, childMergeOverride); if (merged != dominantChild) { if (children == null) { - children = new ArrayList<>(dominant.children()); + children = new ArrayList<>(dominant.getChildren()); } children.set(idx, merged); } @@ -344,7 +344,7 @@ public XmlNode doMerge(XmlNode dominant, XmlNode recessive, Boolean childMergeOv } } else { if (children == null) { - children = new ArrayList<>(dominant.children()); + children = new ArrayList<>(dominant.getChildren()); } int idx = mergeChildren ? children.size() : recessiveChildIndex; children.add(idx, recessiveChild); @@ -353,19 +353,19 @@ public XmlNode doMerge(XmlNode dominant, XmlNode recessive, Boolean childMergeOv } } - if (value != null || attrs != dominant.attributes() || children != null) { + if (value != null || attrs != dominant.getAttributes() || children != null) { if (children == null) { - children = dominant.children(); + children = dominant.getChildren(); } - if (!Objects.equals(value, dominant.value()) - || !Objects.equals(attrs, dominant.attributes()) - || !Objects.equals(children, dominant.children()) + if (!Objects.equals(value, dominant.getValue()) + || !Objects.equals(attrs, dominant.getAttributes()) + || !Objects.equals(children, dominant.getChildren()) || !Objects.equals(location, dominant.inputLocation())) { return XmlNode.newBuilder() - .prefix(dominant.prefix()) - .namespaceUri(dominant.namespaceUri()) - .name(dominant.name()) - .value(value != null ? value : dominant.value()) + .prefix(dominant.getPrefix()) + .namespaceUri(dominant.getNamespaceUri()) + .name(dominant.getName()) + .value(value != null ? value : dominant.getValue()) .attributes(attrs) .children(children) .inputLocation(location) @@ -383,7 +383,7 @@ private static boolean isEmpty(String str) { } private static String getSelfCombinationMode(XmlNode node) { - String value = node.attribute(SELF_COMBINATION_MODE_ATTRIBUTE); + String value = node.getAttribute(SELF_COMBINATION_MODE_ATTRIBUTE); return !isEmpty(value) ? value : DEFAULT_SELF_COMBINATION_MODE; } @@ -395,7 +395,7 @@ private static String getChildCombinationMode(Map attributes) { @Nullable private static XmlNode findNodeById(@Nonnull List nodes, @Nonnull String id) { return nodes.stream() - .filter(n -> id.equals(n.attribute(ID_COMBINATION_MODE_ATTRIBUTE))) + .filter(n -> id.equals(n.getAttribute(ID_COMBINATION_MODE_ATTRIBUTE))) .findFirst() .orElse(null); } @@ -411,8 +411,8 @@ private static XmlNode findNodeByKeys( private static boolean matchesKeys(@Nonnull XmlNode node1, @Nonnull XmlNode node2, @Nonnull String[] keys) { for (String key : keys) { - String value1 = node1.attribute(key); - String value2 = node2.attribute(key); + String value1 = node1.getAttribute(key); + String value2 = node2.getAttribute(key); if (!Objects.equals(value1, value2)) { return false; } diff --git a/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java b/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java index c57eb6e9374a..8a80eb43ccb5 100644 --- a/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java +++ b/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java @@ -110,36 +110,16 @@ public String getPrefix() { @Override @Nonnull - public String prefix() { - return getPrefix(); - } - - @Override - @Nonnull - @Deprecated(since = "4.0.0", forRemoval = true) public String getNamespaceUri() { return namespaceUri; } @Override @Nonnull - public String namespaceUri() { - return getNamespaceUri(); - } - - @Override - @Nonnull - @Deprecated(since = "4.0.0", forRemoval = true) public String getName() { return name; } - @Override - @Nonnull - public String name() { - return getName(); - } - // ---------------------------------------------------------------------- // Value handling // ---------------------------------------------------------------------- @@ -150,11 +130,6 @@ public String getValue() { return value; } - @Override - public String value() { - return getValue(); - } - // ---------------------------------------------------------------------- // Attribute handling // ---------------------------------------------------------------------- @@ -166,23 +141,12 @@ public Map getAttributes() { return attributes; } - @Override - @Nonnull - public Map attributes() { - return getAttributes(); - } - @Override @Deprecated(since = "4.0.0", forRemoval = true) public String getAttribute(@Nonnull String name) { return attributes.get(name); } - @Override - public String attribute(@Nonnull String name) { - return getAttribute(name); - } - // ---------------------------------------------------------------------- // Child handling // ---------------------------------------------------------------------- @@ -202,25 +166,12 @@ public XmlNode getChild(String name) { return null; } - @Override - public XmlNode child(String name) { - return getChild(name); - } - @Override @Nonnull - @Deprecated(since = "4.0.0", forRemoval = true) public List getChildren() { return children; } - @Override - @Nonnull - public List children() { - return getChildren(); - } - - @Deprecated(since = "4.0.0", forRemoval = true) public int getChildCount() { return children.size(); } @@ -233,7 +184,6 @@ public int getChildCount() { * @since 3.2.0 * @return input location */ - @Deprecated(since = "4.0.0", forRemoval = true) @Override public Object getInputLocation() { return location; @@ -278,10 +228,10 @@ public static XmlNode merge(XmlNode dominant, XmlNode recessive) { public boolean equals(Object o) { return this == o || o instanceof XmlNode that - && Objects.equals(this.name, that.name()) - && Objects.equals(this.value, that.value()) - && Objects.equals(this.attributes, that.attributes()) - && Objects.equals(this.children, that.children()); + && Objects.equals(this.name, that.getName()) + && Objects.equals(this.value, that.getValue()) + && Objects.equals(this.attributes, that.getAttributes()) + && Objects.equals(this.children, that.getChildren()); } @Override diff --git a/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeWriter.java b/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeWriter.java index c8cd05a730d9..00880c536b4f 100644 --- a/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeWriter.java +++ b/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlNodeWriter.java @@ -45,14 +45,14 @@ public static void write(Writer writer, XmlNode node) throws XMLStreamException @Deprecated public static void write(XMLStreamWriter xmlWriter, XmlNode node) throws XMLStreamException { // Keep the old direct implementation for backward compatibility - xmlWriter.writeStartElement(node.prefix(), node.name(), node.namespaceUri()); - for (Map.Entry attr : node.attributes().entrySet()) { + xmlWriter.writeStartElement(node.getPrefix(), node.getName(), node.getNamespaceUri()); + for (Map.Entry attr : node.getAttributes().entrySet()) { xmlWriter.writeAttribute(attr.getKey(), attr.getValue()); } - for (XmlNode child : node.children()) { + for (XmlNode child : node.getChildren()) { write(xmlWriter, child); } - String value = node.value(); + String value = node.getValue(); if (value != null) { xmlWriter.writeCharacters(value); } diff --git a/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlPlexusConfiguration.java b/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlPlexusConfiguration.java index afe4026347db..d146da2cbbfa 100644 --- a/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlPlexusConfiguration.java +++ b/impl/maven-xml/src/main/java/org/apache/maven/internal/xml/XmlPlexusConfiguration.java @@ -76,40 +76,40 @@ private XmlNode convertToXmlNode(PlexusConfiguration config) { @Override public String getName() { - return xmlNode.name(); + return xmlNode.getName(); } public synchronized void setName(String name) { this.xmlNode = XmlNode.newBuilder() .name(name) - .value(xmlNode.value()) - .attributes(xmlNode.attributes()) - .children(xmlNode.children()) - .namespaceUri(xmlNode.namespaceUri()) - .prefix(xmlNode.prefix()) + .value(xmlNode.getValue()) + .attributes(xmlNode.getAttributes()) + .children(xmlNode.getChildren()) + .namespaceUri(xmlNode.getNamespaceUri()) + .prefix(xmlNode.getPrefix()) .inputLocation(xmlNode.inputLocation()) .build(); clearCache(); } public String getValue() { - return xmlNode.value(); + return xmlNode.getValue(); } public String getValue(String defaultValue) { - String value = xmlNode.value(); + String value = xmlNode.getValue(); return value != null ? value : defaultValue; } public synchronized void setValue(String value) { this.xmlNode = XmlNode.newBuilder() - .name(xmlNode.name()) + .name(xmlNode.getName()) .value(value) - .attributes(xmlNode.attributes()) - .children(xmlNode.children()) - .namespaceUri(xmlNode.namespaceUri()) - .prefix(xmlNode.prefix()) - .inputLocation(xmlNode.inputLocation()) + .attributes(xmlNode.getAttributes()) + .children(xmlNode.getChildren()) + .namespaceUri(xmlNode.getNamespaceUri()) + .prefix(xmlNode.getPrefix()) + .inputLocation(xmlNode.getInputLocation()) .build(); clearCache(); } @@ -120,39 +120,39 @@ public PlexusConfiguration setValueAndGetSelf(String value) { } public synchronized void setAttribute(String name, String value) { - Map newAttributes = new HashMap<>(xmlNode.attributes()); + Map newAttributes = new HashMap<>(xmlNode.getAttributes()); if (value == null) { newAttributes.remove(name); } else { newAttributes.put(name, value); } this.xmlNode = XmlNode.newBuilder() - .name(xmlNode.name()) - .value(xmlNode.value()) + .name(xmlNode.getName()) + .value(xmlNode.getValue()) .attributes(newAttributes) - .children(xmlNode.children()) - .namespaceUri(xmlNode.namespaceUri()) - .prefix(xmlNode.prefix()) + .children(xmlNode.getChildren()) + .namespaceUri(xmlNode.getNamespaceUri()) + .prefix(xmlNode.getPrefix()) .inputLocation(xmlNode.inputLocation()) .build(); clearCache(); } public String[] getAttributeNames() { - return xmlNode.attributes().keySet().toArray(new String[0]); + return xmlNode.getAttributes().keySet().toArray(new String[0]); } public String getAttribute(String paramName) { - return xmlNode.attribute(paramName); + return xmlNode.getAttribute(paramName); } public String getAttribute(String name, String defaultValue) { - String value = xmlNode.attribute(name); + String value = xmlNode.getAttribute(name); return value != null ? value : defaultValue; } public PlexusConfiguration getChild(String child) { - XmlNode childNode = xmlNode.child(child); + XmlNode childNode = xmlNode.getChild(child); if (childNode != null) { return new XmlPlexusConfiguration(childNode); } else { @@ -163,7 +163,7 @@ public PlexusConfiguration getChild(String child) { } public PlexusConfiguration getChild(int i) { - List children = xmlNode.children(); + List children = xmlNode.getChildren(); if (i >= 0 && i < children.size()) { return new XmlPlexusConfiguration(children.get(i)); } @@ -171,21 +171,21 @@ public PlexusConfiguration getChild(int i) { } public synchronized PlexusConfiguration getChild(String child, boolean createChild) { - XmlNode childNode = xmlNode.child(child); + XmlNode childNode = xmlNode.getChild(child); if (childNode == null) { if (createChild) { // Create a new child node XmlNode newChild = XmlNode.newInstance(child); - List newChildren = new ArrayList<>(xmlNode.children()); + List newChildren = new ArrayList<>(xmlNode.getChildren()); newChildren.add(newChild); this.xmlNode = XmlNode.newBuilder() - .name(xmlNode.name()) - .value(xmlNode.value()) - .attributes(xmlNode.attributes()) + .name(xmlNode.getName()) + .value(xmlNode.getValue()) + .attributes(xmlNode.getAttributes()) .children(newChildren) - .namespaceUri(xmlNode.namespaceUri()) - .prefix(xmlNode.prefix()) + .namespaceUri(xmlNode.getNamespaceUri()) + .prefix(xmlNode.getPrefix()) .inputLocation(xmlNode.inputLocation()) .build(); clearCache(); @@ -200,7 +200,7 @@ public synchronized PlexusConfiguration getChild(String child, boolean createChi public synchronized PlexusConfiguration[] getChildren() { if (childrenCache == null) { - List children = xmlNode.children(); + List children = xmlNode.getChildren(); childrenCache = new PlexusConfiguration[children.size()]; for (int i = 0; i < children.size(); i++) { childrenCache[i] = new XmlPlexusConfiguration(children.get(i)); @@ -211,8 +211,8 @@ public synchronized PlexusConfiguration[] getChildren() { public PlexusConfiguration[] getChildren(String name) { List result = new ArrayList<>(); - for (XmlNode child : xmlNode.children()) { - if (name.equals(child.name())) { + for (XmlNode child : xmlNode.getChildren()) { + if (name.equals(child.getName())) { result.add(new XmlPlexusConfiguration(child)); } } @@ -222,16 +222,16 @@ public PlexusConfiguration[] getChildren(String name) { public synchronized void addChild(PlexusConfiguration configuration) { // Convert PlexusConfiguration to XmlNode XmlNode newChild = convertToXmlNode(configuration); - List newChildren = new ArrayList<>(xmlNode.children()); + List newChildren = new ArrayList<>(xmlNode.getChildren()); newChildren.add(newChild); this.xmlNode = XmlNode.newBuilder() - .name(xmlNode.name()) - .value(xmlNode.value()) - .attributes(xmlNode.attributes()) + .name(xmlNode.getName()) + .value(xmlNode.getValue()) + .attributes(xmlNode.getAttributes()) .children(newChildren) - .namespaceUri(xmlNode.namespaceUri()) - .prefix(xmlNode.prefix()) + .namespaceUri(xmlNode.getNamespaceUri()) + .prefix(xmlNode.getPrefix()) .inputLocation(xmlNode.inputLocation()) .build(); clearCache(); @@ -239,16 +239,16 @@ public synchronized void addChild(PlexusConfiguration configuration) { public synchronized PlexusConfiguration addChild(String name) { XmlNode newChild = XmlNode.newInstance(name); - List newChildren = new ArrayList<>(xmlNode.children()); + List newChildren = new ArrayList<>(xmlNode.getChildren()); newChildren.add(newChild); this.xmlNode = XmlNode.newBuilder() - .name(xmlNode.name()) - .value(xmlNode.value()) - .attributes(xmlNode.attributes()) + .name(xmlNode.getName()) + .value(xmlNode.getValue()) + .attributes(xmlNode.getAttributes()) .children(newChildren) - .namespaceUri(xmlNode.namespaceUri()) - .prefix(xmlNode.prefix()) + .namespaceUri(xmlNode.getNamespaceUri()) + .prefix(xmlNode.getPrefix()) .inputLocation(xmlNode.inputLocation()) .build(); clearCache(); @@ -258,16 +258,16 @@ public synchronized PlexusConfiguration addChild(String name) { public synchronized PlexusConfiguration addChild(String name, String value) { XmlNode newChild = XmlNode.newInstance(name, value); - List newChildren = new ArrayList<>(xmlNode.children()); + List newChildren = new ArrayList<>(xmlNode.getChildren()); newChildren.add(newChild); this.xmlNode = XmlNode.newBuilder() - .name(xmlNode.name()) - .value(xmlNode.value()) - .attributes(xmlNode.attributes()) + .name(xmlNode.getName()) + .value(xmlNode.getValue()) + .attributes(xmlNode.getAttributes()) .children(newChildren) - .namespaceUri(xmlNode.namespaceUri()) - .prefix(xmlNode.prefix()) + .namespaceUri(xmlNode.getNamespaceUri()) + .prefix(xmlNode.getPrefix()) .inputLocation(xmlNode.inputLocation()) .build(); clearCache(); @@ -276,7 +276,7 @@ public synchronized PlexusConfiguration addChild(String name, String value) { } public int getChildCount() { - return xmlNode.children().size(); + return xmlNode.getChildren().size(); } public String toString() { diff --git a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java index 7dfd0f9de803..766914c0b19f 100644 --- a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java +++ b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeBuilderTest.java @@ -52,8 +52,8 @@ void testWithNamespace() throws Exception { StringReader r = new StringReader(doc); XMLStreamReader xsr = XMLInputFactory.newFactory().createXMLStreamReader(r); XmlNode node = XmlService.read(xsr); - assertEquals("doc", node.name()); - assertEquals(1, node.attributes().size()); - assertEquals("foo:bar", node.attribute("xmlns")); + assertEquals("doc", node.getName()); + assertEquals(1, node.getAttributes().size()); + assertEquals("foo:bar", node.getAttribute("xmlns")); } } diff --git a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java index e9805171948d..9577a48c3ab5 100644 --- a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java +++ b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java @@ -60,7 +60,7 @@ void testCombineChildrenAppend() throws Exception { + " org.apache.maven.plugins\n" + " maven-surefire-plugin\n" + " \n" - + " \n" + + " \n" + " \n" + " prop2\n" + " value2\n" @@ -124,7 +124,7 @@ void testCombineChildrenAppend() throws Exception { + " org.apache.maven.plugins\n" + " maven-surefire-plugin\n" + " \n" - + " \n" + + " \n" + " \n" + " prop1\n" + " value1\n" @@ -155,7 +155,7 @@ void testCombineChildrenAppend() throws Exception { void testAppend() throws Exception { String lhs = """ - + -Xmaxerrs 100 -Xmaxwarns @@ -164,7 +164,7 @@ void testAppend() throws Exception { """; String result = """ - + -Xmaxerrs 100 -Xmaxwarns @@ -208,28 +208,28 @@ void testCombineId() throws Exception { assertEquals(3, getChildren(mergeResult, "property").size()); XmlNode p0 = getNthChild(mergeResult, "property", 0); - assertEquals("LHS-ONLY", p0.child("name").value()); - assertEquals("left", p0.child("name").inputLocation()); - assertEquals("LHS", p0.child("value").value()); - assertEquals("left", p0.child("value").inputLocation()); + assertEquals("LHS-ONLY", p0.getChild("name").getValue()); + assertEquals("left", p0.getChild("name").inputLocation()); + assertEquals("LHS", p0.getChild("value").getValue()); + assertEquals("left", p0.getChild("value").inputLocation()); XmlNode p1 = getNthChild(mergeResult, "property", 1); assertEquals( "TOOVERWRITE", - getNthChild(mergeResult, "property", 1).child("name").value()); - assertEquals("left", p1.child("name").inputLocation()); + getNthChild(mergeResult, "property", 1).getChild("name").getValue()); + assertEquals("left", p1.getChild("name").inputLocation()); assertEquals( - "LHS", getNthChild(mergeResult, "property", 1).child("value").value()); - assertEquals("left", p1.child("value").inputLocation()); + "LHS", getNthChild(mergeResult, "property", 1).getChild("value").getValue()); + assertEquals("left", p1.getChild("value").inputLocation()); XmlNode p2 = getNthChild(mergeResult, "property", 2); assertEquals( "RHS-ONLY", - getNthChild(mergeResult, "property", 2).child("name").value()); - assertEquals("right", p2.child("name").inputLocation()); + getNthChild(mergeResult, "property", 2).getChild("name").getValue()); + assertEquals("right", p2.getChild("name").inputLocation()); assertEquals( - "RHS", getNthChild(mergeResult, "property", 2).child("value").value()); - assertEquals("right", p2.child("value").inputLocation()); + "RHS", getNthChild(mergeResult, "property", 2).getChild("value").getValue()); + assertEquals("right", p2.getChild("value").inputLocation()); } /** @@ -254,28 +254,28 @@ void testCombineKeys() throws Exception { assertEquals(3, getChildren(mergeResult, "property").size()); XmlNode p0 = getNthChild(mergeResult, "property", 0); - assertEquals("LHS-ONLY", p0.child("name").value()); - assertEquals("left", p0.child("name").inputLocation()); - assertEquals("LHS", p0.child("value").value()); - assertEquals("left", p0.child("value").inputLocation()); + assertEquals("LHS-ONLY", p0.getChild("name").getValue()); + assertEquals("left", p0.getChild("name").inputLocation()); + assertEquals("LHS", p0.getChild("value").getValue()); + assertEquals("left", p0.getChild("value").inputLocation()); XmlNode p1 = getNthChild(mergeResult, "property", 1); assertEquals( "TOOVERWRITE", - getNthChild(mergeResult, "property", 1).child("name").value()); - assertEquals("left", p1.child("name").inputLocation()); + getNthChild(mergeResult, "property", 1).getChild("name").getValue()); + assertEquals("left", p1.getChild("name").inputLocation()); assertEquals( - "LHS", getNthChild(mergeResult, "property", 1).child("value").value()); - assertEquals("left", p1.child("value").inputLocation()); + "LHS", getNthChild(mergeResult, "property", 1).getChild("value").getValue()); + assertEquals("left", p1.getChild("value").inputLocation()); XmlNode p2 = getNthChild(mergeResult, "property", 2); assertEquals( "RHS-ONLY", - getNthChild(mergeResult, "property", 2).child("name").value()); - assertEquals("right", p2.child("name").inputLocation()); + getNthChild(mergeResult, "property", 2).getChild("name").getValue()); + assertEquals("right", p2.getChild("name").inputLocation()); assertEquals( - "RHS", getNthChild(mergeResult, "property", 2).child("value").value()); - assertEquals("right", p2.child("value").inputLocation()); + "RHS", getNthChild(mergeResult, "property", 2).getChild("value").getValue()); + assertEquals("right", p2.getChild("value").inputLocation()); } @Test @@ -288,7 +288,7 @@ void testPreserveDominantBlankValue() throws XMLStreamException, IOException { XmlNode rightDom = XmlService.read(new StringReader(rhs), new FixedInputLocationBuilder("right")); XmlNode mergeResult = XmlService.merge(leftDom, rightDom, true); - assertEquals(" ", mergeResult.value()); + assertEquals(" ", mergeResult.getValue()); } @Test @@ -301,7 +301,7 @@ void testPreserveDominantEmptyNode() throws XMLStreamException, IOException { XmlNode rightDom = XmlService.read(new StringReader(rhs), new FixedInputLocationBuilder("right")); XmlNode mergeResult = XmlService.merge(leftDom, rightDom, true); - assertEquals("", mergeResult.value()); + assertEquals("", mergeResult.getValue()); } @Test @@ -314,7 +314,7 @@ void testPreserveDominantEmptyNode2() throws XMLStreamException, IOException { XmlNode rightDom = XmlService.read(new StringReader(rhs), new FixedInputLocationBuilder("right")); XmlNode mergeResult = XmlService.merge(leftDom, rightDom, true); - assertNull(mergeResult.value()); + assertNull(mergeResult.getValue()); } /** @@ -323,7 +323,7 @@ void testPreserveDominantEmptyNode2() throws XMLStreamException, IOException { @Test void testShouldPerformAppendAtFirstSubElementLevel() throws XMLStreamException { String lhs = """ - + t1s1Value t1s2Value @@ -339,10 +339,10 @@ void testShouldPerformAppendAtFirstSubElementLevel() throws XMLStreamException { XmlNode result = XmlService.merge(leftDom, rightDom); assertEquals(4, getChildren(result, "topsub1").size()); - assertEquals("t2s1Value", getChildren(result, "topsub1").get(0).value()); - assertEquals("t2s2Value", getChildren(result, "topsub1").get(1).value()); - assertEquals("t1s1Value", getChildren(result, "topsub1").get(2).value()); - assertEquals("t1s2Value", getChildren(result, "topsub1").get(3).value()); + assertEquals("t2s1Value", getChildren(result, "topsub1").get(0).getValue()); + assertEquals("t2s2Value", getChildren(result, "topsub1").get(1).getValue()); + assertEquals("t1s1Value", getChildren(result, "topsub1").get(2).getValue()); + assertEquals("t1s2Value", getChildren(result, "topsub1").get(3).getValue()); assertEquals("left", result.inputLocation()); assertEquals("right", getChildren(result, "topsub1").get(0).inputLocation()); @@ -499,7 +499,7 @@ void testEqualsWithDifferentStructures() throws XMLStreamException, IOException attributes.put("differentAttribute", "differentValue"); List childList = new ArrayList<>(); childList.add(XmlNode.newInstance("differentChild", "differentValue", null, null, null)); - Xpp3Dom dom2 = new Xpp3Dom(XmlNode.newInstance(dom.name(), "differentValue", attributes, childList, null)); + Xpp3Dom dom2 = new Xpp3Dom(XmlNode.newInstance(dom.getName(), "differentValue", attributes, childList, null)); assertNotEquals(dom, dom2); assertNotEquals(dom2, dom); @@ -517,12 +517,12 @@ void testShouldOverwritePluginConfigurationSubItemsByDefault() throws XMLStreamE XmlNode childConfig = toXmlNode(childConfigStr, new FixedInputLocationBuilder("child")); XmlNode result = XmlService.merge(childConfig, parentConfig); - XmlNode items = result.child("items"); + XmlNode items = result.getChild("items"); - assertEquals(1, items.children().size()); + assertEquals(1, items.getChildren().size()); - XmlNode item = items.children().get(0); - assertEquals("three", item.value()); + XmlNode item = items.getChildren().get(0); + assertEquals("three", item.getValue()); assertEquals("child", item.inputLocation()); } @@ -535,21 +535,21 @@ void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() throws XM XmlNode parentConfig = toXmlNode(parentConfigStr, new FixedInputLocationBuilder("parent")); String childConfigStr = - "three"; + "three"; XmlNode childConfig = toXmlNode(childConfigStr, new FixedInputLocationBuilder("child")); XmlNode result = XmlService.merge(childConfig, parentConfig); assertNotNull(result); - XmlNode items = result.child("items"); + XmlNode items = result.getChild("items"); assertNotNull(result); - XmlNode[] item = items.children().toArray(new XmlNode[0]); + XmlNode[] item = items.getChildren().toArray(new XmlNode[0]); assertEquals(3, item.length); - assertEquals("one", item[0].value()); + assertEquals("one", item[0].getValue()); assertEquals("parent", item[0].inputLocation()); - assertEquals("two", item[1].value()); + assertEquals("two", item[1].getValue()); assertEquals("parent", item[1].inputLocation()); - assertEquals("three", item[2].value()); + assertEquals("three", item[2].getValue()); assertEquals("child", item[2].inputLocation()); } @@ -565,13 +565,13 @@ void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty() throw XmlNode recessiveConfig = toXmlNode(configStr); XmlNode result = XmlService.merge(dominantConfig, recessiveConfig); - XmlNode items = result.child("items"); + XmlNode items = result.getChild("items"); - assertEquals(3, items.children().size()); + assertEquals(3, items.getChildren().size()); - assertNull(items.children().get(0).value()); - assertEquals("test", items.children().get(1).value()); - assertNull(items.children().get(2).value()); + assertNull(items.getChildren().get(0).getValue()); + assertEquals("test", items.getChildren().get(1).getValue()); + assertNull(items.getChildren().get(2).getValue()); } /** @@ -603,7 +603,7 @@ void testDupeChildren() throws IOException, XMLStreamException { String dupes = "xy"; XmlNode dom = toXmlNode(new StringReader(dupes)); assertNotNull(dom); - assertEquals("y", dom.child("foo").value()); + assertEquals("y", dom.getChild("foo").getValue()); } /** @@ -649,13 +649,13 @@ void testMergeCombineChildrenAppendOnRecessive() throws XMLStreamException, IOEx + " org.apache.shiro.crypto.cipher.CipherService\n" + " \n" + ""; - String recessive = "\n" + String recessive = "\n" + " \n" + " javax.faces\n" + " jakarta.faces\n" + " \n" + ""; - String expected = "\n" + String expected = "\n" + " \n" + " javax.faces\n" + " jakarta.faces\n" @@ -673,12 +673,12 @@ void testMergeCombineChildrenAppendOnRecessive() throws XMLStreamException, IOEx } private static List getChildren(XmlNode node, String name) { - return node.children().stream().filter(n -> n.name().equals(name)).toList(); + return node.getChildren().stream().filter(n -> n.getName().equals(name)).toList(); } private static XmlNode getNthChild(XmlNode node, String name, int nth) { - return node.children().stream() - .filter(n -> n.name().equals(name)) + return node.getChildren().stream() + .filter(n -> n.getName().equals(name)) .skip(nth) .findFirst() .orElse(null); diff --git a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlPlexusConfigurationOld.java b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlPlexusConfigurationOld.java index 9dfbb76de275..664c89ff4076 100644 --- a/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlPlexusConfigurationOld.java +++ b/impl/maven-xml/src/test/java/org/apache/maven/internal/xml/XmlPlexusConfigurationOld.java @@ -43,13 +43,13 @@ public static PlexusConfiguration toPlexusConfiguration(XmlNode node) { * This is the performance bottleneck that was optimized in the new implementation. */ public XmlPlexusConfigurationOld(XmlNode node) { - super(node.name(), node.value()); + super(node.getName(), node.getValue()); // Copy all attributes - node.attributes().forEach(this::setAttribute); + node.getAttributes().forEach(this::setAttribute); // Recursively create child configurations (expensive deep copying) - node.children().forEach(c -> this.addChild(new XmlPlexusConfigurationOld(c))); + node.getChildren().forEach(c -> this.addChild(new XmlPlexusConfigurationOld(c))); } @Override