All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.devcake.groovy.remoteconsole.ui.RemoteConsole.groovy Maven / Gradle / Ivy

Go to download

The library allows to create remote console server easily, and run Groovy scripts remotely on the console server. It supports execution of parts of the script, with all import statements applied. The library can be used as a standalone remote console server, and as embedded console server. It contains default implementaiton of Remote Console client, whereas customized implementation is also available.

There is a newer version: 1.0.16
Show newest version
package org.devcake.groovy.remoteconsole.ui

import groovy.ui.Console

import org.devcake.groovy.remoteconsole.RemoteConsoleClient
import org.codehaus.groovy.runtime.InvokerHelper
import org.devcake.groovy.autoimports.ConsoleUtils

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 30.09.2010
 * Time: 3:14:33
 * To change this template use File | Settings | File Templates.
 */
class RemoteConsole extends Console {

    RemoteConsole(ClassLoader parent) {
        super(parent)
    }

    void runScript(EventObject evt) {
        runScriptImpl(inputArea.getText(), inputArea.getText())
    }

    void runSelectedScript(EventObject evt) {
        runScriptImpl(inputArea.getText(), inputArea.getSelectedText())
    }

    private void runScriptImpl(String fullScript, String selectedScript) {
        selectedScript = selectedScript ?: fullScript
        appendScriptOutput(selectedScript)
        def p = new ConsoleScriptExecutionProcessor(this)
        def client = new RemoteConsoleClient(p)
        Thread.start {
            try {
                client.execute(RemoteConsoleClient.getScriptOptions(fullScript), fullScript, selectedScript)
            } catch(e) {
                // we use InvokerHelper, because the method is private and nto accessible from the subclass
                InvokerHelper.invokeSuperMethod(this, 'reportException', e)
            }
        }
    }

    private void appendScriptOutput(String script) {
        script.eachLine {
            appendOutputNl 'groovy> ', promptStyle
            appendOutput it, commandStyle
        }
        appendOutputNl('\n', promptStyle)
    }

    static void main(args) {
        ConsoleUtils.runConsole RemoteConsole, args
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy