ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gin...@apache.org
Subject [2/5] ant-ivy git commit: Use StandardCharsets
Date Fri, 03 Aug 2018 12:10:03 GMT
Use StandardCharsets

Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/b5b177b8
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/b5b177b8
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/b5b177b8

Branch: refs/heads/master
Commit: b5b177b84d6e02fe88054699b6e2c2dca2852289
Parents: d67de45
Author: Gintas Grigelionis <gintas@apache.org>
Authored: Fri Aug 3 12:20:40 2018 +0200
Committer: Gintas Grigelionis <gintas@apache.org>
Committed: Fri Aug 3 12:20:40 2018 +0200

----------------------------------------------------------------------
 .../apache/ivy/core/cache/DefaultRepositoryCacheManager.java | 8 ++------
 src/java/org/apache/ivy/osgi/core/ManifestParser.java        | 3 ++-
 .../ivy/plugins/parser/m2/PomModuleDescriptorWriter.java     | 3 ++-
 src/java/org/apache/ivy/plugins/parser/m2/PomReader.java     | 3 ++-
 .../ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java   | 3 ++-
 .../ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java    | 3 ++-
 .../ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java | 6 +++---
 7 files changed, 15 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b5b177b8/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java b/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
index b85e9a8..540cf92 100644
--- a/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
+++ b/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.text.ParseException;
@@ -1188,12 +1189,7 @@ public class DefaultRepositoryCacheManager implements RepositoryCacheManager,
Iv
      * @return the hash
      */
     private String computeResourceNameHash(Resource resource) {
-        try {
-            byte[] shaDigest = SHA_DIGEST.digest(resource.getName().getBytes("UTF-8"));
-            return HexEncoder.encode(shaDigest);
-        } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException("UTF-8 not supported", e);
-        }
+        return HexEncoder.encode(SHA_DIGEST.digest(resource.getName().getBytes(StandardCharsets.UTF_8)));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b5b177b8/src/java/org/apache/ivy/osgi/core/ManifestParser.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/osgi/core/ManifestParser.java b/src/java/org/apache/ivy/osgi/core/ManifestParser.java
index 5192ecd..ee8e3ce 100644
--- a/src/java/org/apache/ivy/osgi/core/ManifestParser.java
+++ b/src/java/org/apache/ivy/osgi/core/ManifestParser.java
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.text.ParseException;
 import java.util.List;
 import java.util.jar.Attributes;
@@ -93,7 +94,7 @@ public class ManifestParser {
     }
 
     public static BundleInfo parseManifest(String manifest) throws IOException, ParseException
{
-        ByteArrayInputStream bais = new ByteArrayInputStream(manifest.getBytes("UTF-8"));
+        ByteArrayInputStream bais = new ByteArrayInputStream(manifest.getBytes(StandardCharsets.UTF_8));
         BundleInfo parseManifest = parseManifest(bais);
         bais.close();
         return parseManifest;

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b5b177b8/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
index e53bda7..bea105a 100644
--- a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
+++ b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
@@ -25,6 +25,7 @@ import java.io.InputStreamReader;
 import java.io.LineNumberReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -82,7 +83,7 @@ public final class PomModuleDescriptorWriter {
             output.getParentFile().mkdirs();
         }
         PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output),
-                "UTF-8"));
+                StandardCharsets.UTF_8));
         try {
             IvySettings settings = IvyContext.getContext().getSettings();
             IvyVariableContainer variables = new IvyVariableContainerWrapper(

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b5b177b8/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java b/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
index 4aeeb23..95af142 100644
--- a/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
+++ b/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
@@ -41,6 +41,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.LineNumberReader;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -798,7 +799,7 @@ public class PomReader {
             }
 
             int bytesToSkip = 0;
-            LineNumberReader reader = new LineNumberReader(new InputStreamReader(this.in,
"UTF-8"),
+            LineNumberReader reader = new LineNumberReader(new InputStreamReader(this.in,
StandardCharsets.UTF_8),
                     100);
             String firstLine = reader.readLine();
             if (firstLine != null) {

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b5b177b8/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
index bd8b180..8bab430 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
@@ -27,6 +27,7 @@ import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -1281,7 +1282,7 @@ public final class XmlModuleDescriptorUpdater {
 
     public static void update(URL inStreamCtx, InputStream inStream, OutputStream outStream,
             final UpdateOptions options) throws IOException, SAXException {
-        final PrintWriter out = new PrintWriter(new OutputStreamWriter(outStream, "UTF-8"));
+        final PrintWriter out = new PrintWriter(new OutputStreamWriter(outStream, StandardCharsets.UTF_8));
         out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
         out.write(LINE_SEPARATOR);
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b5b177b8/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
index bac3180..a40f2bc 100644
--- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
+++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
@@ -22,6 +22,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Map;
 
@@ -68,7 +69,7 @@ public final class XmlModuleDescriptorWriter {
             output.getParentFile().mkdirs();
         }
         try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output),
-                "UTF-8"))) {
+                StandardCharsets.UTF_8))) {
             out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
             if (licenseHeader != null) {
                 out.print(licenseHeader);

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/b5b177b8/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
b/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
index 656b154..2a98b62 100644
--- a/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
+++ b/test/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParserTest.java
@@ -26,7 +26,7 @@ import static org.junit.Assert.fail;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -1101,14 +1101,14 @@ public class PomModuleDescriptorParserTest extends AbstractModuleDescriptorParse
         final String envName = chooseSomeEnvVar();
         final URL originalPomFile = this.getClass().getResource("test-system-properties.pom");
         assertNotNull("Pom file to test, is missing", originalPomFile);
-        final List<String> pomContent = Files.readAllLines(Paths.get(originalPomFile.toURI()),
Charset.forName("UTF-8"));
+        final List<String> pomContent = Files.readAllLines(Paths.get(originalPomFile.toURI()),
StandardCharsets.UTF_8);
         final List<String> replacedContent = new ArrayList<>();
         for (final String line : pomContent) {
             replacedContent.add(line.replaceAll("THIS_WILL_BE_REPLACED_IN_TEST_BY_A_ENV_VAR",
envName));
         }
         // write the new pom contents into a separate file
         final Path updatedPomFile = Paths.get(workDir.getRoot().toPath().toString(), "updated-test-system-properties.pom");
-        Files.write(updatedPomFile, replacedContent, Charset.forName("UTF-8"));
+        Files.write(updatedPomFile, replacedContent, StandardCharsets.UTF_8);
 
         // now start testing - we do 2 rounds -
         // once with a system property (referenced in the pom) set and once unset


Mime
View raw message