Class ClosureJavaScriptCompressor
- java.lang.Object
-
- com.googlecode.htmlcompressor.compressor.ClosureJavaScriptCompressor
-
- All Implemented Interfaces:
Compressor
public class ClosureJavaScriptCompressor extends Object implements Compressor
Basic JavaScript compressor implementation using Google Closure Compiler that could be used byHtmlCompressorfor inline JavaScript compression.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCOMPILATION_LEVEL_ADVANCEDThe Constant COMPILATION_LEVEL_ADVANCED.static StringCOMPILATION_LEVEL_SIMPLEThe Constant COMPILATION_LEVEL_SIMPLE.static StringCOMPILATION_LEVEL_WHITESPACEThe Constant COMPILATION_LEVEL_WHITESPACE.
-
Constructor Summary
Constructors Constructor Description ClosureJavaScriptCompressor()Instantiates a new closure java script compressor.ClosureJavaScriptCompressor(com.google.javascript.jscomp.CompilationLevel compilationLevel)Instantiates a new closure java script compressor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringcompress(String source)The main method that compresses the given source and returns a compressed result.com.google.javascript.jscomp.CompilationLevelgetCompilationLevel()Returns level of optimization that is applied when compiling JavaScript code.com.google.javascript.jscomp.CompilerOptionsgetCompilerOptions()Returns options that are used by the Closure compiler.List<com.google.javascript.jscomp.SourceFile>getExterns()ReturnsSourceFileused as a reference during the compression atCompilationLevel.ADVANCED_OPTIMIZATIONSlevel.LevelgetLoggingLevel()Returns logging level used by the Closure compiler.com.google.javascript.jscomp.WarningLevelgetWarningLevel()ReturnsWarningLevelused by the Closure compiler.booleanisCustomExternsOnly()Returnstrueif default externs defined inside Closure's jar are ignored and only user defined ones are used.voidsetCompilationLevel(com.google.javascript.jscomp.CompilationLevel compilationLevel)Sets level of optimization that should be applied when compiling JavaScript code.voidsetCompilerOptions(com.google.javascript.jscomp.CompilerOptions compilerOptions)Sets options that will be used by the Closure compiler.voidsetCustomExternsOnly(boolean customExternsOnly)If set totrue, default externs defined inside Closure's jar will be ignored and only user defined ones will be used.voidsetExterns(List<com.google.javascript.jscomp.SourceFile> externs)Sets external JavaScript files that are used as a reference for function declarations ifCompilationLevel.ADVANCED_OPTIMIZATIONScompression level is used.voidsetLoggingLevel(Level loggingLevel)Sets logging level for the Closure compiler.voidsetWarningLevel(com.google.javascript.jscomp.WarningLevel warningLevel)Indicates the amount of information you want from the compiler about possible problems in your code.
-
-
-
Field Detail
-
COMPILATION_LEVEL_SIMPLE
public static final String COMPILATION_LEVEL_SIMPLE
The Constant COMPILATION_LEVEL_SIMPLE.- See Also:
- Constant Field Values
-
COMPILATION_LEVEL_ADVANCED
public static final String COMPILATION_LEVEL_ADVANCED
The Constant COMPILATION_LEVEL_ADVANCED.- See Also:
- Constant Field Values
-
COMPILATION_LEVEL_WHITESPACE
public static final String COMPILATION_LEVEL_WHITESPACE
The Constant COMPILATION_LEVEL_WHITESPACE.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ClosureJavaScriptCompressor
public ClosureJavaScriptCompressor()
Instantiates a new closure java script compressor.
-
ClosureJavaScriptCompressor
public ClosureJavaScriptCompressor(com.google.javascript.jscomp.CompilationLevel compilationLevel)
Instantiates a new closure java script compressor.- Parameters:
compilationLevel- the compilation level
-
-
Method Detail
-
compress
public String compress(String source)
Description copied from interface:CompressorThe main method that compresses the given source and returns a compressed result.- Specified by:
compressin interfaceCompressor- Parameters:
source- The source to compress.- Returns:
- Compressed result.
-
getCompilationLevel
public com.google.javascript.jscomp.CompilationLevel getCompilationLevel()
Returns level of optimization that is applied when compiling JavaScript code.- Returns:
CompilationLevelthat is applied when compiling JavaScript code.- See Also:
- CompilationLevel
-
setCompilationLevel
public void setCompilationLevel(com.google.javascript.jscomp.CompilationLevel compilationLevel)
Sets level of optimization that should be applied when compiling JavaScript code. If none is provided,CompilationLevel.SIMPLE_OPTIMIZATIONSwill be used by default.Warning: Using
CompilationLevel.ADVANCED_OPTIMIZATIONScould break inline JavaScript if externs are not set properly.- Parameters:
compilationLevel- Optimization level to use, could be set toCompilationLevel.ADVANCED_OPTIMIZATIONS,CompilationLevel.SIMPLE_OPTIMIZATIONS,CompilationLevel.WHITESPACE_ONLY- See Also:
- Advanced Compilation and Externs, Closure Compiler Compilation Levels, CompilationLevel
-
getCompilerOptions
public com.google.javascript.jscomp.CompilerOptions getCompilerOptions()
Returns options that are used by the Closure compiler.- Returns:
CompilerOptionsthat are used by the compiler- See Also:
- CompilerOptions
-
setCompilerOptions
public void setCompilerOptions(com.google.javascript.jscomp.CompilerOptions compilerOptions)
Sets options that will be used by the Closure compiler. If none is provided, default options constructor will be used:new CompilerOptions().- Parameters:
compilerOptions-CompilerOptionsthat will be used by the compiler- See Also:
- CompilerOptions
-
getLoggingLevel
public Level getLoggingLevel()
Returns logging level used by the Closure compiler.- Returns:
Levelof logging used by the Closure compiler
-
setLoggingLevel
public void setLoggingLevel(Level loggingLevel)
Sets logging level for the Closure compiler.- Parameters:
loggingLevel- logging level for the Closure compiler.- See Also:
Level
-
getExterns
public List<com.google.javascript.jscomp.SourceFile> getExterns()
ReturnsSourceFileused as a reference during the compression atCompilationLevel.ADVANCED_OPTIMIZATIONSlevel.- Returns:
SourceFileused as a reference during compression
-
setExterns
public void setExterns(List<com.google.javascript.jscomp.SourceFile> externs)
Sets external JavaScript files that are used as a reference for function declarations ifCompilationLevel.ADVANCED_OPTIMIZATIONScompression level is used.A number of default externs defined inside Closure's jar will be used besides user defined ones, to use only user defined externs set
setCustomExternsOnly(true)Warning: Using
CompilationLevel.ADVANCED_OPTIMIZATIONScould break inline JavaScript if externs are not set properly.- Parameters:
externs-SourceFileto use as a reference during compression- See Also:
setCompilationLevel(CompilationLevel),setCustomExternsOnly(boolean), Advanced Compilation and Externs, SourceFile
-
getWarningLevel
public com.google.javascript.jscomp.WarningLevel getWarningLevel()
ReturnsWarningLevelused by the Closure compiler.- Returns:
WarningLevelused by the Closure compiler
-
setWarningLevel
public void setWarningLevel(com.google.javascript.jscomp.WarningLevel warningLevel)
Indicates the amount of information you want from the compiler about possible problems in your code.- Parameters:
warningLevel-WarningLevelto use- See Also:
- Google Closure Compiler
-
isCustomExternsOnly
public boolean isCustomExternsOnly()
Returnstrueif default externs defined inside Closure's jar are ignored and only user defined ones are used.- Returns:
trueif default externs defined inside Closure's jar are ignored and only user defined ones are used
-
setCustomExternsOnly
public void setCustomExternsOnly(boolean customExternsOnly)
If set totrue, default externs defined inside Closure's jar will be ignored and only user defined ones will be used.- Parameters:
customExternsOnly-trueto skip default externs and use only user defined ones- See Also:
setExterns(List),setCompilationLevel(CompilationLevel)
-
-