Package com.google.caja.reporting

Examples of com.google.caja.reporting.MessageQueue


  public boolean build(List<File> inputs, List<File> dependencies,
      Map<String, Object> options, File output) throws IOException {
    MessageContext mc = new MessageContext();
    Map<InputSource, CharSequence> contentMap = Maps.newLinkedHashMap();
    MessageQueue mq = new SimpleMessageQueue();
    List<LintJob> lintJobs = parseInputs(inputs, contentMap, mc, mq);
    lint(lintJobs, env, mq);
    if (!ignores.isEmpty()) {
      for (Iterator<Message> it = mq.getMessages().iterator(); it.hasNext();) {
        if (ignores.contains(it.next().getMessageType().name())) {
          it.remove();
        }
      }
    }
View Full Code Here


      if (p != null) {
        mq.getMessages().addAll(p.b);
        return p.a;
      }
    }
    MessageQueue origMq = mq;
    SimpleMessageQueue cacheMq = new SimpleMessageQueue();
    this.mq = cacheMq;
    try {
      WhiteListSkeleton skel = loadSkeleton(
          expectJSONObject(JSONValue.parse(in), "whitelist"));
      if (in instanceof UriReader) {
        cache.put(
            ((UriReader) in).getUri(),
            Pair.pair(skel, cacheMq.getMessages()));
      }
      return skel;
    } finally {
      this.mq = origMq;
      origMq.getMessages().addAll(cacheMq.getMessages());
    }
  }
View Full Code Here

      throws IOException {

    MessageContext mc = new MessageContext();
    mc.addInputSource(input.a);

    final MessageQueue errs = new EchoingMessageQueue(
        err, mc, false);
    CharProducer cp = CharProducer.Factory.create(
        new InputStreamReader(new FileInputStream(input.b),
            Charsets.UTF_8.name()),
        input.a);

    JsLexer lexer = new JsLexer(cp);
    JsTokenQueue tq = new JsTokenQueue(lexer, input.a);
    Parser p = new Parser(tq, errs);
    String output = "";

    try {
      Block start = p.parse();
      tq.expectEmpty();
      Rewriter icr = new InnocentCodeRewriter(errs, false /* logging */);
      output = Rewriter.render(icr.expand(start));
      out.append(output);
    } catch (ParseException ex) {
      ex.toMessageQueue(errs);
    }

    out.flush();

    MessageLevel maxMessageLevel = MessageLevel.values()[0];
    for (Message msg : errs.getMessages()) {
      if (msg.getMessageLevel().compareTo(maxMessageLevel) >= 0) {
        maxMessageLevel = msg.getMessageLevel();
      }
    }
    return maxMessageLevel.compareTo(MessageLevel.ERROR) < 0;
View Full Code Here

          attrsFile.getAbsoluteFile().toURI()));

      MessageContext mc = new MessageContext();
      mc.addInputSource(elements.source());
      mc.addInputSource(attrs.source());
      MessageQueue mq = new EchoingMessageQueue(
          new PrintWriter(new OutputStreamWriter(System.err), true), mc, false);

      Set<File> inputsAndDeps = new HashSet<File>();
      for (File f : inputs) { inputsAndDeps.add(f.getAbsoluteFile()); }
      for (File f : deps) { inputsAndDeps.add(f.getAbsoluteFile()); }
View Full Code Here

      throws IOException {
    MessageContext mc = new MessageContext();
    for (Pair<InputSource, File> input : inputs) {
      mc.addInputSource(input.a);
    }
    final MessageQueue errs = new EchoingMessageQueue(
        err, mc, false);
    RenderContext rc = new RenderContext(
        new JsMinimalPrinter(new Concatenator(out, new Callback<IOException>() {
          public void handle(IOException ex) {
            errs.addMessage(
                MessageType.IO_ERROR,
                MessagePart.Factory.valueOf(ex.getMessage()));
          }
        })));

    for (Pair<InputSource, File> input : inputs) {
      CharProducer cp = CharProducer.Factory.create(
          new InputStreamReader(new FileInputStream(input.b),
              Charsets.UTF_8.name()),
          input.a);
      JsLexer lexer = new JsLexer(cp);
      JsTokenQueue tq = new JsTokenQueue(lexer, input.a);
      Parser p = new Parser(tq, errs);
      try {
        while (!tq.isEmpty()) {
          Block b = p.parse();
          for (Statement topLevelStmt : b.children()) {
            topLevelStmt.render(rc);
            if (!topLevelStmt.isTerminal()) { rc.getOut().consume(";"); }
          }
        }
      } catch (ParseException ex) {
        ex.toMessageQueue(errs);
      }
    }
    rc.getOut().noMoreTokens();
    out.flush();

    MessageLevel maxMessageLevel = MessageLevel.values()[0];
    for (Message msg : errs.getMessages()) {
      if (msg.getMessageLevel().compareTo(maxMessageLevel) >= 0) {
        maxMessageLevel = msg.getMessageLevel();
      }
    }
    return maxMessageLevel.compareTo(MessageLevel.ERROR) < 0;
View Full Code Here

  public static JsonML parse(CharProducer cp) throws ParseException {
    JsLexer lexer = new JsLexer(cp, false);
    JsTokenQueue tq = new JsTokenQueue(
        lexer, cp.getCurrentPosition().source());
    tq.setInputRange(cp.filePositionForOffsets(cp.getOffset(), cp.getLimit()));
    MessageQueue mq = new EchoingMessageQueue(
        new PrintWriter(System.err), new MessageContext());
    Parser p = new Parser(tq, mq);
    Block program = p.parse();
    tq.expectEmpty();
    return program.toJsonMLAsProgram();
View Full Code Here

          functionsFile.getAbsoluteFile().toURI()));

      MessageContext mc = new MessageContext();
      mc.addInputSource(sps.source());
      mc.addInputSource(fns.source());
      MessageQueue mq = new EchoingMessageQueue(
          new PrintWriter(new OutputStreamWriter(System.err), true), mc, false);

      Set<File> inputsAndDeps = Sets.newHashSet();
      for (File f : inputs) { inputsAndDeps.add(f.getAbsoluteFile()); }
      for (File f : deps) { inputsAndDeps.add(f.getAbsoluteFile()); }
View Full Code Here

  // into a more usable api for the cajoler
  public CajolingServiceResult cajole(
      String base, String url, String input,
      boolean debugMode, String opt_idClass) {
    MessageContext mc = new MessageContext();
    MessageQueue mq = new SimpleMessageQueue();

    ParseTreeNode outputJs;
    Node outputHtml;

    Map<InputSource, ? extends CharSequence> originalSources
        = Collections.singletonMap(new InputSource(guessURI(base, url)), input);

    PluginMeta meta = new PluginMeta(fetcher, null);
    if (opt_idClass != null && opt_idClass.length() != 0) {
      meta.setIdClass(opt_idClass);
    }
    PluginCompiler compiler = makePluginCompiler(meta, mq);
    compiler.setJobCache(new AppEngineJobCache());
    compiler.setMessageContext(mc);

    URI uri = guessURI(base, url);
    InputSource is = new InputSource(uri);
    CharProducer cp = CharProducer.Factory.fromString(input, is);
    boolean okToContinue = true;
    Dom inputNode = null;
    try {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      inputNode = new Dom(p.parseFragment());
      p.getTokenQueue().expectEmpty();
    } catch (ParseException e) {
      mq.addMessage(e.getCajaMessage());
      okToContinue = false;
    }

    if (okToContinue && inputNode != null) {
      compiler.addInput(inputNode, uri);
View Full Code Here

    int injectHtmlIndex = inputs.size();

    List<Pair<String, InputSource>> scriptContent
        = new ArrayList<Pair<String, InputSource>>();
    MessageContext mc = new MessageContext();
    MessageQueue mq = new EchoingMessageQueue(new PrintWriter(System.err), mc);

    List<Element> scripts = new ArrayList<Element>();
    for (Element script : Nodes.nodeListIterable(
             html.getElementsByTagNameNS(HTML_NS, "script"), Element.class)) {
      scripts.add(script);
View Full Code Here

    // If there is a failure, there should be an error or greater on the queue.
    assertTrue(maxLevel.name(), MessageLevel.ERROR.compareTo(maxLevel) <= 0);
  }

  private void warns(String css) throws Exception {
    MessageQueue smq = new SimpleMessageQueue();
    CssTree t = css(fromString(css), true);
    CssValidator v = makeCssValidator(smq);
    boolean valid = v.validateCss(ac(t));
    mq.getMessages().addAll(smq.getMessages());
    assertTrue(css, valid);
    assertTrue(css, !mq.getMessages().isEmpty());
  }
View Full Code Here

TOP

Related Classes of com.google.caja.reporting.MessageQueue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.