[MNG-7655] Switch to plexus-utils / plexus-xml 4 (#1093)

This commit is contained in:
Guillaume Nodet 2023-06-04 21:03:41 +02:00 committed by GitHub
parent c124554316
commit e08c95a673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 72 additions and 817 deletions

View File

@ -31,7 +31,6 @@ under the License.
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>org.codehaus.plexus:plexus-classworlds</exclude>
<exclude>org.codehaus.plexus:plexus-utils</exclude>
</excludes>
</dependencySet>
</dependencySets>

View File

@ -18,11 +18,9 @@
*/
package org.apache.maven.usability.plugin;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@ -31,7 +29,6 @@ import java.util.List;
import java.util.Map;
import org.apache.maven.usability.plugin.io.xpp3.ParamdocXpp3Reader;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
@ -100,11 +97,9 @@ public class ExpressionDocumenter {
*/
private static Map<String, Expression> parseExpressionDocumentation(InputStream docStream)
throws IOException, XmlPullParserException {
Reader reader = new BufferedReader(ReaderFactory.newXmlReader(docStream));
ParamdocXpp3Reader paramdocReader = new ParamdocXpp3Reader();
ExpressionDocumentation documentation = paramdocReader.read(reader, true);
ExpressionDocumentation documentation = paramdocReader.read(docStream, true);
List<Expression> expressions = documentation.getExpressions();

View File

@ -129,7 +129,7 @@ under the License.
</dependency>
<!-- Plexus -->
<dependency>
<groupId>org.apache.maven</groupId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>

View File

@ -39,7 +39,7 @@ import org.apache.maven.api.services.xml.XmlWriterException;
import org.apache.maven.api.services.xml.XmlWriterRequest;
import org.apache.maven.model.v4.MavenXpp3ReaderEx;
import org.apache.maven.model.v4.MavenXpp3WriterEx;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.XmlStreamReader;
import static org.apache.maven.internal.impl.Utils.nonNull;
@ -64,11 +64,11 @@ public class DefaultModelXmlFactory implements ModelXmlFactory {
MavenXpp3ReaderEx xml = new MavenXpp3ReaderEx();
xml.setAddDefaultEntities(request.isAddDefaultEntities());
if (path != null) {
reader = ReaderFactory.newXmlReader(path.toFile());
reader = new XmlStreamReader(path.toFile());
} else if (url != null) {
reader = ReaderFactory.newXmlReader(url);
reader = new XmlStreamReader(url);
} else if (inputStream != null) {
reader = ReaderFactory.newXmlReader(inputStream);
reader = new XmlStreamReader(inputStream);
}
return xml.read(reader, request.isStrict(), source);
} catch (Exception e) {

View File

@ -29,7 +29,6 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -101,7 +100,6 @@ import org.codehaus.plexus.configuration.DefaultPlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.graph.DependencyFilter;
@ -264,10 +262,8 @@ public class DefaultMavenPluginManager implements MavenPluginManager {
private PluginDescriptor parsePluginDescriptor(InputStream is, Plugin plugin, String descriptorLocation)
throws PluginDescriptorParsingException {
try {
Reader reader = ReaderFactory.newXmlReader(is);
return builder.build(reader, descriptorLocation);
} catch (IOException | PlexusConfigurationException e) {
return builder.build(is, descriptorLocation);
} catch (PlexusConfigurationException e) {
throw new PluginDescriptorParsingException(plugin, descriptorLocation, e);
}
}

View File

@ -38,7 +38,7 @@ under the License.
<version>4.0.0-alpha-6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>

View File

@ -29,8 +29,8 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>plexus-utils</artifactId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>

View File

@ -42,6 +42,10 @@ under the License.
<artifactId>maven-xml-impl</artifactId>
<version>4.0.0-alpha-6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -24,7 +24,6 @@ import java.io.Reader;
import org.apache.maven.model.InputSource;
import org.apache.maven.model.Model;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
@ -53,8 +52,6 @@ public class MavenXpp3ReaderEx {
} // -- boolean getAddDefaultEntities()
/**
* @see ReaderFactory#newXmlReader
*
* @param reader a reader object.
* @param strict a strict object.
* @throws IOException IOException if any.
@ -70,8 +67,6 @@ public class MavenXpp3ReaderEx {
} // -- Model read( Reader, boolean )
/**
* @see ReaderFactory#newXmlReader
*
* @param reader a reader object.
* @throws IOException IOException if any.
* @throws XmlPullParserException XmlPullParserException if
@ -93,7 +88,10 @@ public class MavenXpp3ReaderEx {
* @return Model
*/
public Model read(InputStream in, boolean strict, InputSource source) throws IOException, XmlPullParserException {
return read(ReaderFactory.newXmlReader(in), strict, source);
XmlPullParser parser =
addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
parser.setInput(in, null);
return read(parser, strict, source);
} // -- Model read( InputStream, boolean )
/**
@ -106,7 +104,7 @@ public class MavenXpp3ReaderEx {
* @return Model
*/
public Model read(InputStream in, InputSource source) throws IOException, XmlPullParserException {
return read(ReaderFactory.newXmlReader(in), source);
return read(in, true, source);
} // -- Model read( InputStream )
/**

View File

@ -45,7 +45,7 @@ under the License.
<artifactId>org.eclipse.sisu.plexus</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>

View File

@ -19,6 +19,7 @@
package org.apache.maven.plugin.descriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
@ -44,6 +45,10 @@ public class PluginDescriptorBuilder {
return build(source, buildConfiguration(reader));
}
public PluginDescriptor build(InputStream input, String source) throws PlexusConfigurationException {
return build(source, buildConfiguration(input));
}
private PluginDescriptor build(String source, PlexusConfiguration c) throws PlexusConfigurationException {
PluginDescriptor pluginDescriptor = new PluginDescriptor();
@ -374,4 +379,12 @@ public class PluginDescriptorBuilder {
throw new PlexusConfigurationException(e.getMessage(), e);
}
}
public PlexusConfiguration buildConfiguration(InputStream configuration) throws PlexusConfigurationException {
try {
return XmlPlexusConfiguration.toPlexusConfiguration(XmlNodeBuilder.build(configuration, null));
} catch (IOException | XmlPullParserException e) {
throw new PlexusConfigurationException(e.getMessage(), e);
}
}
}

View File

@ -33,8 +33,8 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>plexus-utils</artifactId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>

View File

@ -69,7 +69,7 @@ under the License.
<artifactId>maven-resolver-impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>

View File

@ -52,7 +52,7 @@ under the License.
<artifactId>plexus-interpolation</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>

View File

@ -25,12 +25,12 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.file.Files;
import java.util.Map;
import java.util.Objects;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.v4.SettingsXpp3Reader;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
@ -46,7 +46,11 @@ public class DefaultSettingsReader implements SettingsReader {
public Settings read(File input, Map<String, ?> options) throws IOException {
Objects.requireNonNull(input, "input cannot be null");
return read(ReaderFactory.newXmlReader(input), options);
try (InputStream in = Files.newInputStream(input.toPath())) {
return new Settings(new SettingsXpp3Reader().read(in, isStrict(options)));
} catch (XmlPullParserException e) {
throw new SettingsParseException(e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e);
}
}
@Override

View File

@ -31,7 +31,7 @@ import java.util.Objects;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.v4.SettingsXpp3Writer;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.XmlStreamWriter;
/**
* Handles serialization of settings into the default textual format.
@ -49,7 +49,7 @@ public class DefaultSettingsWriter implements SettingsWriter {
output.getParentFile().mkdirs();
write(WriterFactory.newXmlWriter(output), options, settings);
write(new XmlStreamWriter(output), options, settings);
}
@Override

View File

@ -43,8 +43,8 @@ under the License.
<version>4.0.0-alpha-6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>plexus-utils</artifactId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
</dependencies>

View File

@ -23,7 +23,6 @@ import java.io.InputStream;
import java.io.Reader;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
@ -52,8 +51,6 @@ public class SettingsXpp3Reader {
} // -- boolean getAddDefaultEntities()
/**
* @see ReaderFactory#newXmlReader
*
* @param reader a reader object.
* @param strict a strict object.
* @throws IOException IOException if any.
@ -69,8 +66,6 @@ public class SettingsXpp3Reader {
} // -- Model read( Reader, boolean )
/**
* @see ReaderFactory#newXmlReader
*
* @param reader a reader object.
* @throws IOException IOException if any.
* @throws XmlPullParserException XmlPullParserException if
@ -92,7 +87,10 @@ public class SettingsXpp3Reader {
* @return Settings
*/
public Settings read(InputStream in, boolean strict) throws IOException, XmlPullParserException {
return read(ReaderFactory.newXmlReader(in), strict);
XmlPullParser parser =
addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser();
parser.setInput(in, null);
return read(parser, strict);
} // -- Model read( InputStream, boolean )
/**
@ -105,7 +103,7 @@ public class SettingsXpp3Reader {
* @return Settings
*/
public Settings read(InputStream in) throws IOException, XmlPullParserException {
return read(ReaderFactory.newXmlReader(in));
return read(in, true);
} // -- Model read( InputStream )
/**

View File

@ -44,7 +44,7 @@ under the License.
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>

View File

@ -25,12 +25,12 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.file.Files;
import java.util.Map;
import java.util.Objects;
import org.apache.maven.toolchain.model.PersistedToolchains;
import org.apache.maven.toolchain.v4.MavenToolchainsXpp3Reader;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
@ -47,7 +47,11 @@ public class DefaultToolchainsReader implements ToolchainsReader {
public PersistedToolchains read(File input, Map<String, ?> options) throws IOException {
Objects.requireNonNull(input, "input cannot be null");
return read(ReaderFactory.newXmlReader(input), options);
try (InputStream in = Files.newInputStream(input.toPath())) {
return new PersistedToolchains(new MavenToolchainsXpp3Reader().read(in, isStrict(options)));
} catch (XmlPullParserException e) {
throw new ToolchainsParseException(e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e);
}
}
@Override

View File

@ -42,8 +42,8 @@ under the License.
<version>4.0.0-alpha-6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>plexus-utils</artifactId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
</dependencies>

View File

@ -41,8 +41,8 @@ under the License.
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>${plexusUtilsVersionEmbedded}</version>
<artifactId>plexus-xml</artifactId>
<version>${plexusXmlVersion}</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -1,422 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.codehaus.plexus.util.xml;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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.XmlSerializer;
/**
* NOTE: remove all the util code in here when separated, this class should be pure data.
*/
public class Xpp3Dom implements Serializable {
private static final String[] EMPTY_STRING_ARRAY = new String[0];
public static final String CHILDREN_COMBINATION_MODE_ATTRIBUTE = "combine.children";
public static final String CHILDREN_COMBINATION_MERGE = "merge";
public static final String CHILDREN_COMBINATION_APPEND = "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 = CHILDREN_COMBINATION_MERGE;
public static final String SELF_COMBINATION_MODE_ATTRIBUTE = "combine.self";
public static final String SELF_COMBINATION_OVERRIDE = "override";
public static final String SELF_COMBINATION_MERGE = "merge";
public static final String SELF_COMBINATION_REMOVE = "remove";
/**
* This default mode for combining a DOM node during merge means that where element names match, the process will
* try to merge the element attributes and values, rather than overriding the recessive element completely with the
* 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 = SELF_COMBINATION_MERGE;
private ChildrenTracking childrenTracking;
private XmlNode dom;
public Xpp3Dom(String name) {
this.dom = new XmlNodeImpl(name);
}
/**
* @since 3.2.0
* @param inputLocation The input location.
* @param name The name of the Dom.
*/
public Xpp3Dom(String name, Object inputLocation) {
this.dom = new XmlNodeImpl(name, null, null, null, inputLocation);
}
/**
* Copy constructor.
* @param src The source Dom.
*/
public Xpp3Dom(Xpp3Dom src) {
this(src, src.getName());
}
/**
* Copy constructor with alternative name.
* @param src The source Dom.
* @param name The name of the Dom.
*/
public Xpp3Dom(Xpp3Dom src, String name) {
this.dom = new XmlNodeImpl(src.dom, name);
}
public Xpp3Dom(XmlNode dom) {
this.dom = dom;
}
public Xpp3Dom(XmlNode dom, Xpp3Dom parent) {
this.dom = dom;
this.childrenTracking = parent::replace;
}
public Xpp3Dom(XmlNode dom, ChildrenTracking childrenTracking) {
this.dom = dom;
this.childrenTracking = childrenTracking;
}
public XmlNode getDom() {
return dom;
}
// ----------------------------------------------------------------------
// Name handling
// ----------------------------------------------------------------------
public String getName() {
return dom.getName();
}
// ----------------------------------------------------------------------
// Value handling
// ----------------------------------------------------------------------
public String getValue() {
return dom.getValue();
}
public void setValue(String value) {
update(new XmlNodeImpl(dom.getName(), value, dom.getAttributes(), dom.getChildren(), dom.getInputLocation()));
}
// ----------------------------------------------------------------------
// Attribute handling
// ----------------------------------------------------------------------
public String[] getAttributeNames() {
return dom.getAttributes().keySet().toArray(EMPTY_STRING_ARRAY);
}
public String getAttribute(String name) {
return dom.getAttribute(name);
}
/**
*
* @param name name of the attribute to be removed
* @return <code>true</code> if the attribute has been removed
* @since 3.4.0
*/
public boolean removeAttribute(String name) {
if (name != null && !name.isEmpty()) {
Map<String, String> attrs = new HashMap<>(dom.getAttributes());
boolean ret = attrs.remove(name) != null;
if (ret) {
update(new XmlNodeImpl(
dom.getName(), dom.getValue(), attrs, dom.getChildren(), dom.getInputLocation()));
}
return ret;
}
return false;
}
/**
* Set the attribute value
*
* @param name String not null
* @param value String not null
*/
public void setAttribute(String name, String value) {
if (null == value) {
throw new NullPointerException("Attribute value can not be null");
}
if (null == name) {
throw new NullPointerException("Attribute name can not be null");
}
Map<String, String> attrs = new HashMap<>(dom.getAttributes());
attrs.put(name, value);
update(new XmlNodeImpl(dom.getName(), dom.getValue(), attrs, dom.getChildren(), dom.getInputLocation()));
}
// ----------------------------------------------------------------------
// Child handling
// ----------------------------------------------------------------------
public Xpp3Dom getChild(int i) {
return new Xpp3Dom(dom.getChildren().get(i), this);
}
public Xpp3Dom getChild(String name) {
XmlNode child = dom.getChild(name);
return child != null ? new Xpp3Dom(child, this) : null;
}
public void addChild(Xpp3Dom xpp3Dom) {
List<XmlNode> children = new ArrayList<>(dom.getChildren());
children.add(xpp3Dom.dom);
xpp3Dom.childrenTracking = this::replace;
update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation()));
}
public Xpp3Dom[] getChildren() {
return dom.getChildren().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))
.map(d -> new Xpp3Dom(d, this))
.toArray(Xpp3Dom[]::new);
}
public int getChildCount() {
return dom.getChildren().size();
}
public void removeChild(int i) {
List<XmlNode> children = new ArrayList<>(dom.getChildren());
children.remove(i);
update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation()));
}
public void removeChild(Xpp3Dom child) {
List<XmlNode> children = new ArrayList<>(dom.getChildren());
children.remove(child.dom);
update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation()));
}
// ----------------------------------------------------------------------
// Parent handling
// ----------------------------------------------------------------------
public Xpp3Dom getParent() {
throw new UnsupportedOperationException();
}
public void setParent(Xpp3Dom parent) {}
// ----------------------------------------------------------------------
// Input location handling
// ----------------------------------------------------------------------
/**
* @since 3.2.0
* @return input location
*/
public Object getInputLocation() {
return dom.getInputLocation();
}
/**
* @since 3.2.0
* @param inputLocation input location to set
*/
public void setInputLocation(Object inputLocation) {
update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), dom.getChildren(), inputLocation));
}
// ----------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------
public void writeToSerializer(String namespace, XmlSerializer serializer) throws IOException {
// TODO: WARNING! Later versions of plexus-utils psit out an <?xml ?> header due to thinking this is a new
// document - not the desired behaviour!
SerializerXMLWriter xmlWriter = new SerializerXMLWriter(namespace, serializer);
Xpp3DomWriter.write(xmlWriter, this);
if (xmlWriter.getExceptions().size() > 0) {
throw (IOException) xmlWriter.getExceptions().get(0);
}
}
/**
* Merges one DOM into another, given a specific algorithm and possible override points for that algorithm.<p>
* The algorithm is as follows:
* <ol>
* <li> if the recessive DOM is null, there is nothing to do... return.</li>
* <li> Determine whether the dominant node will suppress the recessive one (flag=mergeSelf).
* <ol type="A">
* <li> retrieve the 'combine.self' attribute on the dominant node, and try to match against 'override'...
* if it matches 'override', then set mergeSelf == false...the dominant node suppresses the recessive one
* completely.</li>
* <li> otherwise, use the default value for mergeSelf, which is true...this is the same as specifying
* 'combine.self' == 'merge' as an attribute of the dominant root node.</li>
* </ol></li>
* <li> If mergeSelf == true
* <ol type="A">
* <li> if the dominant root node's value is empty, set it to the recessive root node's value</li>
* <li> For each attribute in the recessive root node which is not set in the dominant root node, set it.</li>
* <li> Determine whether children from the recessive DOM will be merged or appended to the dominant DOM as
* siblings (flag=mergeChildren).
* <ol type="i">
* <li> if childMergeOverride is set (non-null), use that value (true/false)</li>
* <li> retrieve the 'combine.children' attribute on the dominant node, and try to match against
* 'append'...</li>
* <li> if it matches 'append', then set mergeChildren == false...the recessive children will be appended as
* siblings of the dominant children.</li>
* <li> otherwise, use the default value for mergeChildren, which is true...this is the same as specifying
* 'combine.children' == 'merge' as an attribute on the dominant root node.</li>
* </ol></li>
* <li> Iterate through the recessive children, and:
* <ol type="i">
* <li> if mergeChildren == true and there is a corresponding dominant child (matched by element name),
* merge the two.</li>
* <li> otherwise, add the recessive child as a new child on the dominant root node.</li>
* </ol></li>
* </ol></li>
* </ol>
*/
private static void mergeIntoXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) {
// TODO: share this as some sort of assembler, implement a walk interface?
if (recessive == null) {
return;
}
dominant.dom = dominant.dom.merge(recessive.dom, childMergeOverride);
}
/**
* Merge two DOMs, with one having dominance in the case of collision.
*
* @see #CHILDREN_COMBINATION_MODE_ATTRIBUTE
* @see #SELF_COMBINATION_MODE_ATTRIBUTE
* @param dominant The dominant DOM into which the recessive value/attributes/children will be merged
* @param recessive The recessive DOM, which will be merged into the dominant DOM
* @param childMergeOverride Overrides attribute flags to force merging or appending of child elements into the
* dominant DOM
* @return merged DOM
*/
public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) {
if (dominant != null) {
mergeIntoXpp3Dom(dominant, recessive, childMergeOverride);
return dominant;
}
return recessive;
}
/**
* Merge two DOMs, with one having dominance in the case of collision. Merge mechanisms (vs. override for nodes, or
* vs. append for children) is determined by attributes of the dominant root node.
*
* @see #CHILDREN_COMBINATION_MODE_ATTRIBUTE
* @see #SELF_COMBINATION_MODE_ATTRIBUTE
* @param dominant The dominant DOM into which the recessive value/attributes/children will be merged
* @param recessive The recessive DOM, which will be merged into the dominant DOM
* @return merged DOM
*/
public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive) {
if (dominant != null) {
mergeIntoXpp3Dom(dominant, recessive, null);
return dominant;
}
return recessive;
}
// ----------------------------------------------------------------------
// Standard object handling
// ----------------------------------------------------------------------
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Xpp3Dom)) {
return false;
}
Xpp3Dom dom = (Xpp3Dom) obj;
return this.dom.equals(dom.dom);
}
@Override
public int hashCode() {
return dom.hashCode();
}
@Override
public String toString() {
return dom.toString();
}
public String toUnescapedString() {
return ((Xpp3Dom) dom).toUnescapedString();
}
public static boolean isNotEmpty(String str) {
return ((str != null) && (str.length() > 0));
}
public static boolean isEmpty(String str) {
return ((str == null) || (str.trim().length() == 0));
}
private void update(XmlNode dom) {
if (childrenTracking != null) {
childrenTracking.replace(this.dom, dom);
}
this.dom = dom;
}
private boolean replace(Object prevChild, Object newChild) {
List<XmlNode> children = new ArrayList<>(dom.getChildren());
children.replaceAll(d -> d == prevChild ? (XmlNode) newChild : d);
update(new XmlNodeImpl(dom.getName(), dom.getValue(), dom.getAttributes(), children, dom.getInputLocation()));
return true;
}
public void setChildrenTracking(ChildrenTracking childrenTracking) {
this.childrenTracking = childrenTracking;
}
@FunctionalInterface
public interface ChildrenTracking {
boolean replace(Object oldDelegate, Object newDelegate);
}
}

