You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2023/02/20 14:02:56 UTC
[maven] 01/01: Prefer Apache commons utils and Java 7 to codehaus
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch io
in repository https://gitbox.apache.org/repos/asf/maven.git
commit fc431e8ebd69f3892fb8865377d96e3f7796a60c
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Mon Feb 20 09:02:37 2023 -0500
Prefer Apache commons utils and Java 7 to codehaus
---
.../profiles/DefaultMavenProfilesBuilder.java | 9 +++------
.../apache/maven/internal/xml/XmlNodeBuilder.java | 22 ++++++++--------------
2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/maven-compat/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java b/maven-compat/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java
index 87c48f7da..7180e6cdd 100644
--- a/maven-compat/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java
+++ b/maven-compat/src/main/java/org/apache/maven/profiles/DefaultMavenProfilesBuilder.java
@@ -22,14 +22,13 @@ import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
-import java.io.StringWriter;
+import org.apache.commons.io.IOUtils;
import org.apache.maven.profiles.io.xpp3.ProfilesXpp3Reader;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.interpolation.EnvarBasedValueSource;
import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@@ -48,11 +47,9 @@ public class DefaultMavenProfilesBuilder extends AbstractLogEnabled implements M
if (profilesXml.exists()) {
ProfilesXpp3Reader reader = new ProfilesXpp3Reader();
- try (Reader profileReader = ReaderFactory.newXmlReader(profilesXml);
- StringWriter sWriter = new StringWriter()) {
- IOUtil.copy(profileReader, sWriter);
+ try (Reader profileReader = ReaderFactory.newXmlReader(profilesXml)) {
- String rawInput = sWriter.toString();
+ String rawInput = IOUtils.toString(profileReader);
try {
RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
diff --git a/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeBuilder.java b/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeBuilder.java
index c2b3217a2..3fda2c157 100644
--- a/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeBuilder.java
+++ b/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeBuilder.java
@@ -27,13 +27,13 @@ import java.util.List;
import java.util.Map;
import org.apache.maven.api.xml.XmlNode;
-import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
- *
+ * All methods in this class attempt to fully parse the XML and
+ * then close the supplied reader or input stream.
*/
public class XmlNodeBuilder {
private static final boolean DEFAULT_TRIM = true;
@@ -61,17 +61,13 @@ public class XmlNodeBuilder {
public static XmlNodeImpl build(InputStream is, String encoding, boolean trim)
throws XmlPullParserException, IOException {
- try {
+ try (InputStream in = is) {
final XmlPullParser parser = new MXParser();
- parser.setInput(is, encoding);
+ parser.setInput(in, encoding);
final XmlNodeImpl node = build(parser, trim);
- is.close();
- is = null;
return node;
- } finally {
- IOUtil.close(is);
}
}
@@ -80,6 +76,8 @@ public class XmlNodeBuilder {
}
/**
+ * This method closes its reader.
+ *
* @param reader the reader
* @param trim to trim
* @param locationBuilder the builder
@@ -90,17 +88,13 @@ public class XmlNodeBuilder {
*/
public static XmlNodeImpl build(Reader reader, boolean trim, InputLocationBuilder locationBuilder)
throws XmlPullParserException, IOException {
- try {
+ try (Reader in = reader) {
final XmlPullParser parser = new MXParser();
- parser.setInput(reader);
+ parser.setInput(in);
final XmlNodeImpl node = build(parser, trim, locationBuilder);
- reader.close();
- reader = null;
return node;
- } finally {
- IOUtil.close(reader);
}
}