本文整理汇总了Java中org.codehaus.groovy.tools.shell.Groovysh.execute方法的典型用法代码示例。如果您正苦于以下问题:Java Groovysh.execute方法的具体用法?Java Groovysh.execute怎么用?Java Groovysh.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.tools.shell.Groovysh
的用法示例。
在下文中一共展示了Groovysh.execute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
}
示例2: 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$
}
}
}
}
示例3: 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);
}
}
}
示例4: 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);
}
}
}
示例5: 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) {
}
}
示例6: exportGraphson
import org.codehaus.groovy.tools.shell.Groovysh; //导入方法依赖的package包/类
public static void exportGraphson(Groovysh shell, IO io, String query, String path) throws IOException {
// prepare to export
path = resolvePath(path, DEFAULT_JSON_NAME);
File file = new File(path);
FileOutputStream f = new FileOutputStream(file);
GraphSONWriter w = GraphSONWriter.build().create();
// execute the given query
shell.execute("t = " + query + ";null");
Traversal<?, Vertex> traversal = (Traversal<?, Vertex>) shell.getInterp().getContext().getProperty("t");
// try exporting
try {
w.writeVertices(f, traversal);
} catch (ClassCastException e){
shell.execute("t = " + query + ";null");
Traversal<?, Edge> edgeTraversal = (Traversal<?, Edge>) shell.getInterp().getContext().getProperty("t");
while (edgeTraversal.hasNext()){
Edge edge = edgeTraversal.next();
w.writeEdge(f, edge);
}
}
// done
f.close();
io.out.println("==> exported to " + path);
}
示例7: startGroovysh
import org.codehaus.groovy.tools.shell.Groovysh; //导入方法依赖的package包/类
/**
* @param evalString commands that will be executed at startup after loading files given with filenames param
* @param filenames files that will be loaded at startup
*/
protected void startGroovysh(Groovysh shell, String evalString, List<String> filenames) throws IOException {
int code;
SecurityManager psm = System.getSecurityManager();
System.setSecurityManager(new NoExitSecurityManager());
System.out.println(" _ __ __ _");
System.out.println(" | | / /__ _____/ /____ _ __(_)_ ______ ___");
System.out.println(" | | / / _ \\/ ___/ __/ _ \\| |/_/ / / / / __ `__ \\");
System.out.println(" | |/ / __/ / / /_/ __/> </ / /_/ / / / / / / v" + getClass().getPackage().getImplementationVersion());
System.out.println(" |___/\\___/_/ \\__/\\___/_/|_/_/\\__,_/_/ /_/ /_/");
System.out.println("");
System.out.println("Usage:");
System.out.println(" vertex1=v['vertex1'] - gets the vertex with id 'v1' and assigns it to variable 'v'");
System.out.println(" vertex1.methods - gets the methods available on the memgraph object");
System.out.println(" vertex1.properties - gets the properties available on the memgraph object");
System.out.println(" vertex1.delete() - deletes the vertex v1");
System.out.println(" p1.delete() - deletes the property currently referenced by p1");
System.out.println(" q.has('name', 'joe').vertices().each() { println it.id } - execute a query for all vertices with property 'name' equal to 'joe'");
System.out.println(" g.query('apple', auths).vertices()[0] - execute a query for 'apple' and get the first match");
System.out.println("");
System.out.println("Global Properties:");
System.out.println(" g - the Graph object");
System.out.println(" q - a query object");
System.out.println(" auths - the currently set query authorizations");
System.out.println(" time - the currently set query time");
System.out.println(" now - the current time");
System.out.println(" v - vertex map (usage: v['v1'])");
System.out.println(" e - edge map (usage: e['e1'])");
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() + ".*;");
code = shell.run(evalString, filenames);
} finally {
System.setSecurityManager(psm);
}
// Force the JVM to exit at this point, since shell could have created threads or
// popped up Swing components that will cause the JVM to linger after we have been
// asked to shutdown
System.exit(code);
}
示例8: startGroovysh
import org.codehaus.groovy.tools.shell.Groovysh; //导入方法依赖的package包/类
/**
* @param evalString commands that will be executed at startup after loading files given with filenames param
* @param filenames files that will be loaded at startup
*/
protected void startGroovysh(Groovysh shell, String evalString, List<String> filenames) throws IOException {
int code;
SecurityManager psm = System.getSecurityManager();
System.setSecurityManager(new NoExitSecurityManager());
System.out.println(" _ __ __ _");
System.out.println(" | | / /__ _____/ /____ _ __(_)_ ______ ___");
System.out.println(" | | / / _ \\/ ___/ __/ _ \\| |/_/ / / / / __ `__ \\");
System.out.println(" | |/ / __/ / / /_/ __/> </ / /_/ / / / / / / v" + getClass().getPackage().getImplementationVersion());
System.out.println(" |___/\\___/_/ \\__/\\___/_/|_/_/\\__,_/_/ /_/ /_/");
System.out.println("");
System.out.println("Usage:");
System.out.println(" vertex1=v['vertex1'] - gets the vertex with id 'v1' and assigns it to variable 'v'");
System.out.println(" vertex1.methods - gets the methods available on the Vertexium object");
System.out.println(" vertex1.properties - gets the properties available on the Vertexium object");
System.out.println(" vertex1.delete() - deletes the vertex v1");
System.out.println(" p1.delete() - deletes the property currently referenced by p1");
System.out.println(" q.has('name', 'joe').vertices().each() { println it.id } - execute a query for all vertices with property 'name' equal to 'joe'");
System.out.println(" g.query('apple', auths).vertices()[0] - execute a query for 'apple' and get the first match");
System.out.println("");
System.out.println("Global Properties:");
System.out.println(" g - the Graph object");
System.out.println(" q - a query object");
System.out.println(" auths - the currently set query authorizations");
System.out.println(" time - the currently set query time");
System.out.println(" now - the current time");
System.out.println(" v - vertex map (usage: v['v1'])");
System.out.println(" e - edge map (usage: e['e1'])");
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() + ".*;");
code = shell.run(evalString, filenames);
} finally {
System.setSecurityManager(psm);
}
// Force the JVM to exit at this point, since shell could have created threads or
// popped up Swing components that will cause the JVM to linger after we have been
// asked to shutdown
System.exit(code);
}