use of com.google.javascript.jscomp.BasicErrorManager in project structr by structr.
the class MinifiedJavaScriptFile method minify.
static void minify(final MinifiedJavaScriptFile thisFile) throws FrameworkException, IOException {
logger.info("Running minify: {}", thisFile.getUuid());
final com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
final SecurityContext securityContext = thisFile.getSecurityContext();
final CompilerOptions options = new CompilerOptions();
final CompilationLevel selectedLevel = CompilationLevel.valueOf(thisFile.getOptimizationLevel());
selectedLevel.setOptionsForCompilationLevel(options);
compiler.setErrorManager(new BasicErrorManager() {
@Override
public void println(final CheckLevel level, final JSError error) {
}
@Override
protected void printSummary() {
if (getTypedPercent() > 0) {
if (getErrorCount() + getWarningCount() == 0) {
logger.info(SimpleFormat.format("%d error(s), %d warning(s), %.1f%% typed", getErrorCount(), getWarningCount(), getTypedPercent()));
} else {
logger.warn(SimpleFormat.format("%d error(s), %d warning(s), %.1f%% typed", getErrorCount(), getWarningCount(), getTypedPercent()));
}
} else if (getErrorCount() + getWarningCount() > 0) {
logger.warn(SimpleFormat.format("%d error(s), %d warning(s)", getErrorCount(), getWarningCount()));
}
}
});
compiler.compile(CommandLineRunner.getBuiltinExterns(options.getEnvironment()), MinifiedJavaScriptFile.getSourceFileList(thisFile), options);
FileHelper.setFileData(thisFile, compiler.toSource().getBytes(), thisFile.getContentType());
final PropertyMap changedProperties = new PropertyMap();
changedProperties.put(StructrApp.key(MinifiedJavaScriptFile.class, "warnings"), StringUtils.join(compiler.getWarnings(), System.lineSeparator()));
changedProperties.put(StructrApp.key(MinifiedJavaScriptFile.class, "errors"), StringUtils.join(compiler.getErrors(), System.lineSeparator()));
thisFile.setProperties(securityContext, changedProperties);
}
Aggregations