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


Java GroovyScriptEngine.run方法代码示例

本文整理汇总了Java中groovy.util.GroovyScriptEngine.run方法的典型用法代码示例。如果您正苦于以下问题:Java GroovyScriptEngine.run方法的具体用法?Java GroovyScriptEngine.run怎么用?Java GroovyScriptEngine.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在groovy.util.GroovyScriptEngine的用法示例。


在下文中一共展示了GroovyScriptEngine.run方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGroovyScriptEngineVsGroovyShell

import groovy.util.GroovyScriptEngine; //导入方法依赖的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);
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:Groovy1567_Bug.java

示例2: getGroovyRenderer

import groovy.util.GroovyScriptEngine; //导入方法依赖的package包/类
private PrimitiveRenderer getGroovyRenderer() throws IOException, ResourceException, ScriptException {
  if (this.groovyRenderer == null) {
    GroovyScriptEngine gse = this.getGroovyScriptEngine();
    Binding binding = this.getBinding();
    gse.run(this.groovyFile.getName(), binding);
    this.groovyRenderer = (PrimitiveRenderer) binding.getVariable("renderer");
  }
  return this.groovyRenderer;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:10,代码来源:GroovyPrimitiveRenderer.java

示例3: executeScriptByPath

import groovy.util.GroovyScriptEngine; //导入方法依赖的package包/类
@Override
public void executeScriptByPath(String scriptPath, Map<Object, Object> context) {
    try {
        String scriptName = PathUtil.fileName(scriptPath);
        String scriptDir = PathUtil.parentFolder(scriptPath);

        GroovyScriptEngine gse = new GroovyScriptEngine(scriptDir);
        Binding binding = new Binding(context);
        gse.run(scriptName, binding);
    } catch (Exception e) {
        throw new CloudRuntimeException(e);
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:14,代码来源:GroovyFacadeImpl.java

示例4: runSjsCompilation

import groovy.util.GroovyScriptEngine; //导入方法依赖的package包/类
private void runSjsCompilation() throws IOException, ResourceException,
    ScriptException, DependencyResolutionRequiredException {
  Properties projectProperties = project.getProperties();
  projectProperties.put("srcDir", srcDir.getAbsolutePath());
  projectProperties.put("outputDir", outputDir.getAbsolutePath());
  projectProperties.put("modelOutputFileName", modelOutputFileName);
  projectProperties.put("viewOutputFileName", viewOutputFileName);
  projectProperties.put("backOutputFileName", backOutputFileName);
  projectProperties.put("frontOutputFileName", frontOutputFileName);

  List<URL> classpath;
  classpath = new ArrayList<>();
  classpath.add(srcDir.toURI().toURL());
  List<String> compileClasspathElements = project
      .getCompileClasspathElements();
  for (String element : compileClasspathElements) {
    if (!element.equals(project.getBuild().getOutputDirectory())) {
      File elementFile = new File(element);
      getLog().debug(
          "Adding element to plugin classpath " + elementFile.getPath());
      URL url = elementFile.toURI().toURL();
      classpath.add(url);
    }
  }
  GroovyScriptEngine gse = new GroovyScriptEngine(
      classpath.toArray(new URL[classpath.size()]));
  Binding binding = new Binding();
  binding.setVariable("project", project);
  binding.setVariable("fail", new FailClosure());
  String refinedApplicationFileName = applicationFileName;
  if (!new File(srcDir + File.separator + applicationFileName).exists()) {
    if (applicationFileName.contains(SJSEXT)) {
      refinedApplicationFileName = applicationFileName.replaceAll(SJSEXT, GROOVY_EXT);
    } else if(applicationFileName.contains(GROOVY_EXT)) {
      refinedApplicationFileName = applicationFileName.replaceAll(GROOVY_EXT, SJSEXT);
    }
  }
  gse.run(refinedApplicationFileName, binding);
}
 
开发者ID:jspresso,项目名称:jspresso-ce,代码行数:40,代码来源:SjsMojo.java

示例5: transformRawDataToGraphml

import groovy.util.GroovyScriptEngine; //导入方法依赖的package包/类
public void transformRawDataToGraphml(Reader in, Writer out) {
        try {

            GPathResult response = new XmlSlurper().parse(new InputSource(in));
            Binding binding = new Binding();
            binding.setProperty("input", response);
            binding.setProperty("output", out);

           // binding = new Binding();
           // Expect4Groovy.createBindings(connection, binding, true);
           // binding.setProperty("params", params);

           // String gseRoots = new File().toURI().toURL().toString();
            String[] roots =  new String[]{projectPath+"/iDiscover/conf/groovy/"+File.separator};
            GroovyScriptEngine gse = new GroovyScriptEngine(roots);
            gse.run("RawData2GraphmlTransformer.groovy", binding);

//            Class clazz = Class.forName(new File(projectPath,rawData2GraphmlGroovyTransformer).toURI().toURL().toString());
//            Constructor constructor = clazz.getDeclaredConstructor(Binding.class);
//            Script script = (Script) constructor.newInstance(binding);
//            script.run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
开发者ID:iTransformers,项目名称:netTransformer,代码行数:26,代码来源:GraphmlFileLogGroovyDiscoveryListener.java

示例6: launch

import groovy.util.GroovyScriptEngine; //导入方法依赖的package包/类
public Object launch(List<String> roots, String scriptName, Map<String, Object> params) throws IOException, ResourceException, ScriptException {
    CLIConnection conn = createCliConnection(params);
    try {
        conn.connect(params);
        Binding binding = new Binding();
        Expect4Groovy.createBindings(conn, binding, true);
        binding.setProperty("params", params);
        GroovyScriptEngine gse = new GroovyScriptEngine(roots.toArray(new String[roots.size()]));
        return gse.run(scriptName, binding);
    } finally {
        conn.disconnect();
    }
}
 
开发者ID:iTransformers,项目名称:expect4groovy,代码行数:14,代码来源:Expect4GroovyScriptLauncher.java

示例7: runScript

import groovy.util.GroovyScriptEngine; //导入方法依赖的package包/类
/**
 * Run runScript.groovy script in workingDir directory.
 *
 * @param workingDir - Directory with groovy script.
 * @param file - groovy script to run
 * @throws Exception if an error occurs
 */
private static void runScript( String workingDir, String file )
    throws Exception
{
    File verify = new File( workingDir + "/" + file + ".groovy" );
    if ( !verify.isFile() )
    {
        return;
    }
    Binding binding = new Binding();
    binding.setVariable( "basedir", workingDir );
    GroovyScriptEngine engine = new GroovyScriptEngine( workingDir );
    engine.run( file + ".groovy", binding );
}
 
开发者ID:release-engineering,项目名称:pom-manipulation-ext,代码行数:21,代码来源:TestUtils.java

示例8: test

import groovy.util.GroovyScriptEngine; //导入方法依赖的package包/类
private void test(String script, MockGitblit gitblit, MockLogger logger, MockClientLogger clientLogger,
		List<ReceiveCommand> commands, RepositoryModel repository) throws Exception {

	UserModel user = new UserModel("mock");

	String gitblitUrl = GitBlitSuite.url;

	File groovyDir = GitBlit.getGroovyScriptsFolder();
	GroovyScriptEngine gse = new GroovyScriptEngine(groovyDir.getAbsolutePath());

	Binding binding = new Binding();
	binding.setVariable("gitblit", gitblit);
	binding.setVariable("repository", repository);
	binding.setVariable("user", user);
	binding.setVariable("commands", commands);
	binding.setVariable("url", gitblitUrl);
	binding.setVariable("logger", logger);
	binding.setVariable("clientLogger", clientLogger);

	Object result = gse.run(script, binding);
	if (result instanceof Boolean) {
		if (!((Boolean) result)) {
			throw new GitBlitException(MessageFormat.format(
					"Groovy script {0} has failed!  Hook scripts aborted.", script));
		}
	}
}
 
开发者ID:warpfork,项目名称:gitblit,代码行数:28,代码来源:GroovyScriptTest.java


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