From 86d38a6c823457a78fdcfe2bc38fca24bb6a2c9f Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 18 Jul 2024 16:14:57 +0100 Subject: [PATCH 1/2] Remove redundant `InputStreamReader` --- .../main/java/org/codehaus/mojo/versions/api/PomHelper.java | 5 +---- .../org/codehaus/mojo/versions/utils/CoreExtensionUtils.java | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java index b3e19123bb..de8c2def44 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java @@ -23,10 +23,8 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import java.io.UncheckedIOException; @@ -142,8 +140,7 @@ public static Model getRawModel(MavenProject project) throws IOException { * @throws IOException if the file is not found or if the file does not parse. */ public static Model getRawModel(File moduleProjectFile) throws IOException { - try (Reader reader = - new BufferedReader(new InputStreamReader(Files.newInputStream(moduleProjectFile.toPath())))) { + try (Reader reader = Files.newBufferedReader(moduleProjectFile.toPath())) { Model result = getRawModel(reader); result.setPomFile(moduleProjectFile); return result; diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java index 64564dfe56..6a49029e82 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java @@ -16,9 +16,7 @@ * limitations under the License. */ -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import java.io.Reader; import java.nio.file.Files; import java.nio.file.Path; @@ -52,7 +50,7 @@ public static Stream getCoreExtensions(MavenProject project) throws I return Stream.empty(); } - try (Reader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(extensionsFile)))) { + try (Reader reader = Files.newBufferedReader(extensionsFile)) { return new CoreExtensionsXpp3Reader() .read(reader).getExtensions().stream().map(ex -> ExtensionBuilder.newBuilder() .withGroupId(ex.getGroupId()) From 99063253062fa73ae1797145d22ab906ffb99591 Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 19 Jul 2024 23:00:39 +0100 Subject: [PATCH 2/2] Fix encoding issues --- .../main/java/org/codehaus/mojo/versions/api/PomHelper.java | 3 ++- .../org/codehaus/mojo/versions/utils/CoreExtensionUtils.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java index de8c2def44..c52a8b8f75 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java @@ -28,6 +28,7 @@ import java.io.Reader; import java.io.StringReader; import java.io.UncheckedIOException; +import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -140,7 +141,7 @@ public static Model getRawModel(MavenProject project) throws IOException { * @throws IOException if the file is not found or if the file does not parse. */ public static Model getRawModel(File moduleProjectFile) throws IOException { - try (Reader reader = Files.newBufferedReader(moduleProjectFile.toPath())) { + try (Reader reader = Files.newBufferedReader(moduleProjectFile.toPath(), Charset.defaultCharset())) { Model result = getRawModel(reader); result.setPomFile(moduleProjectFile); return result; diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java index 6a49029e82..3bd45df37d 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.Reader; +import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.stream.Stream; @@ -50,7 +51,7 @@ public static Stream getCoreExtensions(MavenProject project) throws I return Stream.empty(); } - try (Reader reader = Files.newBufferedReader(extensionsFile)) { + try (Reader reader = Files.newBufferedReader(extensionsFile, Charset.defaultCharset())) { return new CoreExtensionsXpp3Reader() .read(reader).getExtensions().stream().map(ex -> ExtensionBuilder.newBuilder() .withGroupId(ex.getGroupId())