asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Blow (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: Read & Write License Files As UTF-8
Date Sat, 11 Mar 2017 13:54:13 GMT
Michael Blow has submitted this change and it was merged.

Change subject: Read & Write License Files As UTF-8
......................................................................


Read & Write License Files As UTF-8

Change-Id: I167fbcf4cb913dc00ebdb84b406397ee412b4f1e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1570
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
---
M hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/DownloadLicensesMojo.java
M hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/GenerateFileMojo.java
M hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseUtil.java
M hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/SupplementalModelHelper.java
M hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/freemarker/LoadFileDirective.java
5 files changed, 32 insertions(+), 16 deletions(-)

Approvals:
  Ian Maxon: Looks good to me, approved
  Jenkins: Verified; No violations found; No violations found; Verified



diff --git a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/DownloadLicensesMojo.java
b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/DownloadLicensesMojo.java
index 8219dfc..7d0e77d 100644
--- a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/DownloadLicensesMojo.java
+++ b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/DownloadLicensesMojo.java
@@ -19,11 +19,14 @@
 package org.apache.hyracks.maven.license;
 
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -77,9 +80,10 @@
             final File outFile = new File(downloadDir, fileName);
             getLog().info("[" + id + "] " + url + " -> " + outFile);
             final InputStream is = conn.getInputStream();
-            FileWriter writer = new FileWriter(outFile);
-            IOUtils.copy(is, writer, conn.getContentEncoding());
-            writer.close();
+            try (FileOutputStream fos = new FileOutputStream(outFile);
+                    Writer writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8))
{
+                IOUtils.copy(is, writer, conn.getContentEncoding());
+            }
             getLog().info("[" + id + "] ...done!");
         } catch (IOException e) {
             getLog().warn("[" + id + "] ...error downloading " + url + ": " + e);
diff --git a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/GenerateFileMojo.java
b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/GenerateFileMojo.java
index 262979a..387d18e 100644
--- a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/GenerateFileMojo.java
+++ b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/GenerateFileMojo.java
@@ -19,9 +19,11 @@
 package org.apache.hyracks.maven.license;
 
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.io.StringWriter;
+import java.io.Writer;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Comparator;
@@ -175,7 +177,7 @@
         Configuration config = new Configuration();
         config.setTemplateLoader(new FileTemplateLoader(templateRootDir));
         for (GeneratedFile generation : generatedFiles) {
-            Template template = config.getTemplate(generation.getTemplate());
+            Template template = config.getTemplate(generation.getTemplate(), StandardCharsets.UTF_8.name());
 
             if (template == null) {
                 throw new IOException("Could not load template " + generation.getTemplate());
@@ -184,7 +186,8 @@
             outputDir.mkdirs();
             final File file = new File(outputDir, generation.getOutputFile());
             getLog().info("Writing " + file + "...");
-            try (final FileWriter writer = new FileWriter(file)) {
+            try (final FileOutputStream fos = new FileOutputStream(file);
+                    final Writer writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8))
{
                 template.process(props, writer);
             }
         }
diff --git a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseUtil.java
b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseUtil.java
index 8983160..30588d4 100644
--- a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseUtil.java
+++ b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/LicenseUtil.java
@@ -20,11 +20,13 @@
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
@@ -65,7 +67,8 @@
     }
 
     public static void readAndTrim(Writer out, File file) throws IOException {
-        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
+        try (FileInputStream fis = new FileInputStream(file);
+                BufferedReader reader = new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8)))
{
             reader.mark((int) file.length() * 2);
             trim(out, reader);
         }
diff --git a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/SupplementalModelHelper.java
b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/SupplementalModelHelper.java
index 5ba525a..7f33b46 100644
--- a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/SupplementalModelHelper.java
+++ b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/SupplementalModelHelper.java
@@ -19,8 +19,10 @@
 package org.apache.hyracks.maven.license;
 
 import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -73,8 +75,10 @@
                 log.debug("Loading supplemental models from " + f.getAbsolutePath());
 
                 SupplementalDataModelXpp3Reader reader = new SupplementalDataModelXpp3Reader();
-                SupplementalDataModel supplementalModel = reader.read(new FileReader(f));
-                supplements.addAll(supplementalModel.getSupplement());
+                try (FileInputStream fis = new FileInputStream(f); Reader fileReader = new
InputStreamReader(fis)) {
+                    SupplementalDataModel supplementalModel = reader.read(fileReader);
+                    supplements.addAll(supplementalModel.getSupplement());
+                }
             } catch (Exception e) {
                 String msg = "Error loading supplemental data models: " + e.getMessage();
                 log.error(msg, e);
diff --git a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/freemarker/LoadFileDirective.java
b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/freemarker/LoadFileDirective.java
index 61d84f1..67da23f 100644
--- a/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/freemarker/LoadFileDirective.java
+++ b/hyracks-fullstack/hyracks/hyracks-maven-plugins/license-automation-plugin/src/main/java/org/apache/hyracks/maven/license/freemarker/LoadFileDirective.java
@@ -19,10 +19,14 @@
 package org.apache.hyracks.maven.license.freemarker;
 
 import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.Writer;
+import java.nio.charset.StandardCharsets;
 import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.hyracks.maven.license.LicenseUtil;
 
 import freemarker.cache.FileTemplateLoader;
 import freemarker.core.Environment;
@@ -34,8 +38,6 @@
 import freemarker.template.TemplateModel;
 import freemarker.template.TemplateModelException;
 import freemarker.template.TemplateScalarModel;
-import org.apache.hyracks.maven.license.LicenseUtil;
-import org.apache.commons.io.IOUtils;
 
 public class LoadFileDirective implements TemplateDirectiveModel {
 
@@ -104,7 +106,7 @@
                 LicenseUtil.readAndTrim(out, file);
                 out.write('\n');
             } else {
-                IOUtils.copy(new FileReader(file), out);
+                IOUtils.copy(new FileInputStream(file), out, StandardCharsets.UTF_8);
             }
         } else if (defaultParam != null ) {
             out.append(defaultParam).append("\n");

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1570
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I167fbcf4cb913dc00ebdb84b406397ee412b4f1e
Gerrit-PatchSet: 2
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mblow@apache.org>
Gerrit-Reviewer: Ian Maxon <imaxon@apache.org>
Gerrit-Reviewer: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Michael Blow <mblow@apache.org>
Gerrit-Reviewer: Till Westmann <tillw@apache.org>

Mime
View raw message