Skip to content

Commit

Permalink
Remove hardcoded references to woodstox stax implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jun 13, 2024
1 parent 56cfb7f commit df94ee0
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,7 +27,6 @@
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.*;

Expand All @@ -40,7 +40,7 @@ public boolean isRootDirectory(Path dir) {
// 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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.project;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

Expand All @@ -30,7 +31,6 @@
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;

Expand Down Expand Up @@ -88,7 +88,7 @@ public ExtensionDescriptor build(InputStream is) throws IOException {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private Path getRootDirectory(Map<String, ?> options) {

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);

Expand All @@ -132,7 +132,7 @@ private Model read(InputStream input, Path pomFile, Map<String, ?> options) thro

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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,8 +28,6 @@
import java.nio.file.Files;
import java.nio.file.Path;

import com.ctc.wstx.stax.WstxInputFactory;

@Named
public class DefaultRootLocator implements RootLocator {

Expand All @@ -39,7 +38,7 @@ public boolean isRootDirectory(Path dir) {
// 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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,7 +31,6 @@
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;
Expand Down Expand Up @@ -81,11 +81,11 @@ public PluginDescriptor build(ReaderSupplier readerSupplier) throws PlexusConfig
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) {
Expand All @@ -108,11 +108,11 @@ public PluginDescriptor build(StreamSupplier inputSupplier) throws PlexusConfigu
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) {
Expand Down Expand Up @@ -470,7 +470,7 @@ public MojoDescriptor buildComponentDescriptor(PlexusConfiguration c, PluginDesc

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);
Expand All @@ -479,7 +479,7 @@ public PlexusConfiguration buildConfiguration(Reader configuration) throws Plexu

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,8 +26,6 @@
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;
Expand Down Expand Up @@ -221,9 +216,6 @@ void mergeWithSnapshotLegacy() {

@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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -28,7 +29,6 @@
import java.util.List;
import java.util.Map;

import com.ctc.wstx.stax.WstxInputFactory;
import org.apache.maven.api.xml.XmlNode;

/**
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -49,7 +49,7 @@ public int read(char[] cbuf, int off, int len) throws IOException {
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());
Expand Down
4 changes: 2 additions & 2 deletions src/mdo/reader-stax.vm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/mdo/reader.vm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit df94ee0

Please sign in to comment.