当前位置: 首页>>代码示例>>Java>>正文


Java Groovysh类代码示例

本文整理汇总了Java中org.codehaus.groovy.tools.shell.Groovysh的典型用法代码示例。如果您正苦于以下问题:Java Groovysh类的具体用法?Java Groovysh怎么用?Java Groovysh使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Groovysh类属于org.codehaus.groovy.tools.shell包,在下文中一共展示了Groovysh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldPluginSugar

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
@Test
public void shouldPluginSugar() throws Exception {
    MetaRegistryUtil.clearRegistry(new HashSet<>(Arrays.asList(TinkerGraph.class)));

    final SugarGremlinPlugin plugin = new SugarGremlinPlugin();

    final Groovysh groovysh = new Groovysh();

    final Map<String, Object> env = new HashMap<>();
    env.put("ConsolePluginAcceptor.io", new IO());
    env.put("ConsolePluginAcceptor.shell", groovysh);

    final SpyPluginAcceptor spy = new SpyPluginAcceptor(groovysh::execute, () -> env);
    plugin.pluginTo(spy);

    groovysh.getInterp().getContext().setProperty("g", TinkerFactory.createClassic());
    assertEquals(6l, ((GraphTraversal) groovysh.execute("g.traversal().V()")).count().next());
    assertEquals(6l, ((GraphTraversal) groovysh.execute("g.traversal().V")).count().next());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:20,代码来源:SugarGremlinPluginTest.java

示例2: createShell

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
private Groovysh createShell() {
    final Groovysh shell = getGroovysh();

    // Add a hook to display some status when shutting down...
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        //
        // FIXME: We need to configure JLine to catch CTRL-C for us... Use gshell-io's InputPipe
        //

        if (shell.getHistory() != null) {
            try {
                shell.getHistory().flush();
            } catch (IOException e) {
                System.out.println("Could not flush history.");
            }
        }
    }));

    shell.register(new GetAuthsCommand(shell));
    shell.register(new SetAuthsCommand(shell));
    shell.register(new GetTimeCommand(shell));
    shell.register(new SetTimeCommand(shell));
    shell.register(new NowCommand(shell));
    return shell;
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:26,代码来源:MemgraphShell.java

示例3: loadDefaultScripts

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "serial"})
private void loadDefaultScripts(final Groovysh shell) {
	if (!defaultScripts.isEmpty()) {
		Closure<Groovysh> defaultResultHook = shell.getResultHook();

		try {
			// Set a "no-op closure so we don't get per-line value output when evaluating the default script
			shell.setResultHook(new Closure<Groovysh>(this) {
				@Override
				public Groovysh call(Object... args) {
					return shell;
				}
			});

			org.codehaus.groovy.tools.shell.Command cmd = shell.getRegistry().find("load");
			for (String script : defaultScripts) {
				cmd.execute(asList(script));
			}
		} finally {
			// Restoring original result hook
			shell.setResultHook(defaultResultHook);
		}
	}
}
 
开发者ID:jesse-gallagher,项目名称:xsp-groovy-shell,代码行数:25,代码来源:GroovyShellCommand.java

示例4: shouldPluginUtilities

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
@Test
public void shouldPluginUtilities() throws Exception {
    final UtilitiesGremlinPlugin plugin = new UtilitiesGremlinPlugin();

    final Groovysh groovysh = new Groovysh();
    groovysh.getInterp().getContext().setProperty("g", TinkerFactory.createClassic());

    final Map<String, Object> env = new HashMap<>();
    env.put("ConsolePluginAcceptor.io", new IO());
    env.put("ConsolePluginAcceptor.shell", groovysh);

    final SpyPluginAcceptor spy = new SpyPluginAcceptor(groovysh::execute, () -> env);
    plugin.pluginTo(spy);

    assertThat(groovysh.execute("describeGraph(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph)").toString(), containsString("IMPLEMENTATION - org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph"));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:UtilitiesGremlinPluginTest.java

示例5: pluginTo

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * <p/>
 * Provides a base implementation for plugins by grabbing the console environment variables and assigning them
 * to the {@link #io} and {@link #shell} member variables.
 *
 * @throws IllegalEnvironmentException if {@link #requireConsoleEnvironment} is set to true and if either
 *                                     the {@link #io} and {@link #shell} member variables are null.
 */
@Override
public void pluginTo(final PluginAcceptor pluginAcceptor) throws IllegalEnvironmentException, PluginInitializationException {
    final Map<String, Object> environment = pluginAcceptor.environment();
    io = (IO) environment.get(ENV_CONSOLE_IO);
    shell = (Groovysh) environment.get(ENV_CONSOLE_SHELL);

    if (requireConsoleEnvironment && (null == io || null == shell))
        throw new IllegalEnvironmentException(this, ENV_CONSOLE_SHELL, ENV_CONSOLE_IO);

    try {
        afterPluginTo(pluginAcceptor);
    } catch (PluginInitializationException pie) {
        throw pie;
    } catch (Exception ex) {
        throw new PluginInitializationException(ex);
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:27,代码来源:AbstractGremlinPlugin.java

示例6: interpretFileContent

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
/**
 * Interpret file content in given shell.
 *
 * @param script Script file that should be interpreted
 * @param shell Shell where the script should be interpreted
 * @throws IOException
 */
private static void interpretFileContent(File script, Groovysh shell) throws IOException {
  BufferedReader in = new BufferedReader(new FileReader(script));
  String line;

  // Iterate over all lines and executed them one by one
  while ((line = in.readLine()) != null) {

    // Skip comments and empty lines as we don't need to interpret those
    if(line.isEmpty() || line.startsWith("#")) {
      continue;
    }

    // Render shell and command to get user perception that it was run as usual
    print(shell.renderPrompt());
    println(line);

    // Manually trigger command line parsing
    Object result = shell.execute(line);

    if (result == null) {
      break;
    }
  }
}
 
开发者ID:vybs,项目名称:sqoop-on-spark,代码行数:32,代码来源:SqoopShell.java

示例7: GroovyInterpreter

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
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);
}
 
开发者ID:jonhare,项目名称:COMP6237,代码行数:26,代码来源:GroovyInterpreter.java

示例8: AdminHelpCommand

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
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$
			}
		}
	}
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:24,代码来源:AdminHelpCommand.java

示例9: initializeShellWithScript

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
private void initializeShellWithScript(final IO io, final String initScriptFile, final Groovysh groovy) {
    if (initScriptFile != null) {
        String line = "";
        try {
            final BufferedReader reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream(initScriptFile), Charset.forName("UTF-8")));
            while ((line = reader.readLine()) != null) {
                groovy.execute(line);
            }

            reader.close();
        } catch (FileNotFoundException fnfe) {
            io.err.println(String.format("Gremlin initialization file not found at [%s].", initScriptFile));
            System.exit(1);
        } catch (IOException ioe) {
            io.err.println(String.format("Bad line in Gremlin initialization file at [%s].", line));
            System.exit(1);
        }
    }
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:21,代码来源:Console.java

