Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
}
}
}