本文整理了Java中groovy.lang.GroovyShell.<init>()
方法的一些代码示例,展示了GroovyShell.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GroovyShell.<init>()
方法的具体详情如下:
包路径:groovy.lang.GroovyShell
类名称:GroovyShell
方法名:<init>
[英]Creates a child shell using a new ClassLoader which uses the parent shell's class loader as its parent
[中]使用新的类加载器创建子shell,该类加载器将父shell的类加载器用作其父shell
代码示例来源:origin: jenkinsci/jenkins
/**
* Can be used to customize the environment in which the script runs.
*/
protected GroovyShell createShell() {
return new GroovyShell(loader, bindings);
}
代码示例来源:origin: groovy/groovy-core
public GroovyShell getShell() {
if (shell == null) {
shell = new GroovyShell();
}
return shell;
}
代码示例来源:origin: groovy/groovy-core
/**
* @return a newly created GroovyShell using the same variable scope but a new class loader
*/
protected GroovyShell getEvalShell() {
return new GroovyShell(shell);
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Loads a set of given beans
* @param resources The resources to load
* @throws IOException
*/
public void loadBeans(Resource[] resources) throws IOException {
Closure beans = new Closure(this){
@Override
public Object call(Object... args) {
return beans((Closure)args[0]);
}
};
Binding b = new Binding();
b.setVariable("beans", beans);
GroovyShell shell = classLoader != null ? new GroovyShell(classLoader,b) : new GroovyShell(b);
for (Resource resource : resources) {
shell.evaluate(new InputStreamReader(resource.getInputStream()));
}
}
代码示例来源:origin: spockframework/spock
private GroovyShell createShell() {
CompilerConfiguration compilerSettings = new CompilerConfiguration();
compilerSettings.setScriptBaseClass(DelegatingScript.class.getName());
return new GroovyShell(getClass().getClassLoader(), new Binding(), compilerSettings);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public Object evaluate(ScriptSource script, @Nullable Map<String, Object> arguments) {
GroovyShell groovyShell = new GroovyShell(
this.classLoader, new Binding(arguments), this.compilerConfiguration);
try {
String filename = (script instanceof ResourceScriptSource ?
((ResourceScriptSource) script).getResource().getFilename() : null);
if (filename != null) {
return groovyShell.evaluate(script.getScriptAsString(), filename);
}
else {
return groovyShell.evaluate(script.getScriptAsString());
}
}
catch (IOException ex) {
throw new ScriptCompilationException(script, "Cannot access Groovy script", ex);
}
catch (GroovyRuntimeException ex) {
throw new ScriptCompilationException(script, ex);
}
}
代码示例来源:origin: jenkinsci/jenkins
public String call() throws RuntimeException {
// if we run locally, cl!=null. Otherwise the delegating classloader will be available as context classloader.
if (cl==null) cl = Thread.currentThread().getContextClassLoader();
CompilerConfiguration cc = new CompilerConfiguration();
cc.addCompilationCustomizers(new ImportCustomizer().addStarImports(
"jenkins",
"jenkins.model",
"hudson",
"hudson.model"));
GroovyShell shell = new GroovyShell(cl,new Binding(),cc);
StringWriter out = new StringWriter();
PrintWriter pw = new PrintWriter(out);
shell.setVariable("out", pw);
try {
Object output = shell.evaluate(script);
if(output!=null)
pw.println("Result: "+output);
} catch (Throwable t) {
Functions.printStackTrace(t, pw);
}
return out.toString();
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Parses the bean definition groovy script by first exporting the given {@link Binding}.
*/
public void parse(InputStream script, Binding binding) {
if (script==null)
throw new IllegalArgumentException("No script is provided");
setBinding(binding);
CompilerConfiguration cc = new CompilerConfiguration();
cc.setScriptBaseClass(ClosureScript.class.getName());
GroovyShell shell = new GroovyShell(classLoader,binding,cc);
ClosureScript s = (ClosureScript)shell.parse(new InputStreamReader(script));
s.setDelegate(this);
s.run();
}
代码示例来源:origin: groovy/groovy-core
public void testMe () {
new GroovyShell().evaluate("groovy.bugs.Autobox.Util.printByte(\"1\", Byte.valueOf((byte)1));");
new GroovyShell().evaluate("groovy.bugs.Autobox.Util.printByte(\"1\", (byte)1);");
}
}
代码示例来源:origin: groovy/groovy-core
public XmlTemplateEngine(String indentation, boolean validating) throws SAXException, ParserConfigurationException {
this(new XmlParser(validating, true), new GroovyShell());
this.xmlParser.setTrimWhitespace(true);
setIndentation(indentation);
}
代码示例来源:origin: groovy/groovy-core
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/org/codehaus/groovy/tools/DocGenerator.groovy"), args);
}
catch (Exception e) {
System.out.println("Failed: " + e);
e.printStackTrace();
}
}
}
代码示例来源:origin: groovy/groovy-core
public void testClassLoader() {
Binding context = new Binding();
CompilerConfiguration config = new CompilerConfiguration();
config.setScriptBaseClass(DerivedScript.class.getName());
GroovyShell shell = new GroovyShell(context, config);
String script = "evaluate '''\n"+
"class XXXX{}\n"+
"assert evaluate('XXXX') == XXXX\n"+
"'''";
shell.evaluate(script);
}
代码示例来源:origin: groovy/groovy-core
public void testScriptNameMangling() {
String script = "this.getClass().getName()";
GroovyShell shell = new GroovyShell();
String name = (String) shell.evaluate(script,"a!b");
assertEquals("a_b", name);
}
代码示例来源:origin: groovy/groovy-core
public void testExecuteScript() {
GroovyShell shell = new GroovyShell();
try {
Object result = shell.evaluate(script1, "Test.groovy");
assertEquals(new Integer(1), result);
}
catch (Exception e) {
fail(e.toString());
}
}
代码示例来源:origin: spring-projects/spring-framework
GroovyShell shell = new GroovyShell(getBeanClassLoader(), binding);
shell.evaluate(encodedResource.getReader(), "beans");
代码示例来源:origin: jenkinsci/jenkins
protected int run() throws Exception {
// this allows the caller to manipulate the JVM state, so require the execute script privilege.
Jenkins.getActiveInstance().checkPermission(Jenkins.RUN_SCRIPTS);
Binding binding = new Binding();
binding.setProperty("out",new PrintWriter(stdout,true));
binding.setProperty("stdin",stdin);
binding.setProperty("stdout",stdout);
binding.setProperty("stderr",stderr);
binding.setProperty("channel",channel);
if (channel != null) {
String j = getClientEnvironmentVariable("JOB_NAME");
if (j != null) {
Item job = Jenkins.getActiveInstance().getItemByFullName(j);
binding.setProperty("currentJob", job);
String b = getClientEnvironmentVariable("BUILD_NUMBER");
if (b != null && job instanceof AbstractProject) {
Run r = ((AbstractProject) job).getBuildByNumber(Integer.parseInt(b));
binding.setProperty("currentBuild", r);
}
}
}
GroovyShell groovy = new GroovyShell(Jenkins.getActiveInstance().getPluginManager().uberClassLoader, binding);
groovy.run(loadScript(),"RemoteClass",remaining.toArray(new String[remaining.size()]));
return 0;
}
代码示例来源:origin: groovy/groovy-core
/**
* Test for GROOVY-6615
* @throws Exception
*/
public void testScriptWithCustomBodyMethod() throws Exception {
Binding context = new Binding();
CompilerConfiguration config = new CompilerConfiguration();
config.setScriptBaseClass(BaseScriptCustomBodyMethod.class.getName());
GroovyShell shell = new GroovyShell(context, config);
Object result = shell.evaluate("'I like ' + cheese");
assertEquals("I like Cheddar", result);
}
代码示例来源:origin: groovy/groovy-core
public void test_StaticImport1() throws Exception {
//GROOVY-3711: The following call now results in a valid script class node, so foo.Bar needs to get resolved.
GroovyShell groovyShell = new GroovyShell();
compile("package foo; class Bar{}", groovyShell);
assertNotNull(compile("import static foo.Bar.mooky", groovyShell));
}
代码示例来源:origin: groovy/groovy-core
public void testScriptWithDerivedBaseClass() throws Exception {
Binding context = new Binding();
CompilerConfiguration config = new CompilerConfiguration();
config.setScriptBaseClass(DerivedScript.class.getName());
GroovyShell shell = new GroovyShell(context, config);
Object result = shell.evaluate("x = 'abc'; doSomething(cheese)");
assertEquals("I like Cheddar", result);
assertEquals("abc", context.getVariable("x"));
}
代码示例来源:origin: groovy/groovy-core
public void testClassPropsGroovy() {
Object testObject = new GroovyShell().evaluate("class Test {def meth1(a,b){}}\nreturn new Test()");
Inspector insp = new Inspector(testObject);
String[] classProps = insp.getClassProps();
assertEquals("package n/a", classProps[Inspector.CLASS_PACKAGE_IDX]);
assertEquals("public class Test", classProps[Inspector.CLASS_CLASS_IDX]);
assertEquals("implements GroovyObject ", classProps[Inspector.CLASS_INTERFACE_IDX]);
assertEquals("extends Object", classProps[Inspector.CLASS_SUPERCLASS_IDX]);
assertEquals("is Primitive: false, is Array: false, is Groovy: true", classProps[Inspector.CLASS_OTHER_IDX]);
}
内容来源于网络,如有侵权,请联系作者删除!