示例10: interpretFileContent

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
/**
 * ִ�нű��ļ�
 * @param script
 * @param shell
 * @throws IOException
 */
private static void interpretFileContent(File script, Groovysh shell) throws IOException {
	BufferedReader in = new BufferedReader(new FileReader(script));
	String line;
	// Iterate over all lines and executed them one by one
	while ((line = in.readLine()) != null) {

		// Skip comments and empty lines as we don't need to interpret those
		if (line.isEmpty() || line.startsWith("#")) {
			continue;
		}
		// Render shell and command to get user perception that it was run
		// as usual
		ShellEnvironment.print(shell.renderPrompt());
		ShellEnvironment.println(line);
		// Manually trigger command line parsing
		Object result = shell.execute(line);
		if (result != null) {
			ShellEnvironment.println(result);
		}
	}
}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:28,代码来源:AquilaShell.java

示例11: setGroovyShell

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
private void setGroovyShell(Groovysh groovysh, GroovyShell groovyShell) throws NoSuchFieldException, IllegalAccessException {
    Field interpField = groovysh.getClass().getDeclaredField("interp");
    interpField.setAccessible(true);

    Field shellField = Interpreter.class.getDeclaredField("shell");
    shellField.setAccessible(true);

    Interpreter interpreter = (Interpreter) interpField.get(groovysh);
    shellField.set(interpreter, groovyShell);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:11,代码来源:MemgraphShell.java

示例12: shouldFailWithoutUtilitiesPlugin

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
@Test
public void shouldFailWithoutUtilitiesPlugin() throws Exception {
    final Groovysh groovysh = new Groovysh();
    try {
        groovysh.execute("describeGraph(g.class)");
        fail("Utilities were not loaded - this should fail.");
    } catch (Exception ignored) {
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:10,代码来源:UtilitiesGremlinPluginTest.java

示例13: shouldConstructRemoteAcceptorWhenInConsoleEnvironment

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
@Test
public void shouldConstructRemoteAcceptorWhenInConsoleEnvironment() throws Exception {
    final DriverGremlinPlugin plugin = new DriverGremlinPlugin();
    final Map<String, Object> env = new HashMap<>();
    env.put("ConsolePluginAcceptor.io", new IO());
    env.put("ConsolePluginAcceptor.shell", new Groovysh());
    final SpyPluginAcceptor spy = new SpyPluginAcceptor(() -> env);
    plugin.pluginTo(spy);

    assertThat(plugin.remoteAcceptor().isPresent(), is(true));
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:12,代码来源:DriverGremlinPluginTest.java

示例14: shouldPluginUtilities

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
@Test
public void shouldPluginUtilities() throws Exception {
    final UtilitiesGremlinPlugin plugin = new UtilitiesGremlinPlugin();

    final Groovysh groovysh = new Groovysh();
    groovysh.getInterp().getContext().setProperty("g", TinkerFactory.createClassic());

    final PluggedIn pluggedIn = new PluggedIn(plugin, groovysh, io, false);
    pluggedIn.activate();

    assertThat(groovysh.execute("describeGraph(org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph)").toString(), containsString("IMPLEMENTATION - org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph"));
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:13,代码来源:UtilitiesGremlinPluginTest.java

示例15: pluginTo

import org.codehaus.groovy.tools.shell.Groovysh; //导入依赖的package包/类
@Override
public void pluginTo(final PluginAcceptor pluginAcceptor) {
	pluginAcceptor.addImports(IMPORTS);
	final Groovysh groovy = (Groovysh) pluginAcceptor.environment().get("ConsolePluginAcceptor.shell");
	final IO io = (IO) pluginAcceptor.environment().get("ConsolePluginAcceptor.io");      
	groovy.register(new Bio4jCommand(groovy, io));
}
 
开发者ID:bio4j,项目名称:exporter,代码行数:8,代码来源:Bio4jGremlinPlugin.java


注:本文中的org.codehaus.groovy.tools.shell.Groovysh类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。