本文整理汇总了Java中com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler类的典型用法代码示例。如果您正苦于以下问题:Java ThreadUnsafeLessCompiler类的具体用法?Java ThreadUnsafeLessCompiler怎么用?Java ThreadUnsafeLessCompiler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThreadUnsafeLessCompiler类属于com.github.sommeri.less4j.core包,在下文中一共展示了ThreadUnsafeLessCompiler类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendResource
import com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler; //导入依赖的package包/类
@Override
protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException {
try {
// compile less to css
log.trace("Send css for '{}'", resourceUrl);
LessSource.URLSource source = new LessSource.URLSource(resourceUrl);
String content = source.getContent();
String result = sourceMap.get(content);
if (result == null) {
ThreadUnsafeLessCompiler compiler = new ThreadUnsafeLessCompiler();
LessCompiler.Configuration configuration = new LessCompiler.Configuration();
configuration.setCompressing(minify);
LessCompiler.CompilationResult compilationResult = compiler.compile(resourceUrl, configuration);
for (LessCompiler.Problem warning : compilationResult.getWarnings()) {
log.warn("Line: {}, Character: {}, Message: {} ", warning.getLine(), warning.getCharacter(), warning.getMessage());
}
result = compilationResult.getCss();
if (routeContext.getApplication().getPippoSettings().isProd()) {
sourceMap.put(content, result);
}
}
// send css
routeContext.getResponse().contentType("text/css");
routeContext.getResponse().ok().send(result);
} catch (Exception e) {
throw new PippoRuntimeException(e);
}
}
示例2: process
import com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler; //导入依赖的package包/类
@Override
public String process(final String filename, final String source, final Config conf)
throws Exception {
String path = filename;
try {
LessCompiler compiler = new ThreadUnsafeLessCompiler();
LessSource src = new LessStrSource(source, path);
CompilationResult result = compiler.compile(src, lessConf(conf));
result.getWarnings().forEach(warn -> {
log.warn("{}:{}:{}:{}: {}", path, warn.getType(), warn.getLine(),
warn.getCharacter(), warn.getMessage());
});
if (path.endsWith(".map")) {
return result.getSourceMap();
} else {
return result.getCss();
}
} catch (Less4jException ex) {
List<AssetProblem> problems = ex.getErrors().stream()
.map(it -> new AssetProblem(path, it.getLine(), it.getCharacter(), it.getMessage(), null))
.collect(Collectors.toList());
throw new AssetException(name(), problems);
}
}
示例3: getCompiledStylesheet
import com.github.sommeri.less4j.core.ThreadUnsafeLessCompiler; //导入依赖的package包/类
@Override
// If checkCacheInvalidation is true and, before invocation, a cached value exists and is not up to date, we evict the cache entry.
@CacheEvict(value = "lessCssService.compiledStylesheets",
key = "T(fr.openwide.core.wicket.more.css.lesscss.service.LessCssServiceImpl).getCacheKey(#lessInformation)",
beforeInvocation = true,
condition= "#checkCacheEntryUpToDate && !(caches.?[name=='lessCssService.compiledStylesheets'][0]?.get(T(fr.openwide.core.wicket.more.css.lesscss.service.LessCssServiceImpl).getCacheKey(#lessInformation))?.get()?.isUpToDate() ?: false)"
)
// THEN, we check if a cached value exists. If it does, it is returned ; if not, the method is called.
@Cacheable(value = "lessCssService.compiledStylesheets",
key = "T(fr.openwide.core.wicket.more.css.lesscss.service.LessCssServiceImpl).getCacheKey(#lessInformation)")
public LessCssStylesheetInformation getCompiledStylesheet(LessCssStylesheetInformation lessInformation, boolean checkCacheEntryUpToDate)
throws ServiceException {
prepareRawStylesheet(lessInformation);
try {
Configuration configuration = new Configuration();
if (propertyService != null && propertyService.isConfigurationTypeDevelopment()) {
// on insère inline une source map
// -> utile seulement si on a les outils adéquats pour l'exploiter
configuration.getSourceMapConfiguration().setInline(true);
} else {
// on n'insère aucune information sur l'emplacement des fichiers
configuration.getSourceMapConfiguration().setLinkSourceMap(false);
}
CompilationResult compilationResult = new ThreadUnsafeLessCompiler().compile(lessInformation.getSource(), configuration);
LessCssStylesheetInformation compiledStylesheet = new LessCssStylesheetInformation(
lessInformation, compilationResult.getCss()
);
List<Problem> warnings = compilationResult.getWarnings();
if (!CollectionUtils.isEmpty(warnings)) {
for (Problem warning : warnings) {
LOGGER.warn(formatLess4jProblem(warning));
}
}
return compiledStylesheet;
} catch (Less4jException e) {
List<Problem> errors = e.getErrors();
if (!CollectionUtils.isEmpty(errors)) {
for (Problem error : errors) {
LOGGER.error(formatLess4jProblem(error));
}
}
throw new ServiceException(String.format("Error compiling %1$s (scope: %2$s)",
lessInformation.getName(), lessInformation.getScope()), e);
}
}