(String script, boolean batch, boolean loadOnly, boolean illustrate,
List<String> params, List<String> files)
| 508 | } |
| 509 | |
| 510 | private void loadScript(String script, boolean batch, boolean loadOnly, boolean illustrate, |
| 511 | List<String> params, List<String> files) |
| 512 | throws IOException, ParseException { |
| 513 | |
| 514 | Reader inputReader; |
| 515 | ConsoleReader reader; |
| 516 | boolean interactive; |
| 517 | |
| 518 | PigContext pc = mPigServer.getPigContext(); |
| 519 | |
| 520 | if( !loadOnly ) { |
| 521 | pc.getPreprocessorContext().paramScopePush(); |
| 522 | } |
| 523 | pc.setParams(params); |
| 524 | pc.setParamFiles(files); |
| 525 | |
| 526 | try { |
| 527 | FetchFileRet fetchFile = FileLocalizer.fetchFile(mConf, script); |
| 528 | String cmds = runPreprocessor(fetchFile.file.getAbsolutePath(), params, files); |
| 529 | |
| 530 | if (mInteractive && !batch) { // Write prompt and echo commands |
| 531 | // Console reader treats tabs in a special way |
| 532 | cmds = cmds.replaceAll("\t"," "); |
| 533 | |
| 534 | reader = new ConsoleReader(new ByteArrayInputStream(cmds.getBytes()), |
| 535 | System.out); |
| 536 | reader.setHistory(mConsoleReader.getHistory()); |
| 537 | InputStream in = new ConsoleReaderInputStream(reader); |
| 538 | inputReader = new BufferedReader(new InputStreamReader(in)); |
| 539 | interactive = true; |
| 540 | } else { // Quietly parse the statements |
| 541 | inputReader = new StringReader(cmds); |
| 542 | reader = null; |
| 543 | interactive = false; |
| 544 | } |
| 545 | } catch (FileNotFoundException fnfe) { |
| 546 | throw new ParseException("File not found: " + script); |
| 547 | } catch (SecurityException se) { |
| 548 | throw new ParseException("Cannot access file: " + script); |
| 549 | } |
| 550 | |
| 551 | GruntParser parser = new GruntParser(inputReader, mPigServer); |
| 552 | parser.setConsoleReader(reader); |
| 553 | parser.setInteractive(interactive); |
| 554 | parser.setLoadOnly(loadOnly); |
| 555 | if (illustrate) |
| 556 | parser.setScriptIllustrate(); |
| 557 | parser.mExplain = mExplain; |
| 558 | |
| 559 | parser.prompt(); |
| 560 | while(!parser.isDone()) { |
| 561 | parser.parse(); |
| 562 | } |
| 563 | |
| 564 | if (interactive) { |
| 565 | System.out.println(""); |
| 566 | } |
| 567 | if( ! loadOnly ) { |
no test coverage detected