本文整理匯總了Java中groovy.lang.GroovyShell.run方法的典型用法代碼示例。如果您正苦於以下問題:Java GroovyShell.run方法的具體用法?Java GroovyShell.run怎麽用?Java GroovyShell.run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類groovy.lang.GroovyShell
的用法示例。
在下文中一共展示了GroovyShell.run方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import groovy.lang.GroovyShell; //導入方法依賴的package包/類
/**
* Standalone execution for Designer and Gradle.
*/
public void run() {
startExecution();
CompilerConfiguration compilerConfig = new CompilerConfiguration(System.getProperties());
compilerConfig.setScriptBaseClass(TestCaseScript.class.getName());
Binding binding = new Binding();
binding.setVariable("testCaseRun", this);
ClassLoader classLoader = this.getClass().getClassLoader();
GroovyShell shell = new GroovyShell(classLoader, binding, compilerConfig);
shell.setProperty("out", getLog());
setupContextClassLoader(shell);
try {
shell.run(new GroovyCodeSource(getTestCase().file()), new String[0]);
finishExecution(null);
}
catch (IOException ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}
示例2: testGroovyScriptEngineVsGroovyShell
import groovy.lang.GroovyShell; //導入方法依賴的package包/類
public void testGroovyScriptEngineVsGroovyShell() throws IOException, ResourceException, ScriptException {
// @todo refactor this path
File currentDir = new File("./src/test/groovy/bugs");
String file = "bug1567_script.groovy";
Binding binding = new Binding();
GroovyShell shell = new GroovyShell(binding);
String[] test = null;
Object result = shell.run(new File(currentDir, file), test);
String[] roots = new String[]{currentDir.getAbsolutePath()};
GroovyScriptEngine gse = new GroovyScriptEngine(roots);
binding = new Binding();
// a MME was ensued here stating no 't.start()' was available
// in the script
gse.run(file, binding);
}
示例3: main
import groovy.lang.GroovyShell; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
GroovyShell shell = new GroovyShell();
//shell.run("src/main/org/codehaus/groovy/tools/DocGenerator.groovy", "org.codehaus.groovy.tools.DocGenerator.groovy", args);
shell.run(new File("src/main/groovy/org/codehaus/groovy/tools/DocGenerator.groovy"), args);
}
catch (Exception e) {
System.out.println("Failed: " + e);
e.printStackTrace();
}
}
示例4: run
import groovy.lang.GroovyShell; //導入方法依賴的package包/類
public ArquillianEnvironment run(String script) throws Exception {
CompilerConfiguration config = new CompilerConfiguration();
config.setScriptBaseClass(ArquillianEnvironment.class.getName());
GroovyShell shell = new GroovyShell(config);
// GroovyScriptEngine gse = new GroovyScriptEngine(connector);
// System.out.println(ArquillianEnvironment.class.getName());
// gse.getConfig().setScriptBaseClass(ArquillianEnvironment.class.getName());
return (ArquillianEnvironment)shell.run(script, "arquillian", new ArrayList<String>());
// Binding b = new Binding();
// return (ArquillianEnvironment)gse.run(script, b);
}
示例5: setupDecorateMethods
import groovy.lang.GroovyShell; //導入方法依賴的package包/類
/**
* Decorate Dumpling API with groovy extensions.
*/
public void setupDecorateMethods(ClassLoader cl) {
synchronized (STAR_IMPORTS) {
if (DECORATED) return;
GroovyShell shell = new GroovyShell(cl, new Binding(), getCompilerConfiguration());
try {
shell.run(
"import org.codehaus.groovy.runtime.DefaultGroovyMethods;" +
"def mc = ThreadSet.metaClass;" +
"mc.asImmutable << { -> delegate };" +
"mc.toSet << { -> delegate };" +
"mc.grep << { Object filter -> delegate.derive(DefaultGroovyMethods.grep(delegate.threadsAsSet, filter)) };" +
"mc.grep << { -> delegate.derive(delegate.threadsAsSet.grep()) };" +
"mc.findAll << { Closure closure -> delegate.derive(DefaultGroovyMethods.findAll((Object) delegate.threadsAsSet, closure)) };" +
"mc.findAll << { -> delegate.derive(delegate.threadsAsSet.findAll()) };" +
"mc.intersect << { rhs -> if (!delegate.getProcessRuntime().equals(rhs.getProcessRuntime())) throw new IllegalArgumentException('Unable to intersect ThreadSets bound to different ProcessRuntimes'); return delegate.derive(DefaultGroovyMethods.intersect(delegate.threadsAsSet, rhs.threadsAsSet)) };" +
"mc.plus << { rhs -> if (!delegate.getProcessRuntime().equals(rhs.getProcessRuntime())) throw new IllegalArgumentException('Unable to merge ThreadSets bound to different ProcessRuntimes'); return delegate.derive(DefaultGroovyMethods.plus(delegate.threadsAsSet, rhs.threadsAsSet)) };",
"dumpling-metaclass-setup",
Arrays.asList()
);
} catch (Exception ex) {
AssertionError err = new AssertionError("Unable to decorate object model");
err.initCause(ex);
throw err; // Java 6
}
DECORATED = true;
}
}
示例6: run
import groovy.lang.GroovyShell; //導入方法依賴的package包/類
@Override
public int run(ProcessStream process) throws CmdLineException {
Binding binding = CONFIG.getDefaultBinding(process, args, runtime);
if (runtime != null) {
binding.setProperty("runtime", runtime); // Compatibility
}
GroovyShell shell = new GroovyShell(binding, CONFIG.getCompilerConfiguration());
CONFIG.setupDecorateMethods();
Object exitVal = shell.run(getScript(process), "dumpling-script", args.toArray(new String[args.size()]));
if (exitVal != null) {
if (exitVal instanceof ModelObject) {
final ModelObject model = (ModelObject) exitVal;
model.toString(process.out(), porcelain ? Mode.MACHINE : Mode.HUMAN);
} else {
process.out().println(exitVal);
}
}
if (exitVal instanceof Boolean) {
return Boolean.TRUE.equals(exitVal) ? 0 : -1;
} else if (exitVal instanceof Integer) {
return ((Integer) exitVal);
}
return 0;
}
示例7: run
import groovy.lang.GroovyShell; //導入方法依賴的package包/類
@Override
public int run(ProcessStream process) throws CmdLineException {
Binding binding = CONFIG.getDefaultBinding(process, Arrays.<String>asList(), runtime);
GroovyShell shell = new GroovyShell(binding, CONFIG.getCompilerConfiguration());
CONFIG.setupDecorateMethods();
String script = String.format(SCRIPT_STUB, predicate);
ThreadSet<?, ?, ?> set = (ThreadSet<?, ?, ?>) shell.run(script, "dumpling-script", Arrays.asList());
set.toString(process.out(), porcelain ? Mode.MACHINE : Mode.HUMAN);
process.err().printf("Threads: %d%n", set.size());
return set.isEmpty() ? 1 : 0;
}
示例8: processOnce
import groovy.lang.GroovyShell; //導入方法依賴的package包/類
/**
* Process the standard, single script with args.
*/
private void processOnce() throws CompilationFailedException, IOException, URISyntaxException {
GroovyShell groovy = new GroovyShell(conf);
setupContextClassLoader(groovy);
groovy.run(getScriptSource(isScriptFile, script), args);
}
示例9: evaluate
import groovy.lang.GroovyShell; //導入方法依賴的package包/類
/** evaluate the source text against the classic AST with the JSR parser implementation*/
public Object evaluate(String theSrcText, String testName) throws Exception {
parse(theSrcText, testName); // fail early with a direct message if possible')
GroovyShell groovy = new GroovyShell(new CompilerConfiguration());
return groovy.run(theSrcText, "main", new ArrayList());
}
示例10: testMainMethod
import groovy.lang.GroovyShell; //導入方法依賴的package包/類
public void testMainMethod() throws Exception {
GroovyShell shell = new GroovyShell();
shell.run(new File("src/test/groovy/SampleMain.groovy"), new String[]{"A", "B", "C"});
}