View File

@ -1,98 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.codehaus.plexus.util.xml;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.apache.maven.internal.xml.XmlNodeBuilder;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
* @version $Id$
*/
public class Xpp3DomBuilder {
private static final boolean DEFAULT_TRIM = true;
public static Xpp3Dom build(Reader reader) throws XmlPullParserException, IOException {
return build(reader, null);
}
/**
* @since 3.2.0
*/
public static Xpp3Dom build(Reader reader, InputLocationBuilder locationBuilder)
throws XmlPullParserException, IOException {
return build(reader, DEFAULT_TRIM, locationBuilder);
}
public static Xpp3Dom build(InputStream is, String encoding) throws XmlPullParserException, IOException {
return build(is, encoding, DEFAULT_TRIM);
}
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));
}
}
public static Xpp3Dom build(Reader reader, boolean trim) throws XmlPullParserException, IOException {
return build(reader, trim, null);
}
/**
* @since 3.2.0
*/
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));
}
}
public static Xpp3Dom build(XmlPullParser parser) throws XmlPullParserException, IOException {
return build(parser, DEFAULT_TRIM);
}
public static Xpp3Dom build(XmlPullParser parser, boolean trim) throws XmlPullParserException, IOException {
return build(parser, trim, null);
}
/**
* @since 3.2.0
*/
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));
}
/**
* Input location builder interface, to be implemented to choose how to store data.
*
* @since 3.2.0
*/
public interface InputLocationBuilder {
Object toInputLocation(XmlPullParser parser);
}
}

