@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) 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); } }
@Override public String toString() { final StringBuilder builder = new StringBuilder("less4j errors while generating '" + name + "':\n"); for (LessCompiler.Problem error : e.getErrors()) { builder.append(" > [").append(error.getType()).append("] ") .append(error.getMessage()) .append(" in line ").append(error.getLine()) .append(":").append(error.getCharacter()).append("\n"); } return builder.toString(); } }
@Override public InputStream open(String s, URLConnection resource) throws IOException { LessCompiler compiler = new ThreadUnsafeLessCompiler(); try { LessCompiler.CompilationResult result = compiler.compile(resource.getURL()); return new ByteArrayInputStream(result.getCss().getBytes()); } catch (Less4jException e) { List<LessCompiler.Problem> errors = e.getErrors(); ArrayList<Message> messages = new ArrayList<Message>(errors.size()); for (LessCompiler.Problem error : errors) { String text = error.getMessage() != null ? error.getMessage() : "There is an error in your .less file"; String errorName = error.getType().name(); LessSource source = error.getSource(); Message msg; if (source != null) { msg = new Message(MetaModelPluginImpl.COMPILATION_ERROR, errorName, source.getName(), error.getLine(), text); } else { msg = new Message(MetaModelPluginImpl.GENERAL_PROBLEM, errorName, text); } MetaModelPluginImpl.log.info(msg.toDisplayString()); messages.add(msg); } throw new ProcessingException(messages); } } }
@Override public InputStream open(String s, URLConnection resource) throws IOException { LessCompiler compiler = new ThreadUnsafeLessCompiler(); try { LessCompiler.CompilationResult result = compiler.compile(resource.getURL()); return new ByteArrayInputStream(result.getCss().getBytes()); } catch (Less4jException e) { List<LessCompiler.Problem> errors = e.getErrors(); ArrayList<Message> messages = new ArrayList<Message>(errors.size()); for (LessCompiler.Problem error : errors) { String text = error.getMessage() != null ? error.getMessage() : "There is an error in your .less file"; String errorName = error.getType().name(); LessSource source = error.getSource(); Message msg; if (source != null) { msg = new Message(MetaModelPluginImpl.COMPILATION_ERROR, errorName, source.getName(), error.getLine(), text); } else { msg = new Message(MetaModelPluginImpl.GENERAL_PROBLEM, errorName, text); } MetaModelPluginImpl.log.info(msg.toDisplayString()); messages.add(msg); } throw new ProcessingException(messages); } } }