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


Java CompilerConfiguration.addCompilationCustomizers方法代码示例

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


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

示例1: applyConfigurationScript

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

示例2: prepareInterpreter

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

示例3: getGroovyShell

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

示例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: configureCompiler

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
private void configureCompiler() {
    if (scriptBaseClass!=null) {
        configuration.setScriptBaseClass(scriptBaseClass);
    }
    if (indy) {
        configuration.getOptimizationOptions().put("indy", Boolean.TRUE);
        configuration.getOptimizationOptions().put("int", Boolean.FALSE);
    }
    if (configscript!=null) {
        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);
        File confSrc = new File(configscript);
        try {
            shell.evaluate(confSrc);
        } catch (IOException e) {
            throw new BuildException("Unable to configure compiler using configuration file: "+confSrc, e);
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:Groovy.java

示例6: createFromScript

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
public static GroovyFieldDelegate createFromScript(String script, ClassLoader classLoader) {
    CompilerConfiguration config = new CompilerConfiguration();

    SecureASTCustomizer secureAst = new SecureASTCustomizer();
    secureAst.setIndirectImportCheckEnabled(true);
    // TODO: Determine which classes should be accessible.
    secureAst.setImportsBlacklist(Arrays.asList("java.lang.Process"));
    secureAst.setReceiversClassesBlackList(Arrays.asList(String.class));

    ImportCustomizer imports = new ImportCustomizer();
    imports.addImport("Color", "com.dozingcatsoftware.vectorpinball.model.Color");

    config.addCompilationCustomizers(secureAst, imports);

    try (GroovyClassLoader gcl = new GroovyClassLoader(classLoader, config)) {
        @SuppressWarnings("unchecked")
        Class<? extends Script> groovyScriptClass = gcl.parseClass(script);
        return (new GroovyFieldDelegate()).initWithScript(groovyScriptClass.newInstance());
    }
    catch (IOException | InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }

}
 
开发者ID:dozingcat,项目名称:Vector-Pinball-Editor,代码行数:25,代码来源:GroovyFieldDelegateBuilder.java

示例7: GroovyConditionShell

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

        SecureASTCustomizer secureASTCustomizer = createSecureASTCustomizer();
        ImportCustomizer importCustomizer = createImportCustomizer();
        ASTTransformationCustomizer astTransformationCustomizer = createASTTransformationCustomizer();

        CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
        compilerConfiguration.addCompilationCustomizers(secureASTCustomizer);
        compilerConfiguration.addCompilationCustomizers(importCustomizer);
        compilerConfiguration.addCompilationCustomizers(astTransformationCustomizer);

        this.shell = new GroovyShell(compilerConfiguration);
    }
 
开发者ID:eclipse,项目名称:keti,代码行数:14,代码来源:GroovyConditionShell.java

示例8: init

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
@PostConstruct
public void init() {
    ImportCustomizer importCustomizer = new ImportCustomizer();
    importCustomizer.addStarImports("net.dv8tion.jda.core.entities");

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

    sharedData = new Binding();
    sharedData.setProperty("ctx", context);
    sharedData.setProperty("jda", discordService.getJda());
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:13,代码来源:GroovyService.java

示例9: ConfigManager

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
private ConfigManager()
{
    CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
    ImportCustomizer importCustomizer = new ImportCustomizer();
    importCustomizer.addStarImports("org.diorite.config", "org.diorite.config.serialization", "org.diorite", "org.diorite.config.exceptions");
    compilerConfiguration.addCompilationCustomizers(importCustomizer);
    GroovyClassLoader groovyClassLoader = new GroovyClassLoader(this.getClass().getClassLoader(), compilerConfiguration);
    this.groovy = new GroovyScriptEngineImpl(groovyClassLoader);
    DynamicClassLoader classLoader = DynamicClassLoader.injectAsSystemClassLoader();
    classLoader.addClassLoader(groovyClassLoader, 0);
    this.setImplementationProvider(GroovyImplementationProvider.getInstance());
}
 
开发者ID:GotoFinal,项目名称:diorite-configs-java8,代码行数:13,代码来源:ConfigManager.java

示例10: createClassLoader

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
private synchronized void createClassLoader() {
    final CompilerConfiguration conf = new CompilerConfiguration();
    conf.addCompilationCustomizers(this.importCustomizerProvider.create());

    // ConfigurationCustomizerProvider is treated separately
    customizerProviders.stream().filter(cp -> !(cp instanceof ConfigurationCustomizerProvider))
            .forEach(p -> conf.addCompilationCustomizers(p.create()));

    customizerProviders.stream().filter(cp -> cp instanceof ConfigurationCustomizerProvider).findFirst()
            .ifPresent(cp -> ((ConfigurationCustomizerProvider) cp).applyCustomization(conf));

    this.loader = new GremlinGroovyClassLoader(getParentLoader(), conf);
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:14,代码来源:GremlinGroovyScriptEngine.java

示例11: configureCompiler

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
@Override
public void configureCompiler(Object compiler) throws AppException {
    CompilerConfiguration cc = (CompilerConfiguration) compiler;
    ImportCustomizer imports = new ImportCustomizer();
    imports.addStaticStars("com.anrisoftware.sscontrol.types.external.BindingAddress");
    cc.addCompilationCustomizers(imports);
}
 
开发者ID:devent,项目名称:robobee-osgi,代码行数:8,代码来源:DatabasePreScriptImpl.java

示例12: createStaticConfiguration

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
protected static CompilerConfiguration createStaticConfiguration() {
    CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
    ASTTransformationCustomizer astTransformationCustomizer = new ASTTransformationCustomizer(
            Collections.singletonMap("extensions", Collections.singletonList("EngineVariablesExtension.groovy")),
            CompileStatic.class, "org.codehaus.groovy.transform.sc.StaticCompileTransformation");
    compilerConfiguration.addCompilationCustomizers(astTransformationCustomizer);
    return compilerConfiguration;
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:9,代码来源:GroovyStaticScriptEngine.java

示例13: create

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
private GroovyScriptEngine create() {
  // custom the configuration of the compiler
  CompilerConfiguration cc = new CompilerConfiguration();
  cc.setTargetDirectory(new File(applicationDirectories.getTemporaryDirectory(), "groovy-classes"));
  cc.setSourceEncoding("UTF-8");
  cc.addCompilationCustomizers(secureASTCustomizer());
  GroovyClassLoader gcl = new GroovyClassLoader(classLoader, cc);

  engine = new GroovyScriptEngine(gcl);

  // HACK: For testing
  log.info("Created engine: {}", engine);

  return engine;
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:16,代码来源:GroovyScriptEngineFactory.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: MarkupTemplateEngine

import org.codehaus.groovy.control.CompilerConfiguration; //导入方法依赖的package包/类
public MarkupTemplateEngine(final ClassLoader parentLoader, final TemplateConfiguration tplConfig, final TemplateResolver resolver) {
    compilerConfiguration = new CompilerConfiguration();
    templateConfiguration = tplConfig;
    compilerConfiguration.addCompilationCustomizers(new TemplateASTTransformer(tplConfig));
    compilerConfiguration.addCompilationCustomizers(
            new ASTTransformationCustomizer(Collections.singletonMap("extensions", "groovy.text.markup.MarkupTemplateTypeCheckingExtension"), CompileStatic.class));
    if (templateConfiguration.isAutoNewLine()) {
        compilerConfiguration.addCompilationCustomizers(
                new CompilationCustomizer(CompilePhase.CONVERSION) {
                    @Override
                    public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
                        new AutoNewLineTransformer(source).visitClass(classNode);
                    }
                }
        );
    }
    groovyClassLoader = AccessController.doPrivileged(new PrivilegedAction<TemplateGroovyClassLoader>() {
        public TemplateGroovyClassLoader run() {
            return new TemplateGroovyClassLoader(parentLoader, compilerConfiguration);
        }
    });
    if (DEBUG_BYTECODE) {
        compilerConfiguration.setBytecodePostprocessor(BytecodeDumper.STANDARD_ERR);
    }
    templateResolver = resolver == null ? new DefaultTemplateResolver() : resolver;
    templateResolver.configure(groovyClassLoader, templateConfiguration);
}
 
开发者ID:apache,项目名称:groovy,代码行数:28,代码来源:MarkupTemplateEngine.java


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