@Override public void error(final String message, final String sourceName, final int line, final String lineSource, final int lineOffset) { throw new AssetException(name, ImmutableList.of(new AssetProblem(filename, line, lineOffset, message, null))); } };
@Override public String toString() { return (filename + ":" + line + ":" + column + ": " + message + "\n" + getEvidence()).trim(); } }
/** * Add a virtual/fake stacktrace element with the offending file, useful for whoops. * * @param ex Stack trace to rewrite. * @return Same exception with new stacktrace. */ private AssetException rewrite(final AssetException ex) { List<StackTraceElement> stacktrace = Lists.newArrayList(ex.getStackTrace()); List<AssetProblem> problems = ex.getProblems(); AssetProblem head = problems.get(0); stacktrace.add(0, new StackTraceElement(head.getFilename(), "", head.getFilename(), head.getLine())); ex.setStackTrace(stacktrace.toArray(new StackTraceElement[stacktrace.size()])); return ex; }
/** * @return Message of the first problem (useful for better error display on whoops). */ @Override public String get() { AssetProblem problem = problems.get(0); return problem.getMessage(); }
/** * @return Message of the first problem (useful for better error display on whoops). */ @Override public String get() { AssetProblem problem = problems.get(0); return problem.getMessage(); }
private AssetProblem problem(final V8Object js) { Optional<Integer> line = get("line", name -> ((Number) js.get(name)).intValue()); Optional<Integer> column = get("column", name -> ((Number) js.get(name)).intValue()); Optional<String> filename = get("filename", js::getString); Optional<String> evidence = get("evidence", js::getString); Optional<String> message = get("message", js::getString); return new AssetProblem(filename.orElse("file.js"), line.orElse(-1), column.orElse(-1), message.orElse(""), evidence.orElse(null)); }
/** * Add a virtual/fake stacktrace element with the offending file, useful for whoops. * * @param ex Stack trace to rewrite. * @return Same exception with new stacktrace. */ private AssetException rewrite(final AssetException ex) { List<StackTraceElement> stacktrace = Lists.newArrayList(ex.getStackTrace()); List<AssetProblem> problems = ex.getProblems(); AssetProblem head = problems.get(0); stacktrace.add(0, new StackTraceElement(head.getFilename(), "", head.getFilename(), head.getLine())); ex.setStackTrace(stacktrace.toArray(new StackTraceElement[stacktrace.size()])); return ex; }
@Override public String toString() { return (filename + ":" + line + ":" + column + ": " + message + "\n" + getEvidence()).trim(); } }
private void onChange(final Kind<?> kind, final Path path) { File outputdir = workdir.toFile(); String filename = Route .normalize(Try.apply(() -> path.subpath(1, path.getNameCount()).toString()) .orElse(path.toString())); try { if (kind == StandardWatchEventKinds.ENTRY_DELETE) { errors.remove(filename); } else { if (Files.isDirectory(path)) { errors.clear(); compiler.build("dev", outputdir); } else { compiler.buildOne(filename, outputdir); errors.remove(filename); } } } catch (AssetException ex) { String localname = ex.getProblems().stream() .findFirst() .map(AssetProblem::getFilename) .orElse(filename); errors.put(localname, rewrite(ex)); } catch (Exception ex) { AssetException assetEx = rewrite(new AssetException("compiler", new AssetProblem(filename, -1, -1, ex.getMessage(), null), ex)); errors.put(filename, assetEx); } }
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) { try { Env env = Env.DEFAULT.build(conf); List<String> delims = get("delims"); Resolver resolver = env.resolver(); boolean ignoreMissing = get("ignoreMissing"); if (ignoreMissing) { resolver.ignoreMissing(); } resolver.delimiters(delims.get(0), delims.get(1)); return resolver.resolve(source); } catch (Exception cause) { int line = -1; int column = -1; Matcher matcher = POS.matcher(cause.getMessage()); if (matcher.find()) { line = Integer.parseInt(matcher.group(1)); column = Integer.parseInt(matcher.group(2)); } throw new AssetException(name(), new AssetProblem(filename, line, column, cause.getMessage(), null)); } }
int column = location.getOrDefault("column", -1); throw new AssetException(name(), new AssetProblem(Optional.ofNullable(x.getErrorFile()).orElse(filename), line, column, x.getErrorText(), null));
@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 process(final String filename, final String source, final Config conf, final ClassLoader loader) throws Exception { final CompilerOptions copts = new CompilerOptions(); copts.setCodingConvention(new ClosureCodingConvention()); copts.setOutputCharset(StandardCharsets.UTF_8); copts.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.WARNING); CompilationLevel level = level(get("level")); level.setOptionsForCompilationLevel(copts); Compiler.setLoggingLevel(Level.SEVERE); Compiler compiler = new Compiler(); compiler.disableThreads(); compiler.initOptions(copts); List<SourceFile> externs = externs(copts); Result result = compiler.compile(externs, ImmutableList.of(SourceFile.fromCode(filename, source)), copts); if (result.success) { return compiler.toSource(); } List<AssetProblem> errors = Arrays.stream(result.errors) .map(error -> new AssetProblem(error.sourceName, error.lineNumber, error.getCharno(), error.description, null)) .collect(Collectors.toList()); throw new AssetException(name(), errors); }
private void onChange(final Kind<?> kind, final Path path) { File outputdir = workdir.toFile(); String filename = Route .normalize(Try.apply(() -> path.subpath(1, path.getNameCount()).toString()) .orElse(path.toString())); try { if (kind == StandardWatchEventKinds.ENTRY_DELETE) { errors.remove(filename); } else { if (Files.isDirectory(path)) { errors.clear(); compiler.build("dev", outputdir); } else { compiler.buildOne(filename, outputdir); errors.remove(filename); } } } catch (AssetException ex) { String localname = ex.getProblems().stream() .findFirst() .map(AssetProblem::getFilename) .orElse(filename); errors.put(localname, rewrite(ex)); } catch (Exception ex) { AssetException assetEx = rewrite(new AssetException("compiler", new AssetProblem(filename, -1, -1, ex.getMessage(), null), ex)); errors.put(filename, assetEx); } }
@Override public String process(final String filename, final String source, final Config conf, final ClassLoader loader) { try { Env env = Env.DEFAULT.build(conf); List<String> delims = get("delims"); Resolver resolver = env.resolver(); boolean ignoreMissing = get("ignoreMissing"); if (ignoreMissing) { resolver.ignoreMissing(); } resolver.delimiters(delims.get(0), delims.get(1)); return resolver.resolve(source); } catch (Exception cause) { int line = -1; int column = -1; Matcher matcher = POS.matcher(cause.getMessage()); if (matcher.find()) { line = Integer.parseInt(matcher.group(1)); column = Integer.parseInt(matcher.group(2)); } throw new AssetException(name(), new AssetProblem(filename, line, column, cause.getMessage(), null)); } }