groovy.lang.GroovyShell.setProperty()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中groovy.lang.GroovyShell.setProperty()方法的一些代码示例,展示了GroovyShell.setProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GroovyShell.setProperty()方法的具体详情如下:
包路径:groovy.lang.GroovyShell
类名称:GroovyShell
方法名:setProperty

GroovyShell.setProperty介绍

暂无

代码示例

代码示例来源:origin: mulesoft/mule

private void executeGroovyScript() {
 try {
  GroovyShell shell = new GroovyShell();
  resolvePropertiesUsingLambdas();
  properties.forEach((key, value) -> shell.setProperty(key, value));
  shell.evaluate(IOUtils.getResourceAsString(scriptPath, GroovyScriptExecutor.class));
  LOGGER.info("Groovy script executed");
 } catch (IOException e) {
  throw new RuntimeException("Error reading Groovy script: " + scriptPath, e);
 } catch (CompilationFailedException e) {
  throw new RuntimeException("Compilation error were found on: " + scriptPath, e);
 }
}

代码示例来源:origin: pl.edu.icm.synat/synat-console-core

private GroovyShell prepareScript() {
  GroovyShell shell = new GroovyShell();
  for (Map.Entry<String, Object> entry : properties.entrySet()) {
    shell.setProperty(entry.getKey(), entry.getValue());
  }
  return shell;
}

代码示例来源:origin: org.ow2.bonita/bonita-server

private Object modifyJavaObject(final Object data, final String variableName,
  final String groovyPlaceholderAccessExpression, final String setterName, final Object variableValue,
  final ClassLoader classLoader) {
 final GroovyShell shell = new GroovyShell(classLoader);
 shell.setProperty(variableName, data);
 shell.setProperty("__variableValue__", variableValue);
 final StringBuilder script = new StringBuilder();
 script.append("def __tmp__ =");
 if (groovyPlaceholderAccessExpression != null && groovyPlaceholderAccessExpression.trim().length() > 0) {
  script.append(groovyPlaceholderAccessExpression);
 } else {
  script.append(variableName);
 }
 script.append(";\n");
 script.append("__tmp__.");
 script.append(setterName);
 script.append("(__variableValue__);\n");
 script.append(variableName);
 return shell.evaluate(script.toString());
}

代码示例来源:origin: org.mule.tools.maven/mule-maven-plugin

protected void executeGroovyScript() throws MojoExecutionException
{
  GroovyShell shell = new GroovyShell();
  getLog().info("executing script: " + script.getAbsolutePath());
  shell.setProperty("basedir",mavenProject.getBasedir());
  for (Map.Entry entry: mavenProject.getProperties().entrySet())
  {
    shell.setProperty((String) entry.getKey(), entry.getValue());
  }
  getLog().info(mavenProject.getBasedir().getAbsolutePath());
  try
  {
    shell.evaluate(readFile(script.getAbsolutePath()));
  }
  catch (IOException e)
  {
    throw new MojoExecutionException("error executing script: " + script.getAbsolutePath() + "\n" + e.getMessage() );
  }
}

代码示例来源:origin: io.vertx/vertx-lang-groovy-gen

@Test
 public void testInvokeRawMethod() throws Exception {
  ListMethods itf = list -> {
   JsonObject combined = new JsonObject();
   list.forEach(combined::mergeIn);
   return combined;
  };
  CompilerConfiguration config = new CompilerConfiguration();
  Properties props = new Properties();
  props.setProperty("groovy.disabled.global.ast.transformations", "io.vertx.lang.groovy.VertxTransformation");
  config.configure(props);
  GroovyShell shell = new GroovyShell(config);
  shell.setProperty("itf", itf);
  Object o = shell.evaluate("return itf.jsonList([new io.vertx.core.json.JsonObject().put('foo', 'foo_value'), new io.vertx.core.json.JsonObject().put('bar', 'bar_value')])");
  JsonObject result = (JsonObject) o;
  assertEquals(result, new JsonObject().put("foo", "foo_value").put("bar", "bar_value"));
 }
}

相关文章