View File

@ -1,10 +0,0 @@
// CHECKSTYLE_OFF: RegexpHeader
/**
* Contains modified versions of the
* {@link org.codehaus.plexus.util.xml.Xpp3Dom} and
* {@link org.codehaus.plexus.util.xml.Xpp3DomBuilder}
* classes.
* The modified {@link org.codehaus.plexus.util.xml.Xpp3Dom} wraps
* an immutable {@link org.apache.maven.api.xml.XmlNode} instance.
*/
package org.codehaus.plexus.util.xml;

View File

@ -1,166 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>4.0.0-alpha-6-SNAPSHOT</version>
</parent>
<groupId>org.apache.maven</groupId>
<artifactId>plexus-utils</artifactId>
<version>4.0.0-alpha-6-SNAPSHOT</version>
<name>Apache Maven Plexus-Utils</name>
<description>Apache Maven repackaging of Plexus Utils with immutable Dom interface and its replacement implementation.</description>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>${plexusUtilsVersionEmbedded}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-xml-impl</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>unpack-sources</id>
<goals>
<goal>unpack</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>${plexusUtilsVersionEmbedded}</version>
<classifier>sources</classifier>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/generated-sources/plexus-utils</outputDirectory>
<includes>**/*.java</includes>
<excludes>org/codehaus/plexus/util/xml/Xpp3Dom.java,
org/codehaus/plexus/util/xml/Xpp3DomBuilder.java</excludes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpack-classes</id>
<goals>
<goal>unpack</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>${plexusUtilsVersionEmbedded}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<includes>**/*.class,**/*.xml</includes>
<excludes>org/codehaus/plexus/util/xml/Xpp3Dom.class,
org/codehaus/plexus/util/xml/Xpp3DomBuilder.class</excludes>
</artifactItem>
<artifactItem>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-xml</artifactId>
<version>${project.version}</version>
<type>jar</type>
<includes>**/*</includes>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.apache.maven</groupId>
<artifactId>maven-xml-impl</artifactId>
<version>${project.version}</version>
<type>jar</type>
<includes>**/*</includes>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</artifactItem>
</artifactItems>
<includes>**/*.java</includes>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>add-source</id>
<goals>
<goal>add-source</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<sources>
<source>target/generated-sources/plexus-utils</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<executions>
<execution>
<id>compile</id>
<configuration>
<skipMain>true</skipMain>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<executions>
<execution>
<id>check-java-compat</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,26 +0,0 @@
<!---
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
Apache Maven Plexus Utils
=========================
This module is a repackaging of the `org.codehaus.plexus:plexus-utils` jar, which contains a few modified classes to allow a seamless transition between the Maven 3.x and 4.x APIs.
The Maven 4.x API is based on immutable data objects. The Maven model contains a few classes that contain some open xml data for configuration (`Plugin`, `PluginExecution`, `ReportPlugin` and `ReportSet`). So the v3 API which was using the `org.codehaus.plexus.utils.xml.Xpp3Dom` class now wraps the `org.apache.maven.api.Dom` interface node. This is completely transparent for existing plugins, but the correct (new) classes have to be used.
Given the new implementation of `org.codehaus.plexus.utils.xml.Xpp3Dom` now relies on `org.apache.maven.api.Dom`, the modifications can't be made inside the `plexus-utils` project, because Maven itself depends on it.
This is drop-in replacement for `plexus-utils` ${plexusUtilsVersionEmbedded}.

