Package org.codehaus.groovy.tools.shell

Examples of org.codehaus.groovy.tools.shell.Groovysh


            in = socket.getInputStream();
            out = new PrintStream(socket.getOutputStream());
            binding.setVariable("out", out);

            final IO io = new IO(in, out, out);
            final Groovysh gsh = new Groovysh(binding, io);
            gsh.run();
        } catch (Exception e) {
            log.error("Error running the Groovy shell.", e);
        } finally {
            try { if (out != null) out.close(); } catch (Exception e) {}
            try { if (in != null) in.close(); } catch (Exception e) {}
View Full Code Here


        // this being remote means no jline capability is available
        System.setProperty("jline.terminal", UnsupportedTerminal.class.getName());
        Terminal.resetTerminal();

        Groovysh shell = createShell(stdin, stdout, stderr);
        return shell.run(args.toArray(new String[args.size()]));
    }
View Full Code Here

                r.register(GroovyshCommand.class.getResource("commands.xml"));

                return null;
            }
        };
        Groovysh shell = new Groovysh(cl, binding, io, registrar);
        shell.getImports().add("import hudson.model.*");

        // defaultErrorHook doesn't re-throw IOException, so ShellRunner in
        // Groovysh will keep looping forever if we don't terminate when the
        // channel is closed
        final Closure originalErrorHook = shell.getErrorHook();
        shell.setErrorHook(new Closure(shell, shell) {
            private static final long serialVersionUID = 1L;

            @SuppressWarnings("unused")
            @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS",justification="Closure invokes this via reflection")
            public Object doCall(Object[] args) throws ChannelClosedException {
View Full Code Here

   * @param args Command line arguments
   * @throws Exception
   */
  public static void main (String[] args) throws Exception {
    System.setProperty("groovysh.prompt", Constants.SQOOP_PROMPT);
    Groovysh shell = new Groovysh();

    // Install our error hook (exception handling)
    shell.setErrorHook(new MethodClosure(ThrowableDisplayer.class, "errorHook"));

    CommandRegistry registry = shell.getRegistry();
    @SuppressWarnings("unchecked")
    Iterator<Command> iterator = registry.iterator();
    while (iterator.hasNext()) {
      Command command = iterator.next();
      if (!commandsToKeep.contains(command.getName())) {
        iterator.remove();
        // remove from "names" set to avoid duplicate error.
        registry.remove(command);
      }
    }

    shell.register(new HelpCommand(shell));
    shell.register(new SetCommand(shell));
    shell.register(new ShowCommand(shell));
    shell.register(new CreateCommand(shell));
    shell.register(new DeleteCommand(shell));
    shell.register(new UpdateCommand(shell));
    shell.register(new CloneCommand(shell));
    shell.register(new StartCommand(shell));
    shell.register(new StopCommand(shell));
    shell.register(new StatusCommand(shell));
    shell.register(new EnableCommand(shell));
    shell.register(new DisableCommand(shell));

    // Configure shared shell io object
    setIo(shell.getIo());

    // We're running in batch mode by default
    setInteractive(false);

    // Let's see if user do have resource file with initial commands that he
    // would like to apply.
    String homeDir = System.getProperty(Constants.PROP_HOMEDIR);
    File rcFile = new File(homeDir, RC_FILE);

    if(rcFile.exists()) {
      printlnResource(Constants.RES_SQOOP_PROMPT_SHELL_LOADRC, RC_FILE);
      interpretFileContent(rcFile, shell);
      printlnResource(Constants.RES_SQOOP_PROMPT_SHELL_LOADEDRC);
    }

    if (args.length == 0) {
      // Interactive mode:
      getIo().setVerbosity(Verbosity.QUIET);
      printlnResource(Constants.RES_SQOOP_SHELL_BANNER);
      println();

      // Switch to interactive mode
      setInteractive(true);
      shell.run(args);

    } else {
      // Batch mode (with a script file):
      File script = new File(args[0]);
      if (!script.isAbsolute()) {
View Full Code Here

   * @throws Exception
   */
  public static void main (String[] args) throws Exception
  {
    System.setProperty("groovysh.prompt", Constants.SQOOP_PROMPT);
    Groovysh shell = new Groovysh();

    // Install our error hook (exception handling)
    shell.setErrorHook(
      new MethodClosure(ThrowableDisplayer.class, "errorHook"));
    ThrowableDisplayer.setIo(shell.getIo());

    CommandRegistry registry = shell.getRegistry();
    @SuppressWarnings("unchecked")
    Iterator<Command> iterator = registry.iterator();
    while (iterator.hasNext()) {
      Command command = iterator.next();
      if (!commandsToKeep.contains(command.getName())) {
        iterator.remove();
        // remove from "names" set to avoid duplicate error.
        registry.remove(command);
      }
    }

    shell.register(new HelpCommand(shell));
    shell.register(new SetCommand(shell));
    shell.register(new ShowCommand(shell));
    shell.register(new CreateCommand(shell));
    shell.register(new DeleteCommand(shell));
    shell.register(new UpdateCommand(shell));
    shell.register(new CloneCommand(shell));
    shell.register(new SubmissionCommand(shell));

    // Let's see if user do have resource file with initial commands that he
    // would like to apply.
    String homeDir = System.getProperty(Constants.PROP_HOMEDIR);
    File rcFile = new File(homeDir, RC_FILE);

    if(rcFile.exists()) {
      shell.getIo().out.println(MessageFormat.format(clientResource.getString
          (Constants.RES_SQOOP_PROMPT_SHELL_LOADRC), RC_FILE));
      interpretFileContent(rcFile, shell);
      shell.getIo().out.println(clientResource.getString(Constants.RES_SQOOP_PROMPT_SHELL_LOADEDRC));
    }

    if (args.length == 0) {
      // Interactive mode:
      shell.getIo().setVerbosity(Verbosity.QUIET);
      shell.getIo().out.println(clientResource.getString(Constants
          .RES_SQOOP_SHELL_BANNER));
      shell.getIo().out.println();
      shell.run(args);

    } else {
      // Batch mode (with a script file):
      File script = new File(args[0]);
      if (!script.isAbsolute()) {
View Full Code Here

      setup.println( "import org.apache.hadoop.gateway.shell.job.Job;" );
      setup.println( "import org.apache.hadoop.gateway.shell.workflow.Workflow;" );
      setup.println( "import java.util.concurrent.TimeUnit;" );
      //setup.println( "set verbosity QUIET;" );
      //setup.println( "set show-last-result false;" );
      Groovysh shell = new Groovysh();
      shell.execute( buffer.toString() );
      shell.run();
    }
  }
View Full Code Here

  @Override
  public void start(final Environment env) throws IOException {
    TtyFilterOutputStream out = new TtyFilterOutputStream(this.out);
    TtyFilterOutputStream err = new TtyFilterOutputStream(this.err);

    final Groovysh shell = new Groovysh(createBinding(bindings, out, err), new IO(in, out, err));

    loadDefaultScripts(shell);

    String threadName = "GroovySh Client Thread";
    wrapper = new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          SshTerminal.registerEnvironment(env);
          shell.run();
          callback.onExit(0);
        } catch (RuntimeException e) {
          callback.onExit(-1, e.getMessage());
        } catch (Error e) {
          callback.onExit(-1, e.getMessage());
View Full Code Here

        io.out.println();
        io.out.println("         \\,,,/");
        io.out.println("         (o o)");
        io.out.println("-----oOOo-(_)-oOOo-----");

        final Groovysh groovy = new Groovysh();
        groovy.setResultHook(new NullResultHookClosure(groovy));
        for (final String imps : Imports.getImports()) {
            groovy.execute("import " + imps);
        }
        for (final String evs : Imports.getEvaluates()) {
            groovy.execute(evs);
        }

        groovy.setResultHook(new ResultHookClosure(groovy, io, resultPrompt));
        groovy.setHistory(new History());

        final InteractiveShellRunner runner = new InteractiveShellRunner(groovy, new PromptClosure(groovy, inputPrompt));
        runner.setErrorHandler(new ErrorHookClosure(runner, io));
        try {
            runner.setHistory(new History(new File(System.getProperty("user.home") + "/" + HISTORY_FILE)));
View Full Code Here

      setup.println( "import org.apache.hadoop.gateway.shell.workflow.Workflow;" );
      setup.println( "import org.apache.hadoop.gateway.shell.yarn.Yarn;" );
      setup.println( "import java.util.concurrent.TimeUnit;" );
      //setup.println( "set verbosity QUIET;" );
      //setup.println( "set show-last-result false;" );
      Groovysh shell = new Groovysh();
      shell.execute( buffer.toString() );
      shell.run();
    }
  }
View Full Code Here

              final CompilerConfiguration conf = new CompilerConfiguration(System.getProperties());
              final GroovyShell shell = new GroovyShell(binding, conf);
              shell.run(scriptFile, args);
          }
          else {
              final Groovysh shell = new Groovysh(binding, new IO());
              shell.run();
          }
        }
        finally {
          if (applicationContext instanceof DisposableBean) {
            ((DisposableBean) applicationContext).destroy();
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.tools.shell.Groovysh

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.