org.codehaus.groovy.tools.shell.IO Java Examples

The following examples show how to use org.codehaus.groovy.tools.shell.IO. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Preferences.java    From groovy with Apache License 2.0 6 votes vote down vote up
public void preferenceChange(final PreferenceChangeEvent event) {
    if (event.getKey().equals(VERBOSITY_KEY)) {
        String name = event.getNewValue();

        if (name == null) {
            name = IO.Verbosity.INFO.name;
        }

        try {
            verbosity = IO.Verbosity.forName(name);
        }
        catch (Exception e) {
            event.getNode().put(event.getKey(), verbosity.name);
        }
    }
}
 
Example #2
Source File: GroovyInterpreter.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public GroovyInterpreter(Binding binding) throws IOException {
	this.binding = binding;
	if (this.binding == null)
		this.binding = new Binding();

	is = new PipedInputStream();
	os = new PipedOutputStream();
	pis = new PipedInputStream(os);
	pos = new PipedOutputStream(is);

	System.setProperty(TerminalFactory.JLINE_TERMINAL, "none");
	AnsiConsole.systemInstall();
	Ansi.setDetector(new AnsiDetector());

	binding.setProperty("out", new ImmediateFlushingPrintWriter(pos));

	shell = new Groovysh(binding, new IO(pis, pos, pos));
	// {
	// @Override
	// public void displayWelcomeBanner(InteractiveShellRunner runner) {
	// // do nothing
	// }
	// };
	shell.getIo().setVerbosity(Verbosity.QUIET);
}
 
Example #3
Source File: GroovyShellWrapper.java    From artifactory_ssh_proxy with Apache License 2.0 5 votes vote down vote up
protected void runGroovy() {
    try {
        LOGGER.info("Running groovy shell");
        IO io = new IO(in, out, err);

        LOGGER.info("in: {} out: {}  err: {}", in, out, err);

        // TODO: fix to allow other bindings.
        Binding binding = new Binding();
        binding.setVariable("out", io.out);

        Groovysh groovysh = new Groovysh(binding, io);
        InteractiveShellRunner isr = new InteractiveShellRunner(groovysh, new GroovyPrompt(this));

        isr.setErrorHandler(new OutputStreamErrorHandler(this, err));

        try {
            // groovysh.run((String) null);
            isr.run();
        } catch (Exception e) {
            try (PrintStream ps = new PrintStream(out)) {
                e.printStackTrace(ps);
            }
            this.alive = false;
        }
    } finally {
        this.alive = false;
        destroy();
        callback.onExit(exitValue());
    }
}
 
Example #4
Source File: ShellEnvironment.java    From sqoop-on-spark with Apache License 2.0 4 votes vote down vote up
public static void setIo(IO ioObject) {
  io = ioObject;
}
 
Example #5
Source File: ShellEnvironment.java    From sqoop-on-spark with Apache License 2.0 4 votes vote down vote up
public static IO getIo() {
  return io;
}
 
Example #6
Source File: Logger.java    From groovy with Apache License 2.0 4 votes vote down vote up
public boolean isDebugEnabled() {
    return Preferences.verbosity == IO.Verbosity.DEBUG;
}
 
Example #7
Source File: MockGroovyGremlinShellEnvironment.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public MockGroovyGremlinShellEnvironment(final Groovysh groovysh, final IO io) {
    this.groovysh = groovysh;
    this.io = io;
}