View File

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/DECORATION/1.8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 http://maven.apache.org/xsd/decoration-1.8.0.xsd">
<edit>${project.scm.url}</edit>
<body>
<menu name="Overview">
<item name="Introduction" href="index.html"/>
<!--item name="Javadocs" href="apidocs/index.html"/>
<item name="Source Xref" href="xref/index.html"/>
<item name="FAQ" href="faq.html"/-->
</menu>
<menu ref="parent"/>
<menu ref="reports"/>
</body>
</project>

12
pom.xml
View File

@ -108,7 +108,6 @@ under the License.
<module>maven-model-transform</module>
<module>api</module>
<module>maven-xml-impl</module>
<module>plexus-utils</module>
<module>maven-core</module>
<module>maven-settings</module>
<module>maven-settings-builder</module>
@ -157,8 +156,8 @@ under the License.
<mockitoVersion>4.11.0</mockitoVersion>
<plexusVersion>2.1.0</plexusVersion>
<plexusInterpolationVersion>1.26</plexusInterpolationVersion>
<plexusUtilsVersion>4.0.0-alpha-6-SNAPSHOT</plexusUtilsVersion>
<plexusUtilsVersionEmbedded>3.5.1</plexusUtilsVersionEmbedded>
<plexusUtilsVersion>4.0.0</plexusUtilsVersion>
<plexusXmlVersion>4.0.0</plexusXmlVersion>
<guiceVersion>5.1.0</guiceVersion>
<guavaVersion>30.1-jre</guavaVersion>
<guavafailureaccessVersion>1.0.1</guavafailureaccessVersion>
@ -206,10 +205,15 @@ under the License.
<!--bootstrap-end-comment-->
<!-- Plexus -->
<dependency>
<groupId>org.apache.maven</groupId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>${plexusUtilsVersion}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
<version>${plexusXmlVersion}</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>