Groovysh shell = new Groovysh(cl, binding, io, registrar); shell.getImports().add("hudson.model.*"); final Closure originalErrorHook = shell.getErrorHook(); shell.setErrorHook(new Closure(shell, shell) { private static final long serialVersionUID = 1L;
@Override protected int run() { // this allows the caller to manipulate the JVM state, so require the admin privilege. Jenkins.getActiveInstance().checkPermission(Jenkins.RUN_SCRIPTS); // this being remote means no jline capability is available System.setProperty("jline.terminal", UnsupportedTerminal.class.getName()); TerminalFactory.reset(); StringBuilder commandLine = new StringBuilder(); for (String arg : args) { if (commandLine.length() > 0) { commandLine.append(" "); } commandLine.append(arg); } Groovysh shell = createShell(stdin, stdout, stderr); return shell.run(commandLine.toString()); }
public static void main( String... args ) throws IOException { PropertyConfigurator.configure( System.getProperty( "log4j.configuration" ) ); if( args.length > 0 ) { GroovyMain.main( args ); } else { Groovysh shell = new Groovysh(); for( String name : IMPORTS ) { shell.execute( "import " + name ); } shell.run( null ); } }
public GremlinWebConsole( Binding bindings, IO io ) { groovy = new Groovysh( bindings, io ); groovy.setResultHook( new NullResultHookClosure( groovy ) ); for ( String imps : Imports.getImports() ) { groovy.execute( "import " + imps ); } for ( String imps : Neo4jGroovyImports.getImports() ) { groovy.execute( "import " + imps ); } groovy.execute( "import com.tinkerpop.gremlin.groovy.*" ); // groovy.execute( "import .*" ); groovy.setResultHook( new GremlinResultHook( groovy, io ) ); Gremlin.load(); }
System.setProperty("java.awt.headless", "true"); // don't start awt/swing Groovysh ish= new Groovysh(binding, io); ish.run(""); ish.getHistory().flush();
public Console(final IO io, final String inputPrompt, final String resultPrompt) { 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))); } catch (IOException e) { io.err.println("Unable to create history file: " + HISTORY_FILE); } Gremlin.load(); FaunusGremlin.load(); try { runner.run(); } catch (Error e) { //System.err.println(e.getMessage()); } }
groovysh = new Groovysh(io); setGroovyShell(groovysh, groovyShell); setResultHook(groovysh, resultHook); shell.execute("import " + Visibility.class.getPackage().getName() + ".*;"); shell.execute("v = new " + LazyVertexMap.class.getName() + "();"); shell.execute("e = new " + LazyEdgeMap.class.getName() + "();"); shell.execute("g = " + VertexiumScript.class.getName() + ".getGraph();"); shell.execute("auths = " + VertexiumScript.class.getName() + ".getAuthorizations();"); shell.execute("time = " + VertexiumScript.class.getName() + ".getTime();"); shell.execute("cypher = { code -> " + VertexiumScript.class.getName() + ".executeCypher(code) };"); startGroovysh(params, shell, params.evalString, params.fileNames); return 0;
private Groovysh createShell() { if (welcomeMessage != null) { writer.println(SEPARATOR_BAR); writer.println(welcomeMessage); writer.println(SEPARATOR_BAR); } binding.setVariable(OUT_KEY, out); final CompilerConfiguration config = new CompilerConfiguration(); final GroovyClassLoader loader = new GroovyClassLoader(this.getClass().getClassLoader(), config); final Groovysh shell = new Groovysh(loader, binding, new IO(in, out, out)); writer.flush(); return shell; }
System.out.println(" cypher - run a cypher query (usage: cypher(\"\"\"MATCH (n) RETURN n LIMIT 10\"\"\"))"); try { shell.execute("import " + Visibility.class.getPackage().getName() + ".*;"); shell.execute("import " + GeoPoint.class.getPackage().getName() + ".*;"); shell.execute("import " + GeoCompare.class.getPackage().getName() + ".*;"); for (String evalFile : params.evalFiles) { shell.execute(String.format(":load '%s'", evalFile)); code = shell.run(evalString, filenames); } finally { System.setSecurityManager(psm);
final Groovysh shell = new Groovysh(createBinding(bindings, out, err), io); shell.setErrorHook(new Closure(this) { @Override public Object call(Object... args) {
public void execute( String script ) { groovy.execute( script ); } }
protected AdminHelpCommand(Groovysh shell) { super(shell, "adminhelp", "\\ah"); //$NON-NLS-1$ //$NON-NLS-2$ //hook to introduce default imports final String[] imports = GroovyAdminConsole.IMPORTS.split("\n"); //$NON-NLS-1$ for(String aimport : imports){ shell.execute(aimport); } //for backwards compatibility add aliases to 1.7 Groovy commands for (Command cmd :new ArrayList<Command>(shell.getRegistry().commands())) { if (cmd.getHidden()) { continue; } String name = cmd.getName(); if (name.startsWith(":")) { //$NON-NLS-1$ shell.execute(":alias " + name.substring(1) + " " + name); //$NON-NLS-1$ //$NON-NLS-2$ String shortCut = cmd.getShortcut(); if (shortCut.startsWith(":")) { //$NON-NLS-1$ shell.execute(":alias \\" + shortCut.substring(1) + " " + name); //$NON-NLS-1$ //$NON-NLS-2$ } } } }
/** * Retrieve a script as defined in the shell context. This allows for multi-line scripts to be submitted. */ public static String getScript(final String submittedScript, final Groovysh shell) { return submittedScript.startsWith("@") ? shell.getInterp().getContext().getProperty(submittedScript.substring(1)).toString() : submittedScript; } }
public static void main( String... args ) throws IOException { PropertyConfigurator.configure( System.getProperty( "log4j.configuration" ) ); if( args.length > 0 ) { GroovyMain.main( args ); } else { Groovysh shell = new Groovysh(); for( String name : IMPORTS ) { shell.execute( "import " + name ); } shell.run( null ); } }
private Groovysh createShell() { if (welcomeMessage != null) { writer.println(SEPARATOR_BAR); writer.println(welcomeMessage); writer.println(SEPARATOR_BAR); } binding.setVariable(OUT_KEY, out); final CompilerConfiguration config = new CompilerConfiguration(); final GroovyClassLoader loader = new GroovyClassLoader(this.getClass().getClassLoader(), config); final Groovysh shell = new Groovysh(loader, binding, new IO(in, out, out)); writer.flush(); return shell; }
@Override public Object eval(final String script) throws ScriptException { return this.shell.execute(script); }
@Override public Map<String, Object> getBindings() { return Collections.unmodifiableMap(this.shell.getInterp().getContext().getVariables()); }