Ejemplo n.º 1
0
 private boolean parseInputs(Collection<URI> inputs, PluginCompiler pluginc) {
   boolean parsePassed = true;
   for (URI input : inputs) {
     try {
       ParseTreeNode parseTree = parseInput(input);
       if (null != parseTree) {
         pluginc.addInput(new AncestorChain<ParseTreeNode>(parseTree));
       }
     } catch (ParseException ex) {
       ex.toMessageQueue(mq);
       parsePassed = false;
     } catch (IOException ex) {
       mq.addMessage(MessageType.IO_ERROR, MessagePart.Factory.valueOf(ex.toString()));
       parsePassed = false;
     }
   }
   return parsePassed;
 }
Ejemplo n.º 2
0
  private int run(String[] argv) {
    if (!config.processArguments(argv)) {
      return -1;
    }

    boolean success = false;
    MessageContext mc = null;
    ParseTreeNode compiledOutput = null;
    try {
      PluginMeta meta = new PluginMeta(makeEnvironment(config));
      meta.setDebugMode(config.debugMode());
      meta.setValijaMode(config.cajaMode());
      PluginCompiler compiler = new PluginCompiler(BuildInfo.getInstance(), meta, mq);
      mc = compiler.getMessageContext();
      compiler.setCssSchema(config.getCssSchema(mq));
      compiler.setHtmlSchema(config.getHtmlSchema(mq));

      success = parseInputs(config.getInputUris(), compiler) && compiler.run();
      if (success) {
        compiledOutput = compiler.getJavascript();
      }
    } finally {
      if (mc == null) {
        mc = new MessageContext();
      }
      MessageLevel maxMessageLevel = dumpMessages(mq, mc, System.err);
      success &= MessageLevel.ERROR.compareTo(maxMessageLevel) > 0;
    }

    if (success) {
      writeFile(config.getOutputJsFile(), compiledOutput);
    } else {
      // Make sure there is no previous output file from a failed run.
      config.getOutputJsFile().delete();
      // If it wasn't there in the first place, or is not writable, that's OK,
      // so ignore the return value.
    }

    return success ? 0 : -1;
  }