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


Java GroovyShell类代码示例

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


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

示例1: process

import groovy.lang.GroovyShell; //导入依赖的package包/类
@Override
public void process(Network network, ComputationManager computationManager) throws Exception {
    if (Files.exists(script)) {
        LOGGER.debug("Execute groovy post processor {}", script);
        try (Reader reader = Files.newBufferedReader(script, StandardCharsets.UTF_8)) {
            CompilerConfiguration conf = new CompilerConfiguration();

            Binding binding = new Binding();
            binding.setVariable("network", network);
            binding.setVariable("computationManager", computationManager);

            GroovyShell shell = new GroovyShell(binding, conf);
            shell.evaluate(reader);
        }
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:17,代码来源:GroovyScriptPostProcessor.java

示例2: applyConfigurationScript

import groovy.lang.GroovyShell; //导入依赖的package包/类
private void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
    VersionNumber version = parseGroovyVersion();
    if (version.compareTo(VersionNumber.parse("2.1")) < 0) {
        throw new GradleException("Using a Groovy compiler configuration script requires Groovy 2.1+ but found Groovy " + version + "");
    }
    Binding binding = new Binding();
    binding.setVariable("configuration", configuration);

    CompilerConfiguration configuratorConfig = new CompilerConfiguration();
    ImportCustomizer customizer = new ImportCustomizer();
    customizer.addStaticStars("org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");
    configuratorConfig.addCompilationCustomizers(customizer);

    GroovyShell shell = new GroovyShell(binding, configuratorConfig);
    try {
        shell.evaluate(configScript);
    } catch (Exception e) {
        throw new GradleException("Could not execute Groovy compiler configuration script: " + configScript.getAbsolutePath(), e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:21,代码来源:ApiGroovyCompiler.java

示例3: setUp

import groovy.lang.GroovyShell; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    network = createNetwork();
    ComputationManager computationManager = Mockito.mock(ComputationManager.class);
    LoadFlow loadFlow = Mockito.mock(LoadFlow.class);
    LoadFlowFactory loadFlowFactory = Mockito.mock(LoadFlowFactory.class);
    Mockito.when(loadFlowFactory.create(Mockito.any(Network.class), Mockito.any(ComputationManager.class), Mockito.anyInt()))
            .thenReturn(loadFlow);
    LoadFlowResult loadFlowResult = Mockito.mock(LoadFlowResult.class);
    Mockito.when(loadFlowResult.isOk())
            .thenReturn(true);
    Mockito.when(loadFlow.getName()).thenReturn("load flow mock");
    Mockito.when(loadFlow.run())
            .thenReturn(loadFlowResult);
    LoadFlowActionSimulatorObserver observer = createObserver();
    GroovyCodeSource src = new GroovyCodeSource(new InputStreamReader(getClass().getResourceAsStream(getDslFile())), "test", GroovyShell.DEFAULT_CODE_BASE);
    actionDb = new ActionDslLoader(src).load(network);
    engine = new LoadFlowActionSimulator(network, computationManager, new LoadFlowActionSimulatorConfig(LoadFlowFactory.class, 3, false), observer) {
        @Override
        protected LoadFlowFactory newLoadFlowFactory() {
            return loadFlowFactory;
        }
    };
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:25,代码来源:AbstractLoadFlowRulesEngineTest.java

示例4: getGroovyAttributeValue

import groovy.lang.GroovyShell; //导入依赖的package包/类
private static Object getGroovyAttributeValue(final String groovyScript,
                                              final Map<String, Object> resolvedAttributes) {
    try {
        final Binding binding = new Binding();
        final GroovyShell shell = new GroovyShell(binding);
        binding.setVariable("attributes", resolvedAttributes);
        binding.setVariable("logger", LOGGER);

        LOGGER.debug("Executing groovy script [{}] with attributes binding of [{}]",
                StringUtils.abbreviate(groovyScript, groovyScript.length() / 2), resolvedAttributes);
        final Object res = shell.evaluate(groovyScript);
        return res;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:ReturnMappedAttributeReleasePolicy.java

示例5: prepareInterpreter

import groovy.lang.GroovyShell; //导入依赖的package包/类
@Override
protected void prepareInterpreter() {
    ImportCustomizer importCustomizer = new ImportCustomizer();

    PROCESSOR_CLASSES
            .forEach((interfaceClass, scriptClass) -> addImport(importCustomizer, scriptClass, interfaceClass.getSimpleName()));
    addImport(importCustomizer, GroovyPlugin.class, Plugin.class.getSimpleName());

    getStandardImportClasses().forEach(cls -> addImport(importCustomizer, cls));

    CompilerConfiguration configuration = new CompilerConfiguration();
    configuration.addCompilationCustomizers(importCustomizer);

    binding = createBinding();
    shell = new GroovyShell(binding, configuration);
    scripts = Collections.synchronizedList(new ArrayList<>());

    setVariable(KnowledgeBaseConstants.VAR_ENGINE_OPERATIONS, getEngineOperations());

    setClasspath(getEngineOperations() != null ? getEngineOperations().getEngine() : null);
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:22,代码来源:GroovyKnowledgeBaseInterpreter.java

示例6: interpret

import groovy.lang.GroovyShell; //导入依赖的package包/类
public static EObject interpret(String groovyScript) {
		EDataType data =  EcorePackage.eINSTANCE.getEString();				
		Binding binding = new Binding();

		//Binding setVariable allow to pass a variable from the moonti arc model to the groovy interpreter
		//binding.setVariable(name, value);
		
		 GroovyShell shell = new GroovyShell(binding);		    
		    Object result = shell.evaluate(groovyScript);
		    
		    //Binding.getVariable get the new value of this variable. 
//		    binding.getVariable(name)

		    
		    //		data.setName(""+(rand.nextInt(100)+1));
		data.setName(""+result);
		return data;
	}
 
开发者ID:awortmann,项目名称:xmontiarc,代码行数:19,代码来源:GroovyInterpreter.java

示例7: getGroovyShell

import groovy.lang.GroovyShell; //导入依赖的package包/类
private GroovyShell getGroovyShell() {
  if (this.groovySh == null) {
    // add some default imports to the script
    ImportCustomizer defaultImports = new ImportCustomizer();
    defaultImports
        .addStarImports("fr.ign.cogit.geoxygene.appli.render.primitive");
    defaultImports
        .addStarImports("fr.ign.cogit.geoxygene.appli.render.operator");
    defaultImports.addStarImports("fr.ign.cogit.geoxygene.appli.render.gl");
    defaultImports.addStarImports("fr.ign.cogit.geoxygene.appli.render");
    defaultImports.addStarImports("fr.ign.cogit.geoxygene.function");
    defaultImports.addStaticStars("org.lwjgl.opengl.GL11");
    defaultImports.addStaticStars("java.lang.Math");
    defaultImports.addStarImports("javax.vecmath");
    defaultImports.addStarImports("java.awt");
    final CompilerConfiguration config = new CompilerConfiguration();
    config.addCompilationCustomizers(defaultImports);
    final Binding binding = this.getBinding();

    this.groovySh = new GroovyShell(binding, config);
  }
  return this.groovySh;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:24,代码来源:ScriptingPrimitiveRenderer.java

示例8: runGroovy

import groovy.lang.GroovyShell; //导入依赖的package包/类
public static void runGroovy(int xmax, int ymax, int zmax) {
    Binding binding = new Binding();
    GroovyShell shell = new GroovyShell(binding);
    String expression = "x + y*2 - z";
    Integer result = 0;
    Date start = new Date();
    for (int xval = 0; xval < xmax; xval++) {
        for (int yval = 0; yval < ymax; yval++) {
            for (int zval = 0; zval <= zmax; zval++) {
                binding.setVariable("x", xval);
                binding.setVariable("y", yval);
                binding.setVariable("z", zval);
                Integer cal = (Integer) shell.evaluate(expression);
                result += cal;
            }
        }
    }
    Date end = new Date();
    System.out.println("Groovy:time is : " + (end.getTime() - start.getTime()) + ",result is " + result);
}
 
开发者ID:brucefengnju,项目名称:eldemo,代码行数:21,代码来源:RunPerform.java

示例9: gpath

import groovy.lang.GroovyShell; //导入依赖的package包/类
/**
 * Matches according to GPath.
 */
public Closure<Boolean> gpath(final String condition) throws TestException {
    return new Closure<Boolean>(this, this) {
        @Override
        public Boolean call(Object request) {
            try {
                GPathResult gpathRequest = new XmlSlurper().parseText(request.toString());
                Binding binding = getBinding();
                binding.setVariable("request", gpathRequest);
                return (Boolean) new GroovyShell(binding).evaluate(condition);
            }
            catch (Exception ex) {
                ex.printStackTrace(getTestCaseRun().getLog());
                getTestCaseRun().getLog().println("Failed to parse request as XML/JSON. Stub response: " + AdapterActivity.MAKE_ACTUAL_CALL);
                return false;
            }
        }
    };
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:22,代码来源:TestCaseScript.java

示例10: substitute

import groovy.lang.GroovyShell; //导入依赖的package包/类
/**
 * performs groovy substitutions with this as delegate and inherited bindings
 */
protected String substitute(String before) {
    if (before.indexOf("${") == -1)
        return before;
    // escape all $ not followed by curly braces on same line
    before = before.replaceAll("\\$(?!\\{)", "\\\\\\$");
    // escape all regex -> ${~
    before = before.replaceAll("\\$\\{~", "\\\\\\$\\{~");
    // escape all escaped newlines
    before = before.replaceAll("\\\\n", "\\\\\\\\\\n");
    before = before.replaceAll("\\\\r", "\\\\\\\\\\r");
    // escape all escaped quotes
    before = before.replaceAll("\\\"", "\\\\\"");

    CompilerConfiguration compilerCfg = new CompilerConfiguration();
    compilerCfg.setScriptBaseClass(DelegatingScript.class.getName());
    GroovyShell shell = new GroovyShell(TestCaseScript.class.getClassLoader(), getBinding(), compilerCfg);
    DelegatingScript script = (DelegatingScript) shell.parse("return \"\"\"" + before + "\"\"\"");
    script.setDelegate(TestCaseScript.this);
    // restore escaped \$ to $ for comparison
    return script.run().toString().replaceAll("\\\\$", "\\$");
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:25,代码来源:TestCaseScript.java

示例11: 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);
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:24,代码来源:StandaloneTestCaseRun.java

示例12: setupContextClassLoader

import groovy.lang.GroovyShell; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static void setupContextClassLoader(GroovyShell shell) {
    final Thread current = Thread.currentThread();
    @SuppressWarnings("rawtypes")
    class DoSetContext implements PrivilegedAction {
        ClassLoader classLoader;
        public DoSetContext(ClassLoader loader) {
            classLoader = loader;
        }
        public Object run() {
            current.setContextClassLoader(classLoader);
            return null;
        }
    }
    AccessController.doPrivileged(new DoSetContext(shell.getClassLoader()));
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:17,代码来源:StandaloneTestCaseRun.java

示例13: runScript

import groovy.lang.GroovyShell; //导入依赖的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

示例14: main

import groovy.lang.GroovyShell; //导入依赖的package包/类
public static void main(String[] args) {
    List<String> rules = Lists.newArrayList();
    rules.add("S <= 10");
    rules.add("S + A <= 20");
    rules.add("S + A + BP <= 55");
    rules.add("C >= 5");

    Binding binding = new Binding();
    binding.setVariable("S", 5.0);
    binding.setVariable("A", 5.0);
    binding.setVariable("BP", 30.0);
    binding.setVariable("B", 30.0);
    binding.setVariable("C", 30.0);
    GroovyShell shell = new GroovyShell(binding);
    for (String rule : rules) {
        Object result = shell.evaluate(rule);
        System.out.println(result);
    }
}
 
开发者ID:yongli82,项目名称:dsl,代码行数:20,代码来源:CheckRuleDsl.java

示例15: applyConfigurationScript

import groovy.lang.GroovyShell; //导入依赖的package包/类
private static void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
  Binding binding = new Binding();
  binding.setVariable("configuration", configuration);

  CompilerConfiguration configuratorConfig = new CompilerConfiguration();
  ImportCustomizer customizer = new ImportCustomizer();
  customizer.addStaticStars("org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");
  configuratorConfig.addCompilationCustomizers(customizer);

  try {
    new GroovyShell(binding, configuratorConfig).evaluate(configScript);
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:DependentGroovycRunner.java


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