Remove hardcoded references to woodstox stax implementation

This commit is contained in:
Guillaume Nodet 2024-06-13 09:08:07 +02:00
parent 56cfb7fa46
commit df94ee0d2c
10 changed files with 25 additions and 34 deletions

View File

@ -18,6 +18,7 @@
*/
package org.apache.maven.internal.impl.model;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@ -26,7 +27,6 @@ import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import com.ctc.wstx.stax.WstxInputFactory;
import org.apache.maven.api.di.Named;
import org.apache.maven.api.services.model.*;
@ -40,7 +40,7 @@ public class DefaultRootLocator implements RootLocator {
// we're too early to use the modelProcessor ...
Path pom = dir.resolve("pom.xml");
try (InputStream is = Files.newInputStream(pom)) {
XMLStreamReader parser = new WstxInputFactory().createXMLStreamReader(is);
XMLStreamReader parser = XMLInputFactory.newFactory().createXMLStreamReader(is);
if (parser.nextTag() == XMLStreamReader.START_ELEMENT
&& parser.getLocalName().equals("project")) {
for (int i = 0; i < parser.getAttributeCount(); i++) {

View File

@ -18,6 +18,7 @@
*/
package org.apache.maven.project;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@ -30,7 +31,6 @@ import java.util.List;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import com.ctc.wstx.stax.WstxInputFactory;
import org.apache.maven.api.xml.XmlNode;
import org.apache.maven.internal.xml.XmlNodeStaxBuilder;
@ -88,7 +88,7 @@ public class ExtensionDescriptorBuilder {
XmlNode dom;
try {
XMLStreamReader reader = WstxInputFactory.newFactory().createXMLStreamReader(is);
XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(is);
dom = XmlNodeStaxBuilder.build(reader);
} catch (XMLStreamException e) {
throw new IOException(e.getMessage(), e);

View File

@ -108,7 +108,7 @@ public class DefaultModelReader implements ModelReader {
private Model read(InputStream input, Path pomFile, Map<String, ?> options) throws IOException {
try {
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader parser = factory.createXMLStreamReader(input);
@ -132,7 +132,7 @@ public class DefaultModelReader implements ModelReader {
private Model read(Reader reader, Path pomFile, Map<String, ?> options) throws IOException {
try {
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader parser = factory.createXMLStreamReader(reader);

View File

@ -19,6 +19,7 @@
package org.apache.maven.model.root;
import javax.inject.Named;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@ -27,8 +28,6 @@ import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import com.ctc.wstx.stax.WstxInputFactory;
@Named
public class DefaultRootLocator implements RootLocator {
@ -39,7 +38,7 @@ public class DefaultRootLocator implements RootLocator {
// we're too early to use the modelProcessor ...
Path pom = dir.resolve("pom.xml");
try (InputStream is = Files.newInputStream(pom)) {
XMLStreamReader parser = new WstxInputFactory().createXMLStreamReader(is);
XMLStreamReader parser = XMLInputFactory.newFactory().createXMLStreamReader(is);
if (parser.nextTag() == XMLStreamReader.START_ELEMENT
&& parser.getLocalName().equals("project")) {
for (int i = 0; i < parser.getAttributeCount(); i++) {

View File

@ -18,6 +18,7 @@
*/
package org.apache.maven.plugin.descriptor;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@ -30,7 +31,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import com.ctc.wstx.stax.WstxInputFactory;
import org.apache.maven.api.xml.XmlNode;
import org.apache.maven.internal.xml.XmlNodeStaxBuilder;
import org.apache.maven.internal.xml.XmlPlexusConfiguration;
@ -81,11 +81,11 @@ public class PluginDescriptorBuilder {
public PluginDescriptor build(ReaderSupplier readerSupplier, String source) throws PlexusConfigurationException {
try (BufferedReader br = new BufferedReader(readerSupplier.open(), BUFFER_SIZE)) {
br.mark(BUFFER_SIZE);
XMLStreamReader xsr = WstxInputFactory.newFactory().createXMLStreamReader(br);
XMLStreamReader xsr = XMLInputFactory.newFactory().createXMLStreamReader(br);
xsr.nextTag();
String nsUri = xsr.getNamespaceURI();
try (BufferedReader br2 = reset(readerSupplier, br)) {
xsr = WstxInputFactory.newFactory().createXMLStreamReader(br2);
xsr = XMLInputFactory.newFactory().createXMLStreamReader(br2);
return build(source, nsUri, xsr);
}
} catch (XMLStreamException | IOException e) {
@ -108,11 +108,11 @@ public class PluginDescriptorBuilder {
public PluginDescriptor build(StreamSupplier inputSupplier, String source) throws PlexusConfigurationException {
try (BufferedInputStream bis = new BufferedInputStream(inputSupplier.open(), BUFFER_SIZE)) {
bis.mark(BUFFER_SIZE);
XMLStreamReader xsr = WstxInputFactory.newFactory().createXMLStreamReader(bis);
XMLStreamReader xsr = XMLInputFactory.newFactory().createXMLStreamReader(bis);
xsr.nextTag();
String nsUri = xsr.getNamespaceURI();
try (BufferedInputStream bis2 = reset(inputSupplier, bis)) {
xsr = WstxInputFactory.newFactory().createXMLStreamReader(bis2);
xsr = XMLInputFactory.newFactory().createXMLStreamReader(bis2);
return build(source, nsUri, xsr);
}
} catch (XMLStreamException | IOException e) {
@ -470,7 +470,7 @@ public class PluginDescriptorBuilder {
public PlexusConfiguration buildConfiguration(Reader configuration) throws PlexusConfigurationException {
try {
XMLStreamReader reader = WstxInputFactory.newFactory().createXMLStreamReader(configuration);
XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(configuration);
return XmlPlexusConfiguration.toPlexusConfiguration(XmlNodeStaxBuilder.build(reader, true, null));
} catch (XMLStreamException e) {
throw new PlexusConfigurationException(e.getMessage(), e);
@ -479,7 +479,7 @@ public class PluginDescriptorBuilder {
public PlexusConfiguration buildConfiguration(InputStream configuration) throws PlexusConfigurationException {
try {
XMLStreamReader reader = WstxInputFactory.newFactory().createXMLStreamReader(configuration);
XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(configuration);
return XmlPlexusConfiguration.toPlexusConfiguration(XmlNodeStaxBuilder.build(reader, true, null));
} catch (XMLStreamException e) {
throw new PlexusConfigurationException(e.getMessage(), e);

View File

@ -18,9 +18,6 @@
*/
package org.apache.maven.artifact.repository.metadata;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.text.DateFormat;
@ -29,8 +26,6 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import com.ctc.wstx.stax.WstxInputFactory;
import com.ctc.wstx.stax.WstxOutputFactory;
import org.apache.maven.metadata.v4.MetadataStaxReader;
import org.apache.maven.metadata.v4.MetadataStaxWriter;
import org.eclipse.aether.artifact.Artifact;
@ -221,9 +216,6 @@ class MetadataTest {
@Test
void testRoundtrip() throws Exception {
System.setProperty(XMLInputFactory.class.getName(), WstxInputFactory.class.getName());
System.setProperty(XMLOutputFactory.class.getName(), WstxOutputFactory.class.getName());
Metadata source = new Metadata(org.apache.maven.api.metadata.Metadata.newBuilder(
createMetadataFromArtifact(artifact).getDelegate(), true)
.modelEncoding("UTF-16")

View File

@ -18,6 +18,7 @@
*/
package org.apache.maven.internal.xml;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@ -28,7 +29,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.ctc.wstx.stax.WstxInputFactory;
import org.apache.maven.api.xml.XmlNode;
/**
@ -40,12 +40,12 @@ public class XmlNodeStaxBuilder {
public static XmlNodeImpl build(InputStream stream, InputLocationBuilderStax locationBuilder)
throws XMLStreamException {
XMLStreamReader parser = WstxInputFactory.newFactory().createXMLStreamReader(stream);
XMLStreamReader parser = XMLInputFactory.newFactory().createXMLStreamReader(stream);
return build(parser, DEFAULT_TRIM, locationBuilder);
}
public static XmlNodeImpl build(Reader reader, InputLocationBuilderStax locationBuilder) throws XMLStreamException {
XMLStreamReader parser = WstxInputFactory.newFactory().createXMLStreamReader(reader);
XMLStreamReader parser = XMLInputFactory.newFactory().createXMLStreamReader(reader);
return build(parser, DEFAULT_TRIM, locationBuilder);
}

View File

@ -18,12 +18,12 @@
*/
package org.apache.maven.internal.xml;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import java.io.IOException;
import java.io.StringReader;
import com.ctc.wstx.stax.WstxInputFactory;
import org.apache.maven.api.xml.XmlNode;
import org.junit.jupiter.api.Test;
@ -49,7 +49,7 @@ class XmlNodeBuilderTest {
void testWithNamespace() throws Exception {
String doc = "<?xml version='1.0'?><doc xmlns='foo:bar'/>";
StringReader r = new StringReader(doc);
XMLStreamReader xsr = WstxInputFactory.newFactory().createXMLStreamReader(r);
XMLStreamReader xsr = XMLInputFactory.newFactory().createXMLStreamReader(r);
XmlNode node = XmlNodeStaxBuilder.build(xsr);
assertEquals("doc", node.getName());
assertEquals(1, node.getAttributes().size());

View File

@ -421,7 +421,7 @@ public class ${className} {
#else
public ${root.name} read(Reader reader, boolean strict) throws XMLStreamException {
#end
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
#if ( $locationTracking )
StreamSource streamSource = new StreamSource(reader, source != null ? source.getLocation() : null);
@ -458,7 +458,7 @@ public class ${className} {
#else
public ${root.name} read(InputStream in, boolean strict) throws XMLStreamException {
#end
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
#if ( $locationTracking )
StreamSource streamSource = new StreamSource(in, source != null ? source.getLocation() : null);

View File

@ -358,7 +358,7 @@ public class ${className} {
* @return ${root.name}
*/
public ${root.name} read(Reader reader, boolean strict) throws IOException, XMLStreamException {
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader parser = null;
try {
@ -392,7 +392,7 @@ public class ${className} {
* @return ${root.name}
*/
public ${root.name} read(InputStream in, boolean strict) throws IOException, XMLStreamException {
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
StreamSource streamSource = new StreamSource(in, null);
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);
@ -409,7 +409,7 @@ public class ${className} {
* @return ${root.name}
*/
public ${root.name} read(InputStream in) throws IOException, XMLStreamException {
XMLInputFactory factory = new com.ctc.wstx.stax.WstxInputFactory();
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
StreamSource streamSource = new StreamSource(in, null);
XMLStreamReader parser = factory.createXMLStreamReader(streamSource);