From 57c4e385dbefe5cb65f82b3b411ebbeabced8989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Sj=C3=B6berg?= Date: Fri, 28 Jul 2017 15:46:46 -0500 Subject: [PATCH 1/2] Write source mapping files even if they already exist. --- .../maven/minify/plugin/ProcessJSFilesTask.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/samaxes/maven/minify/plugin/ProcessJSFilesTask.java b/src/main/java/com/samaxes/maven/minify/plugin/ProcessJSFilesTask.java index 7407ad89..4e406179 100644 --- a/src/main/java/com/samaxes/maven/minify/plugin/ProcessJSFilesTask.java +++ b/src/main/java/com/samaxes/maven/minify/plugin/ProcessJSFilesTask.java @@ -30,6 +30,7 @@ import java.io.*; import java.nio.charset.Charset; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -153,9 +154,7 @@ protected void minify(File mergedFile, File minifiedFile) throws IOException { log.info("Creating the minified file map [" + (verbose ? sourceMapResult.getPath() : sourceMapResult.getName()) + "]."); - if (sourceMapResult.createNewFile()) { - flushSourceMap(sourceMapResult, minifiedFile.getName(), compiler.getSourceMap()); - + if (flushSourceMap(sourceMapResult, minifiedFile.getName(), compiler.getSourceMap())) { writer.append(System.getProperty("line.separator")); writer.append("//# sourceMappingURL=").append(sourceMapResult.getName()); } @@ -184,12 +183,14 @@ protected void minify(File mergedFile, File minifiedFile) throws IOException { logCompressionGains(mergedFile, minifiedFile); } - private void flushSourceMap(File sourceMapOutputFile, String minifyFileName, SourceMap sourceMap) { - try (FileWriter out = new FileWriter(sourceMapOutputFile)) { + private boolean flushSourceMap(File sourceMapOutputFile, String minifyFileName, SourceMap sourceMap) { + try (BufferedWriter out = Files.newBufferedWriter(sourceMapOutputFile.toPath())) { sourceMap.appendTo(out, minifyFileName); + return true; } catch (IOException e) { log.error("Failed to write the JavaScript Source Map file [" + (verbose ? sourceMapOutputFile.getPath() : sourceMapOutputFile.getName()) + "].", e); + return false; } } } From 25194b93be72c9ec6064410d1eb822cb4e8586c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Sj=C3=B6berg?= Date: Fri, 28 Jul 2017 16:00:08 -0500 Subject: [PATCH 2/2] Use Java 1.7 API. --- .../com/samaxes/maven/minify/plugin/ProcessJSFilesTask.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/samaxes/maven/minify/plugin/ProcessJSFilesTask.java b/src/main/java/com/samaxes/maven/minify/plugin/ProcessJSFilesTask.java index 4e406179..23a0419d 100644 --- a/src/main/java/com/samaxes/maven/minify/plugin/ProcessJSFilesTask.java +++ b/src/main/java/com/samaxes/maven/minify/plugin/ProcessJSFilesTask.java @@ -30,6 +30,7 @@ import java.io.*; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; import java.util.List; @@ -184,7 +185,7 @@ protected void minify(File mergedFile, File minifiedFile) throws IOException { } private boolean flushSourceMap(File sourceMapOutputFile, String minifyFileName, SourceMap sourceMap) { - try (BufferedWriter out = Files.newBufferedWriter(sourceMapOutputFile.toPath())) { + try (BufferedWriter out = Files.newBufferedWriter(sourceMapOutputFile.toPath(), StandardCharsets.UTF_8)) { sourceMap.appendTo(out, minifyFileName); return true; } catch (IOException e) {