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


Java Script.run方法代码示例

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


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

示例1: execute

import groovy.lang.Script; //导入方法依赖的package包/类
public GroovyResult execute(GroovyResult result, final Script groovyScript, final Map<String, Object> variables)
{
  if (variables != null) {
    final Binding binding = groovyScript.getBinding();
    for (final Map.Entry<String, Object> entry : variables.entrySet()) {
      binding.setVariable(entry.getKey(), entry.getValue());
    }
  }
  if (result == null) {
    result = new GroovyResult();
  }
  Object res = null;
  try {
    res = groovyScript.run();
  } catch (final Exception ex) {
    log.info("Groovy-Execution-Exception: " + ex.getMessage(), ex);
    return new GroovyResult(ex);
  }
  result.setResult(res);
  return result;
}
 
开发者ID:micromata,项目名称:projectforge-webapp,代码行数:22,代码来源:GroovyExecutor.java

示例2: runScript

import groovy.lang.Script; //导入方法依赖的package包/类
/**
 * Returns the builder object for creating new output variable value.
 */
protected void runScript(String mapperScript, Slurper slurper, Builder builder)
        throws ActivityException, TransformerException {

    CompilerConfiguration compilerConfig = new CompilerConfiguration();
    compilerConfig.setScriptBaseClass(CrossmapScript.class.getName());

    Binding binding = new Binding();
    binding.setVariable("runtimeContext", getRuntimeContext());
    binding.setVariable(slurper.getName(), slurper.getInput());
    binding.setVariable(builder.getName(), builder);
    GroovyShell shell = new GroovyShell(getPackage().getCloudClassLoader(), binding, compilerConfig);
    Script gScript = shell.parse(mapperScript);
    // gScript.setProperty("out", getRuntimeContext().get);
    gScript.run();
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:19,代码来源:CrossmapActivity.java

示例3: processScenario

import groovy.lang.Script; //导入方法依赖的package包/类
/**
 * Post process every stored request just before it get saved to disk
 *
 * @param sampler recorded http-request (sampler)
 * @param tree   HashTree (XML like data structure) that represents exact recorded sampler
 */
public void processScenario(HTTPSamplerBase sampler, HashTree tree, Arguments userVariables, JMeterRecorder recorder)
{
    Binding binding = new Binding();
    binding.setVariable(ScriptBindingConstants.LOGGER, LOG);
    binding.setVariable(ScriptBindingConstants.SAMPLER, sampler);
    binding.setVariable(ScriptBindingConstants.TREE, tree);
    binding.setVariable(ScriptBindingConstants.CONTEXT, recorder.getContext());
    binding.setVariable(ScriptBindingConstants.JSFLIGHT, JMeterJSFlightBridge.getInstance());
    binding.setVariable(ScriptBindingConstants.USER_VARIABLES, userVariables);
    binding.setVariable(ScriptBindingConstants.CLASSLOADER, classLoader);

    Script compiledProcessScript = ScriptEngine.getScript(getScenarioProcessorScript());
    if (compiledProcessScript == null)
    {
        return;
    }
    compiledProcessScript.setBinding(binding);
    LOG.info("Run compiled script");
    try {
        compiledProcessScript.run();
    } catch (Throwable throwable) {
        LOG.error(throwable.getMessage(), throwable);
    }
}
 
开发者ID:d0k1,项目名称:jsflight,代码行数:31,代码来源:JMeterScriptProcessor.java

示例4: evaluate

import groovy.lang.Script; //导入方法依赖的package包/类
public Object evaluate(final String expression, final Map<String, ?> values) throws ExpressionEvaluationException {
    LOG.debug("Evaluating Groovy expression: {1}", expression);
    try {
        final ObjectCache<String, Script> scriptCache = threadScriptCache.get();
        Script script = scriptCache.get(expression);
        if (script == null) {
            script = GROOVY_SHELL.parse(expression);
            scriptCache.put(expression, script);
        }

        final Binding binding = new Binding();
        for (final Entry<String, ?> entry : values.entrySet()) {
            binding.setVariable(entry.getKey(), entry.getValue());
        }
        script.setBinding(binding);
        return script.run();
    } catch (final Exception ex) {
        throw new ExpressionEvaluationException("Evaluating script with Groovy failed.", ex);
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:21,代码来源:ExpressionLanguageGroovyImpl.java

示例5: testGroovyShell

import groovy.lang.Script; //导入方法依赖的package包/类
@Test
public void testGroovyShell() throws Exception {
    GroovyShell groovyShell = new GroovyShell();
    final String s = "x  > 2  &&  y  > 1";
    Script script = groovyShell.parse(s);

    Binding binding = new Binding();
    binding.setProperty("x",5);
    binding.setProperty("y",3);
    script.setBinding(binding);

    Object result = script.run();
    Assert.assertEquals(true, result);
    log.debug("evaluating [{}] with (x,y)=({},{}) => {}\n", s,
            script.getBinding().getProperty("x"), script.getBinding().getProperty("y"), result);

    binding.setProperty("y",0);
    result = script.run();
    Assert.assertEquals(false, result);
    log.debug("evaluating [{}] with (x,y)=({},{}) => {}\n", s,
            binding.getProperty("x"), binding.getProperty("y"), result);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:23,代码来源:GroovyTest.java

示例6: locate

import groovy.lang.Script; //导入方法依赖的package包/类
@Override
public GPathResult locate(GPathResult root, OfflineOptions options) throws Exception {
    boolean domain = Type.of(root) == Type.DOMAIN;

    Script script = (Script) (
            domain ? DOMAIN_SCRIPT_CLASS.newInstance() : STANDALONE_OR_HOST_SCRIPT_CLASS.newInstance()
    );
    script.setProperty("root", root);
    if (domain) {
        String defaultSocketBindingGroup = options.defaultProfile + "-sockets";
        if ("default".equals(options.defaultProfile)) {
            defaultSocketBindingGroup = "standard-sockets";
        }
        script.setProperty("defaultSocketBindingGroup", defaultSocketBindingGroup);
    }
    return (GPathResult) script.run();
}
 
开发者ID:wildfly-extras,项目名称:creaper,代码行数:18,代码来源:Subtree.java

示例7: eval

import groovy.lang.Script; //导入方法依赖的package包/类
/**
 * Evaluate an expression.
 */
public Object eval(String source, int lineNo, int columnNo, Object script) throws BSFException {
    try {
        Class scriptClass = evalScripts.get(script);
        if (scriptClass == null) {
            scriptClass = loader.parseClass(script.toString(), source);
            evalScripts.put(script, scriptClass);
        } else {
            LOG.fine("eval() - Using cached script...");
        }
        //can't cache the script because the context may be different.
        //but don't bother loading parsing the class again
        Script s = InvokerHelper.createScript(scriptClass, context);
        return s.run();
    } catch (Exception e) {
        throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:CachingGroovyEngine.java

示例8: testGroovyShell_goodBindingFollowedByBadBinding_Exception

import groovy.lang.Script; //导入方法依赖的package包/类
@Test(expected = groovy.lang.MissingPropertyException.class)
public void testGroovyShell_goodBindingFollowedByBadBinding_Exception() throws Exception {
    GroovyShell groovyShell = new GroovyShell();
    final String s = "x  > 2  &&  y  > 1";
    Script script = groovyShell.parse(s);

    Binding binding = new Binding();
    binding.setProperty("x", 5);
    binding.setProperty("y", 3);
    script.setBinding(binding);

    Object result = script.run();
    Assert.assertEquals(true, result);

    Assert.assertTrue(binding.hasVariable("x"));

    binding = new Binding();
    binding.setProperty("x1", 5);
    binding.setProperty("y1", 3);
    script.setBinding(binding);

    Assert.assertFalse(binding.hasVariable("x"));

    script.run();  // throws exception because no bindings for x, y
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:26,代码来源:GroovyTest.java

示例9: executeScript

import groovy.lang.Script; //导入方法依赖的package包/类
protected void executeScript(Class scriptClass, Permission missingPermission) {
    try {
        Script script = InvokerHelper.createScript(scriptClass, new Binding());
        script.run();
        //InvokerHelper.runScript(scriptClass, null);
    } catch (AccessControlException ace) {
        if (missingPermission != null && missingPermission.implies(ace.getPermission())) {
            return;
        } else {
            fail(ace.toString());
        }
    }
    if (missingPermission != null) {
        fail("Should catch an AccessControlException");
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:SecurityTestSupport.java

示例10: initWithScript

import groovy.lang.Script; //导入方法依赖的package包/类
public GroovyFieldDelegate initWithScript(Script groovyScript) {
	this.groovyScript = groovyScript;
	Object result = groovyScript.run();
	@SuppressWarnings("rawtypes")
       Map<?, ?> methodMap = (result instanceof Map) ? ((Map) result) : Collections.emptyMap();

	gameStarted = getClosure(methodMap, "gameStarted");
	ballLost = getClosure(methodMap, "ballLost");
	gameEnded = getClosure(methodMap, "gameEnded");
	tick = getClosure(methodMap, "tick");
	processCollision = getClosure(methodMap, "processCollision");
	flippersActivated = getClosure(methodMap, "flippersActivated");
	allDropTargetsInGroupHit = getClosure(methodMap, "allDropTargetsInGroupHit");
	allRolloversInGroupActivated = getClosure(methodMap, "allRolloversInGroupActivated");
	ballInSensorRange = getClosure(methodMap, "ballInSensorRange");
	isFieldActive = getClosure(methodMap, "isFieldActive");

	return this;
}
 
开发者ID:dozingcat,项目名称:Vector-Pinball-Editor,代码行数:20,代码来源:GroovyFieldDelegate.java

示例11: initializeApi

import groovy.lang.Script; //导入方法依赖的package包/类
/**
 *  Initializes the API that the 'runtime' scripts will rely upon.
 *  IF this is not called by the application then this is called automatically 
 *  the first time that a script is evaluated.
 */
public void initializeApi() {
    if( initialized ) {
        return;
    }
    
    for( Script script : api ) {
        if( log.isDebugEnabled() ) {
            log.debug("evaluating API script:" + script);
        }
                
        //script.setBinding(localBindings(bindings, source));
        Object result = script.run(); 
        if( log.isDebugEnabled() )
            log.debug("result:" + result);
    }
}
 
开发者ID:Simsilica,项目名称:SiO2,代码行数:22,代码来源:ScriptEnvironment.java

示例12: eval

import groovy.lang.Script; //导入方法依赖的package包/类
public Object eval( InputStream is, String s ) {
    if( log.isDebugEnabled() ) {
        log.debug( "evaluating:" + s );
    }
    Script script = compile(is, s);

    int before = context.getVariables().size();
    Object result = script.run(); 
    if( log.isTraceEnabled() )
        log.trace("result:" + result);                
        
    if( before != context.getVariables().size() ) {
        log.warn("Binding count increased executing:" + s + "  keys:" + context.getVariables().keySet());        
    }
    
    return result;
}
 
开发者ID:Simsilica,项目名称:SiO2,代码行数:18,代码来源:ScriptEnvironment.java

示例13: run

import groovy.lang.Script; //导入方法依赖的package包/类
@Override
public void run(JobToRun job) {
  RunnerFilterChain<JobStoryRunContext> chain = createFilterChain();
  StoryFilterChainAdapter adapter = new StoryFilterChainAdapter(job, chain);
  DslBuilderAndRun.setFilterChainCurrentThread(adapter);
  try {
    Class<?> clazz = Class.forName(job.getStoryClassName());
    
    if (! (clazz.getSuperclass().getName().equals("groovy.lang.Script"))){
      throw new RuntimeException(job.getStoryClassName() + " is not a groovy script");
    }
    
    Script script = (Script)clazz.newInstance();
    script.run();
    
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:detectiveframework,项目名称:detective,代码行数:20,代码来源:JobRunnerFilterImpl.java

示例14: runScript

import groovy.lang.Script; //导入方法依赖的package包/类
private void runScript(String script) throws Exception {
  Vertx vertx = Vertx.vertx();
  try {
    GroovyShell gcl = new GroovyShell();
    Script s = gcl.parse(new File(script));
    Binding binding = new Binding();
    binding.setProperty("test", this);
    binding.setProperty("vertx", vertx);
    s.setBinding(binding);
    s.run();
  } finally {
    CountDownLatch latch = new CountDownLatch(1);
    vertx.close(v -> {
      latch.countDown();
    });
    latch.await();
  }
}
 
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:19,代码来源:GroovyIntegrationTest.java

示例15: testDefaultSleep

import groovy.lang.Script; //导入方法依赖的package包/类
@Test
public void testDefaultSleep() throws Exception {
	final Script script = createScript("sleep(1000);", new HashMap<String, Object>());
	final AtomicInteger counter = new AtomicInteger(0);
	Fiber fiber = new Fiber(scheduler, new SuspendableRunnable() {
		@Override
		public void run() throws SuspendExecution, InterruptedException {
			counter.incrementAndGet();
			script.run();
			counter.incrementAndGet();
		}
	});
	fiber.start();
	fiber.join();
	Assert.assertEquals(counter.intValue(), 2);
}
 
开发者ID:dinix2008,项目名称:quasar-groovy,代码行数:17,代码来源:FiberTest.java


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