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..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,8 @@ 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; import java.util.Map; @@ -153,9 +155,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 +184,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(), StandardCharsets.UTF_8)) { 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; } } }