Package org.ametys.core.minimize.js
Class MinimizeJSManager
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.core.minimize.AbstractMinimizeManager
-
- org.ametys.core.minimize.js.MinimizeJSManager
-
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
public class MinimizeJSManager extends AbstractMinimizeManager implements Component
Manager for JS minimization and source map generation
-
-
Field Summary
Fields Modifier and Type Field Description private static Pattern
__SOURCEMAP_FILE_NAME
private static Pattern
__SOURCEMAP_LINE
static String
ROLE
The avalon ROLE-
Fields inherited from class org.ametys.core.minimize.AbstractMinimizeManager
_proxiedContextPathProvider, _resolver, _sourceMapCache
-
-
Constructor Summary
Constructors Constructor Description MinimizeJSManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private com.google.javascript.jscomp.Compiler
_minimizeJS(String code, String fileName, boolean withSourceMap)
protected void
addSourceMap(com.google.debugging.sourcemap.SourceMapGeneratorV3 sourceMapGenerator, int lineCount, String fileContent, String fileUri, String sourceMapUri)
Aggregate the source map of the single file with the othersprotected String
formatSourceMappingURL(String sourceMapName)
Format a source mapping URL to be added at the end of a minimized fileString
generateJSSourceMap(String code, String location, String sourceMapKey, Long lastModified)
Minimize a JS string and return the source mapprotected String
getMinimizedContent(String uri, String nestedParentFilesName)
Get the minimized content at the specified URIprotected String
getSourceMappingURL(String line)
Get the source mapping URL value from the lineprotected boolean
isSourceMappingURLLine(String line)
Test if the line contains a source mapping URLString
minimizeJS(String code, String location)
Minimize a JS stringString
minimizeJS(String code, String location, String sourceMapKey, Long lastModified)
Minimize a JS stringprotected String
removeSourceMappingURLLine(String content)
Remove the source mapping url from the contentvoid
service(ServiceManager manager)
-
Methods inherited from class org.ametys.core.minimize.AbstractMinimizeManager
applyMediaToContent, convertSourceMapURIs, minimizeAndAggregateURIs, validateAndOutputMinimizedFile
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
__SOURCEMAP_FILE_NAME
private static final Pattern __SOURCEMAP_FILE_NAME
-
__SOURCEMAP_LINE
private static final Pattern __SOURCEMAP_LINE
-
-
Constructor Detail
-
MinimizeJSManager
public MinimizeJSManager()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractMinimizeManager
- Throws:
ServiceException
-
minimizeJS
public String minimizeJS(String code, String location) throws ProcessingException, IOException
Minimize a JS string- Parameters:
code
- The JS codelocation
- The JS location- Returns:
- The minimized JS
- Throws:
ProcessingException
- If an error occurred during minimizationIOException
- If an error occurred while retrieving the source map
-
minimizeJS
public String minimizeJS(String code, String location, String sourceMapKey, Long lastModified) throws IOException, ProcessingException
Minimize a JS string- Parameters:
code
- The JS codelocation
- The JS locationsourceMapKey
- The key to store the source map in cache. Can be null to prevent source map generationlastModified
- The last modified date of the code, used to assert validity of the source map cache. Can be null- Returns:
- The minimized JS
- Throws:
ProcessingException
- If an error occurred during minimizationIOException
- If an error occurred while retrieving the source map
-
generateJSSourceMap
public String generateJSSourceMap(String code, String location, String sourceMapKey, Long lastModified) throws ProcessingException, IOException
Minimize a JS string and return the source map- Parameters:
code
- The JS codelocation
- The JS locationsourceMapKey
- The key to store the source map in cachelastModified
- The last modified date of the code, used to assert validity of the source map cache- Returns:
- The minimized JS
- Throws:
ProcessingException
- If an error occurred during minimizationIOException
- If an error occurred while retrieving the source map
-
_minimizeJS
private com.google.javascript.jscomp.Compiler _minimizeJS(String code, String fileName, boolean withSourceMap) throws ProcessingException
- Throws:
ProcessingException
-
addSourceMap
protected void addSourceMap(com.google.debugging.sourcemap.SourceMapGeneratorV3 sourceMapGenerator, int lineCount, String fileContent, String fileUri, String sourceMapUri)
Description copied from class:AbstractMinimizeManager
Aggregate the source map of the single file with the others- Specified by:
addSourceMap
in classAbstractMinimizeManager
- Parameters:
sourceMapGenerator
- The aggregator helperlineCount
- The current line countfileContent
- The content of the filefileUri
- The uri of the filesourceMapUri
- The sourceMappingURL found at the end of the file content
-
getMinimizedContent
protected String getMinimizedContent(String uri, String nestedParentFilesName)
Description copied from class:AbstractMinimizeManager
Get the minimized content at the specified URI- Specified by:
getMinimizedContent
in classAbstractMinimizeManager
- Parameters:
uri
- The urinestedParentFilesName
- The parents file name, can be an empty string if there are no parents- Returns:
- The minimized content of the specified URI
-
isSourceMappingURLLine
protected boolean isSourceMappingURLLine(String line)
Description copied from class:AbstractMinimizeManager
Test if the line contains a source mapping URL- Specified by:
isSourceMappingURLLine
in classAbstractMinimizeManager
- Parameters:
line
- The line- Returns:
- True if a source mapping url is found
-
getSourceMappingURL
protected String getSourceMappingURL(String line)
Description copied from class:AbstractMinimizeManager
Get the source mapping URL value from the line- Specified by:
getSourceMappingURL
in classAbstractMinimizeManager
- Parameters:
line
- The line- Returns:
- The source mapping URL
-
removeSourceMappingURLLine
protected String removeSourceMappingURLLine(String content)
Description copied from class:AbstractMinimizeManager
Remove the source mapping url from the content- Specified by:
removeSourceMappingURLLine
in classAbstractMinimizeManager
- Parameters:
content
- The content- Returns:
- The content without the mention of the source mapping URL
-
formatSourceMappingURL
protected String formatSourceMappingURL(String sourceMapName)
Description copied from class:AbstractMinimizeManager
Format a source mapping URL to be added at the end of a minimized file- Specified by:
formatSourceMappingURL
in classAbstractMinimizeManager
- Parameters:
sourceMapName
- The map name- Returns:
- The source mapping URL line
-
-