From aefa9599fbc685c16cbfe03d09b68c19f10b4053 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 22 Sep 2023 09:03:47 +0200 Subject: [PATCH] Avoid usage of XmlStreamReader (#1256) --- .../metadata/io/DefaultMetadataReader.java | 3 +-- .../PomConstructionWithSettingsTest.java | 18 ++++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/io/DefaultMetadataReader.java b/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/io/DefaultMetadataReader.java index e4f4a97e13..dc5cf5b5a2 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/io/DefaultMetadataReader.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/repository/metadata/io/DefaultMetadataReader.java @@ -31,7 +31,6 @@ import java.util.Map; import java.util.Objects; import org.apache.maven.artifact.repository.metadata.Metadata; -import org.codehaus.plexus.util.xml.XmlStreamReader; /** * Handles deserialization of metadata from some kind of textual format like XML. @@ -44,7 +43,7 @@ public class DefaultMetadataReader implements MetadataReader { public Metadata read(File input, Map options) throws IOException { Objects.requireNonNull(input, "input cannot be null"); - return read(new XmlStreamReader(Files.newInputStream(input.toPath())), options); + return read(Files.newInputStream(input.toPath()), options); } public Metadata read(Reader input, Map options) throws IOException { diff --git a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java index f8630aa397..bb7193d431 100644 --- a/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java +++ b/maven-core/src/test/java/org/apache/maven/settings/PomConstructionWithSettingsTest.java @@ -23,8 +23,10 @@ import javax.xml.stream.XMLStreamException; import java.io.File; import java.io.IOException; -import java.io.Reader; +import java.io.InputStream; +import java.nio.file.Files; +import org.apache.maven.api.settings.InputSource; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.bridge.MavenRepositorySystem; import org.apache.maven.model.Profile; @@ -33,9 +35,8 @@ import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.harness.PomTestWrapper; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; -import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; +import org.apache.maven.settings.v4.SettingsStaxReader; import org.codehaus.plexus.testing.PlexusTest; -import org.codehaus.plexus.util.xml.XmlStreamReader; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; @@ -121,13 +122,10 @@ class PomConstructionWithSettingsTest { } private static Settings readSettingsFile(File settingsFile) throws IOException, XMLStreamException { - Settings settings = null; - - try (Reader reader = new XmlStreamReader(settingsFile)) { - SettingsXpp3Reader modelReader = new SettingsXpp3Reader(); - - settings = modelReader.read(reader); + try (InputStream is = Files.newInputStream(settingsFile.toPath())) { + SettingsStaxReader reader = new SettingsStaxReader(); + InputSource source = new InputSource(settingsFile.toString()); + return new Settings(reader.read(is, true, source)); } - return settings; } }