private void writeResult(String source) {
if (this.outputFile.getParentFile().mkdirs()) {
log("Created missing parent directory " +
this.outputFile.getParentFile(), Project.MSG_DEBUG);
}
try (OutputStreamWriter out =
new OutputStreamWriter(new FileOutputStream(this.outputFile), outputEncoding)) {
out.append(source);
} catch (IOException e) {
throw new BuildException(e);
}
log("Compiled JavaScript written to " + this.outputFile.getAbsolutePath(),
Project.MSG_DEBUG);
}
/**
* Determine if compilation must actually happen, i.e. if any input file
* (extern or source) has changed after the outputFile was last modified.
*
* @return true if compilation should happen
*/
private boolean isStale() {
long lastRun = outputFile.lastModified();
long sourcesLastModified = Math.max(
getLastModifiedTime(this.sourceFileLists),
getLastModifiedTime(this.sourcePaths));
long externsLastModified = getLastModifiedTime(this.externFileLists);
return lastRun <= sourcesLastModified || lastRun <= externsLastModified;
}