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


Java CompilerConfiguration.setScriptBaseClass方法代码示例

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


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

示例1: substitute

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的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

示例2: run

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的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

示例3: runScript

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的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

示例4: runGroovyDslScript

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
/**
 * Runs a Groovy DSL script and returns the value returned by the script.
 * @param scriptReader For reading the script text
 * @param expectedType The expected type of the return value
 * @param parameters Parameters used by the script, null or empty if the script doesn't need any
 * @param <T> The expected type of the return value
 * @return The return value of the script, not null
 */
private static <T> T runGroovyDslScript(Reader scriptReader, Class<T> expectedType, Map<String, Object> parameters) {
  Map<String, Object> timeoutArgs = ImmutableMap.<String, Object>of("value", 2);
  ASTTransformationCustomizer customizer = new ASTTransformationCustomizer(timeoutArgs, TimedInterrupt.class);
  CompilerConfiguration config = new CompilerConfiguration();
  config.addCompilationCustomizers(customizer);
  config.setScriptBaseClass(SimulationScript.class.getName());
  Map<String, Object> bindingMap = parameters == null ? Collections.<String, Object>emptyMap() : parameters;
  //copy map to ensure that binding is mutable (for use in registerAliases)
  Binding binding = new Binding(Maps.newHashMap(bindingMap));
  registerAliases(binding);
  GroovyShell shell = new GroovyShell(binding, config);
  Script script = shell.parse(scriptReader);
  Object scriptOutput = script.run();
  if (scriptOutput == null) {
    throw new IllegalArgumentException("Script " + scriptReader + " didn't return an object");
  }
  if (expectedType.isInstance(scriptOutput)) {
    return expectedType.cast(scriptOutput);
  } else {
    throw new IllegalArgumentException("Script '" + scriptReader + "' didn't create an object of the expected type. " +
        "expected type: " + expectedType.getName() + ", " +
        "actual type: " + scriptOutput.getClass().getName() + ", " +
        "actual value: " + scriptOutput);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:34,代码来源:SimulationUtils.java

示例5: ensureInitializedOrReloaded

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
protected void ensureInitializedOrReloaded() {
    if (groovyClassLoader == null) {
        compilerConfiguration = new CompilerConfiguration(getCompilerConfigurationFactory().getCompilerConfiguration());
        if (getScriptBaseClass() != null) {
            compilerConfiguration.setScriptBaseClass(getScriptBaseClass());
        }

        groovyClassLoader = AccessController.doPrivileged((PrivilegedAction<GroovyClassLoader>)
                () -> new GroovyClassLoader(getParentClassLoaderFactory().getClassLoader(), compilerConfiguration));
        if (!scriptCache.isEmpty()) {
            // de-serialized: need to re-generate all previously compiled scripts (this can cause a hick-up...):
            for (ScriptCacheElement element : scriptCache.keySet()) {
                element.setScriptClass(compileScript(element.getBaseClass(), element.getScriptSource(), element.getScriptName()));
            }
        }
    }
}
 
开发者ID:apache,项目名称:commons-scxml,代码行数:18,代码来源:GroovyExtendableScriptCache.java

示例6: buildClasses

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
private ImmutableList<BaseListener> buildClasses() {
	List<BaseListener> listeners = new ArrayList<>();
	CompilerConfiguration compiler = new CompilerConfiguration();
	compiler.setScriptBaseClass(BaseListener.class.getName());
	GroovyClassLoader loader = new GroovyClassLoader(this.getClass().getClassLoader(), compiler);
	paths.forEach(path -> {
		try {
			final Class clazz = loader.parseClass(path.toFile());
			BaseListener listener = (BaseListener) clazz.newInstance();
			listener.run();
			listener.init();
			listeners.add(listener);
		} catch (Exception e) {
			log.error("Error building or initializing groovy script " + path, e);
		}
	});
	return ImmutableList.copyOf(listeners);
}
 
开发者ID:charliek,项目名称:kt,代码行数:19,代码来源:BaseListenerBuilder.java

示例7: loadByPath

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
@Override
public void loadByPath(Path path) throws Throwable {
	String id;
	if (Files.isDirectory(path)) {
		id = path.getFileName().toString();
		path = path.resolve("plugin.groovy");
	} else {
		if(path.getFileName().toString().equals("plugin.groovy"))
			id = path.getParent().getFileName().toString();
		else {
			id = path.getFileName().toString();
			id = id.substring(0, id.length() - 7);
		}
	}
	System.setProperty("groovy.grape.report.downloads", "true");
	CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
	compilerConfiguration.setSourceEncoding("UTF-8");
	compilerConfiguration.setScriptBaseClass("info.deskchan.groovy_support.GroovyPlugin");
	compilerConfiguration.setClasspath(path.getParent().toString());
	GroovyShell groovyShell = new GroovyShell(compilerConfiguration);
	Script script = groovyShell.parse(path.toFile());
	GroovyPlugin plugin = (GroovyPlugin) script;
	plugin.setPluginDirPath(path.getParent());
	PluginConfig config = new PluginConfig("Groovy");
	path = path.getParent().resolve("manifest.json");
	config.appendFromJson(path);
	PluginManager.getInstance().initializePlugin(id, plugin, config);
}
 
开发者ID:DeskChan,项目名称:DeskChan,代码行数:29,代码来源:Main.java

示例8: createCompiler

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
private CompilerConfiguration createCompiler() throws AppException {
    CompilerConfiguration cc = new CompilerConfiguration();
    cc.setScriptBaseClass(ParsedScript.class.getName());
    Set<String> services = hostServices.getAvailableServices();
    for (String name : services) {
        PreHost pre = hostServices.getAvailablePreService(name).create();
        pre.configureCompiler(cc);
    }
    return cc;
}
 
开发者ID:devent,项目名称:robobee-osgi,代码行数:11,代码来源:ParserImpl.java

示例9: run

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
public void run() {
    startExecution();
    try {
        if (testCase.getAsset().isFormat(Asset.POSTMAN)) {
            String runnerClass = NODE_PACKAGE + ".TestRunner";
            Package pkg = PackageCache.getPackage(testCase.getPackage());
            Class<?> testRunnerClass = CompiledJavaCache.getResourceClass(runnerClass, getClass().getClassLoader(), pkg);
            Object runner = testRunnerClass.newInstance();
            Method runMethod = testRunnerClass.getMethod("run", TestCase.class);
            runMethod.invoke(runner, testCase);
            finishExecution(null);
        }
        else {
            String groovyScript = testCase.getText();
            CompilerConfiguration compilerConfig = new CompilerConfiguration();
            compilerConfig.setScriptBaseClass(TestCaseScript.class.getName());

            Binding binding = new Binding();
            binding.setVariable("testCaseRun", this);

            ClassLoader classLoader = this.getClass().getClassLoader();
            Package testPkg = PackageCache.getPackage(testCase.getPackage());
            if (testPkg != null)
                classLoader = testPkg.getCloudClassLoader();

            GroovyShell shell = new GroovyShell(classLoader, binding, compilerConfig);
            Script gScript = shell.parse(groovyScript);
            gScript.setProperty("out", log);
            gScript.run();
            finishExecution(null);
        }
    }
    catch (Throwable ex) {
        finishExecution(ex);
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:37,代码来源:TestCaseRun.java

示例10: initialize

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
public void initialize(Reader resource) throws URISyntaxException, IOException {
    logger.info("Initializing from reader: " + resource);
    if (resource == null) {
        throw new NullPointerException("resource not found");
    }
    CompilerConfiguration cc = new CompilerConfiguration();
    cc.setScriptBaseClass(DelegatingScript.class.getName());
    GroovyShell shell = new GroovyShell(cc);
    DelegatingScript script = (DelegatingScript) shell.parse(resource);
    script.setDelegate(this);
    script.run();
    logger.info("Games available after initialization: " + games.keySet());
}
 
开发者ID:Zomis,项目名称:flexgame-server,代码行数:14,代码来源:GroovyGames.java

示例11: runScript

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
private static StandAloneScenarioScript runScript(File scriptFile) throws IOException {
  CompilerConfiguration config = new CompilerConfiguration();
  config.setScriptBaseClass(StandAloneScenarioScript.class.getName());
  GroovyShell shell = new GroovyShell(config);
  StandAloneScenarioScript script;

  try (Reader reader = new BufferedReader(new FileReader(scriptFile))) {
    script = (StandAloneScenarioScript) shell.parse(reader, scriptFile.getAbsolutePath());
  }
  Binding binding = new Binding();
  SimulationUtils.registerAliases(binding);
  script.setBinding(binding);
  script.run();
  return script;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:16,代码来源:StandAloneScenarioRunner.java

示例12: getParameters

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
/**
 * Gets the parameters.
 * 
 * @return the parameters, keyed by name
 */
@Override
@SuppressWarnings("unchecked")
public Map<String, Object> getParameters() {
  CompilerConfiguration config = new CompilerConfiguration();
  config.setScriptBaseClass(SimulationScript.class.getName());
  GroovyShell shell = new GroovyShell(config);
  Script script = shell.parse(new StringReader(_script));
  script.run();
  return script.getBinding().getVariables();
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:16,代码来源:ScenarioDslParameters.java

示例13: createScript

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
private static StandAloneScenarioScript createScript(String scriptText) {
  CompilerConfiguration config = new CompilerConfiguration();
  config.setScriptBaseClass(StandAloneScenarioScript.class.getName());
  GroovyShell shell = new GroovyShell(config);
  StandAloneScenarioScript script = (StandAloneScenarioScript) shell.parse(scriptText);
  Binding binding = new Binding();
  SimulationUtils.registerAliases(binding);
  script.setBinding(binding);
  script.run();
  return script;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:12,代码来源:StandAloneScenarioScriptTest.java

示例14: GroovyCodeBlockCompiler

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
private GroovyCodeBlockCompiler() {

        CompilerConfiguration conf = new CompilerConfiguration(CompilerConfiguration.DEFAULT);

        ImportCustomizer imports = new ImportCustomizer();
        imports.addStarImports("org.voltdb");
        imports.addImports(
                "org.voltdb.groovy.TableBuilder",
                "org.voltdb.groovy.Tuplerator",
                "org.voltdb.VoltProcedure.VoltAbortException"
                 );
        imports.addStaticStars("org.voltdb.VoltProcedure","org.voltdb.VoltType");

        conf.addCompilationCustomizers(imports);
        // conf.getOptimizationOptions().put("int", false);
        // conf.getOptimizationOptions().put("indy", true);
        conf.setScriptBaseClass(DelegatingScript.class.getName());

        File groovyOut = createGroovyOutDirectory();

        List<String> classPath = conf.getClasspath();
        classPath.add(groovyOut.getAbsolutePath());
        conf.setClasspathList(classPath);

        conf.setTargetDirectory(groovyOut);

        gcl = new GroovyClassLoader(Thread.currentThread().getContextClassLoader(), conf);
    }
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:29,代码来源:GroovyCodeBlockCompiler.java

示例15: testScriptWithDerivedBaseClass

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
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"));
}
 
开发者ID:apache,项目名称:groovy,代码行数:10,代码来源:GroovyShellTest.java


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