use of org.xwiki.lesscss.internal.compiler.DefaultLESSCompiler in project xwiki-platform by xwiki.
the class AbstractCachedCompiler method getResult.
/**
* Get the result of the compilation.
* @param lessResourceReference reference to the LESS content
* @param includeSkinStyle include the main LESS file of the skin in order to have variables and mix-ins
* defined there
* @param useVelocity either or not the resource be parsed by Velocity before compiling it
* @param force force the computation, even if the output is already in the cache (not recommended)
* @param skin name of the skin used for the context
* @return the desired object
* @throws LESSCompilerException if problems occur
*/
public T getResult(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity, String skin, boolean force) throws LESSCompilerException {
// If the cache is disabled, we just compile
if (lessContext.isCacheDisabled()) {
return compiler.compute(lessResourceReference, includeSkinStyle, useVelocity, true, skin);
}
T result = null;
SkinReference skinReference = skinReferenceFactory.createReference(skin);
ColorThemeReference colorThemeReference = colorThemeReferenceFactory.createReference(currentColorThemeGetter.getCurrentColorTheme(true, "default"));
// Only one computation is allowed in the same time per color theme, then the waiting threads will be able to
// use the last result stored in the cache.
Object mutex = cache.getMutex(lessResourceReference, skinReference, colorThemeReference);
synchronized (mutex) {
// Check if the result is in the cache
if (!force) {
result = cache.get(lessResourceReference, skinReference, colorThemeReference);
if (result != null) {
// we only do the Velocity Execution step.
if (lessContext.isHtmlExport() && useVelocity && this instanceof DefaultLESSCompiler) {
compiler.compute(lessResourceReference, includeSkinStyle, true, false, skin);
}
return cloneResult(result);
}
}
// Either the result was in the cache or the force flag is set to true, we need to compile
try {
result = compiler.compute(lessResourceReference, includeSkinStyle, useVelocity, true, skin);
} catch (LESSCompilerException e) {
logger.error("Error during the compilation of the resource [{}].", lessResourceReference, e);
// We must cache the result, even if the compilation have failed, to prevent re-compiling again and
// again (the compilation will still fail until the LESS resource is updated so it useless to retry).
result = exceptionAsResult(e);
} finally {
// Put the result in the cache
cache.set(lessResourceReference, skinReference, colorThemeReference, result);
}
}
return cloneResult(result);
}
Aggregations