Beispiel #1
0
  public String parse(PRubySourceDef source) {
    String[] array = new String[] {"/usr/bin/ruby", PRubyParserJRuby.PARSER_RB, source.getPath()};

    System.out.println("Parsing:");

    String input = source.getString();
    VMLog.debug("INPUT:");
    VMLog.debug(input);
    System.out.println("Parsed.");

    String ret = runPipe(array, input);
    return ret;
  }
Beispiel #2
0
  public String runPipe(String[] array, String input) {
    Runtime r = Runtime.getRuntime();

    if (input == null) return null;

    try {
      Process proc = r.exec(array);

      // write
      OutputStream os = proc.getOutputStream();
      InputStream error = proc.getErrorStream();

      os.write(input.getBytes());
      os.close();

      // proc.getOutputStream();
      int read;
      byte[] buffer = new byte[1024];

      while ((read = error.read(buffer)) > 0) {
        System.out.println(new String(buffer, 0, read));
      }

      proc.waitFor();

      // read
      StringBuilder b = new StringBuilder();
      while ((read = proc.getInputStream().read(buffer)) > 0) {
        b.append(new String(buffer, 0, read));
      }
      if (proc.exitValue() != 0) {
        VMLog.error("Exit Value:" + proc.exitValue());

        System.out.println(b.toString());

        return null;
      }

      return b.toString();
    } catch (IOException e) {
      VMLog.error(e);
    } catch (InterruptedException e) {
      VMLog.error(e);
    }

    return null;
  }
Beispiel #3
0
  public static void main(String[] args) {
    VMLog.setLogLevels(new Level[] {VMLog.Level.DEBUG, Level.ERROR, Level.WARN});

    PRubyParserMRIRuby p = new PRubyParserMRIRuby();
    PRubySourceDef def =
        new PRubySourceDef("simple_function.prb", new SinglePathSourceSource(new File("ruby")));
    String res = p.parse(def);
    System.out.println(res);
  }
  public void execute(VMScope scope, Task parentTask)
      throws VMExceptionFunctionNotFound, VMExceptionOutOfMemory, VMInternalException {

    BasicObject bo = scope.get(rObjectName);
    if (bo instanceof MemberProvider) {
      MemberProvider p = (MemberProvider) bo;

      scope.put(lObjectName, p.getStatic(rMemberName));
      return;
    }
    VMLog.debug("Right:" + bo);
    throw new VMInternalException(this, "Right value was not found!");
  }