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 2020/12/26 20:02:47 UTC
[maven-dependency-plugin] 01/01: replace code that relies on
default encoding
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-dependency-plugin.git
commit c6639fcda8b306ecc8bf635a48d3453d216f8dcb
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Sat Dec 26 15:02:30 2020 -0500
replace code that relies on default encoding
---
.../fromDependencies/BuildClasspathMojo.java | 15 +++++++----
.../plugins/dependency/utils/DependencyUtil.java | 30 ++++++++++++----------
2 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
index 223e725..8c8e670 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
@@ -22,10 +22,13 @@ package org.apache.maven.plugins.dependency.fromDependencies;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
@@ -333,7 +336,8 @@ public class BuildClasspathMojo
// make sure the parent path exists.
out.getParentFile().mkdirs();
- try ( Writer w = new BufferedWriter( new FileWriter( out ) ) )
+ try ( Writer w =
+ new BufferedWriter( new OutputStreamWriter( new FileOutputStream( out ), StandardCharsets.UTF_8 ) ) )
{
w.write( cpString );
getLog().info( "Wrote classpath file '" + out + "'." );
@@ -346,7 +350,7 @@ public class BuildClasspathMojo
}
/**
- * Reads into a string the file specified by the mojo param 'outputFile'. Assumes, the instance variable
+ * Reads into a string the file specified by the mojo param 'outputFile'. Assumes the field
* 'outputFile' is not null.
*
* @return the string contained in the classpathFile, if it exists, or null otherwise
@@ -366,7 +370,8 @@ public class BuildClasspathMojo
return null;
}
StringBuilder sb = new StringBuilder();
- try ( BufferedReader r = new BufferedReader( new FileReader( outputFile ) ) )
+ try ( BufferedReader r =
+ new BufferedReader( new InputStreamReader( new FileInputStream( outputFile ), StandardCharsets.UTF_8 ) ) )
{
for ( String line = r.readLine(); line != null; line = r.readLine() )
{
diff --git a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java
index eacedbf..9119524 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java
@@ -21,9 +21,12 @@ package org.apache.maven.plugins.dependency.utils;
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.StringReader;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
import java.util.Objects;
import org.apache.maven.artifact.Artifact;
@@ -32,7 +35,7 @@ import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.util.StringUtils;
/**
- * Utility class with static helper methods
+ * Utility class with static helper methods.
*
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
* @version $Id$
@@ -71,13 +74,13 @@ public final class DependencyUtil
/**
* Builds the file name. If removeVersion is set, then the file name must be reconstructed from the groupId (if
- * <b>prependGroupId</b> is true) artifactId, Classifier (if used) and Type. Otherwise, this method returns the
+ * <b>prependGroupId</b> is true) artifactId, Classifier (if used), and Type. Otherwise, this method returns the
* artifact file name.
*
- * @param artifact File to be formatted.
- * @param removeVersion Specifies if the version should be removed from the file name.
- * @param prependGroupId Specifies if the groupId should be prepended to the file name.
- * @param useBaseVersion Specifies if the baseVersion of the artifact should be used instead of the version.
+ * @param artifact file to be formatted
+ * @param removeVersion Specifies if the version should be removed from the file name
+ * @param prependGroupId Specifies if the groupId should be prepended to the file name
+ * @param useBaseVersion Specifies if the baseVersion of the artifact should be used instead of the version
* @return Formatted file name in the format [groupId].artifactId-[version]-[classifier].[type]
*/
public static String getFormattedFileName( Artifact artifact, boolean removeVersion, boolean prependGroupId,
@@ -219,8 +222,8 @@ public final class DependencyUtil
*
* @param string the string to write
* @param file the file to write to
- * @param append append to existing file or not.
- * @param log where to send the logging output.
+ * @param append append to existing file or not
+ * @param log ignored
* @throws IOException if an I/O error occurs
*/
public static synchronized void write( String string, File file, boolean append, Log log )
@@ -228,7 +231,7 @@ public final class DependencyUtil
{
file.getParentFile().mkdirs();
- try ( FileWriter writer = new FileWriter( file, append ) )
+ try ( Writer writer = new OutputStreamWriter( new FileOutputStream( file, append ), StandardCharsets.UTF_8 ) )
{
writer.write( string );
}
@@ -257,9 +260,10 @@ public final class DependencyUtil
}
/**
- * mainly used to parse excludes,includes configuration
- * @param str The string to be split.
- * @return The result items.
+ * Mainly used to parse excludes, includes configuration.
+ *
+ * @param str the string to split
+ * @return the result items
*/
public static String[] tokenizer( String str )
{