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


Java CompilerConfiguration类代码示例

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


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

示例1: process

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

import org.codehaus.groovy.control.CompilerConfiguration; //导入依赖的package包/类
/**
 * Gets credential selection predicate.
 *
 * @param selectionCriteria the selection criteria
 * @return the credential selection predicate
 */
public static Predicate<org.apereo.cas.authentication.Credential> newCredentialSelectionPredicate(final String selectionCriteria) {
    try {
        if (StringUtils.isBlank(selectionCriteria)) {
            return credential -> true;
        }

        if (selectionCriteria.endsWith(".groovy")) {
            final ResourceLoader loader = new DefaultResourceLoader();
            final Resource resource = loader.getResource(selectionCriteria);
            if (resource != null) {
                final String script = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8);
                final GroovyClassLoader classLoader = new GroovyClassLoader(Beans.class.getClassLoader(),
                        new CompilerConfiguration(), true);
                final Class<Predicate> clz = classLoader.parseClass(script);
                return clz.newInstance();
            }
        }

        final Class predicateClazz = ClassUtils.getClass(selectionCriteria);
        return (Predicate<org.apereo.cas.authentication.Credential>) predicateClazz.newInstance();
    } catch (final Exception e) {
        final Predicate<String> predicate = Pattern.compile(selectionCriteria).asPredicate();
        return credential -> predicate.test(credential.getId());
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:32,代码来源:Beans.java

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

示例4: compileToDir

import org.codehaus.groovy.control.CompilerConfiguration; //导入依赖的package包/类
@Override
public void compileToDir(ScriptSource source, ClassLoader classLoader, File classesDir, File metadataDir, CompileOperation<?> extractingTransformer,
                         Class<? extends Script> scriptBaseClass, Action<? super ClassNode> verifier) {
    Timer clock = Timers.startTimer();
    GFileUtils.deleteDirectory(classesDir);
    GFileUtils.mkdirs(classesDir);
    CompilerConfiguration configuration = createBaseCompilerConfiguration(scriptBaseClass);
    configuration.setTargetDirectory(classesDir);
    try {
        compileScript(source, classLoader, configuration, metadataDir, extractingTransformer, verifier);
    } catch (GradleException e) {
        GFileUtils.deleteDirectory(classesDir);
        GFileUtils.deleteDirectory(metadataDir);
        throw e;
    }

    logger.debug("Timing: Writing script to cache at {} took: {}", classesDir.getAbsolutePath(), clock.getElapsed());
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:19,代码来源:DefaultScriptCompilationHandler.java

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

示例6: createCompilationUnit

import org.codehaus.groovy.control.CompilerConfiguration; //导入依赖的package包/类
@Override
protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource source) {
    CompilationUnit compilationUnit = super.createCompilationUnit(config, source);
    if ("/groovy/script".equals(source.getLocation().getPath())) {
        return compilationUnit;
    }
    for (File file : FileUtils.listFiles(new File(FileUtils.getTempDirectory(), Configuration.GROOVY), new String[]{"groovy"}, true)) {
        String srcPath = source.getLocation().getPath();
        String flnPath = null;
        try {
            flnPath = file.getCanonicalPath();
        } catch (IOException e) {
            flnPath = file.getAbsolutePath();
        }
        if (!srcPath.equals(flnPath)) {
            compilationUnit.addSource(file);
        }
    }
    return compilationUnit;
}
 
开发者ID:PkayJava,项目名称:MBaaS,代码行数:21,代码来源:GroovyClassLoader.java

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

示例8: applyCustomization

import org.codehaus.groovy.control.CompilerConfiguration; //导入依赖的package包/类
public CompilerConfiguration applyCustomization(final CompilerConfiguration compilerConfiguration) {
    final Class<CompilerConfiguration> clazz = CompilerConfiguration.class;
    final List<Method> methods = Arrays.asList(clazz.getMethods());
    for (Map.Entry<String,Object> entry : properties.entrySet()) {
        final Method method = methods.stream().filter(m -> m.getName().equals("set" + entry.getKey())).findFirst()
               .orElseThrow(() -> new IllegalStateException("Invalid setting [" + entry.getKey() + "] for CompilerConfiguration"));

        try {
            method.invoke(compilerConfiguration, entry.getValue());
        } catch (Exception ex) {
            throw new IllegalStateException(ex);
        }
    }

    return compilerConfiguration;
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:17,代码来源:ConfigurationCustomizerProvider.java

示例9: shouldApplyConfigurationChanges

import org.codehaus.groovy.control.CompilerConfiguration; //导入依赖的package包/类
@Test
public void shouldApplyConfigurationChanges() {
    final CompilerConfiguration configuration = new CompilerConfiguration();

    assertEquals(10, configuration.getTolerance());
    assertNull(configuration.getScriptBaseClass());
    assertEquals(false, configuration.getDebug());

    final ConfigurationCustomizerProvider provider = new ConfigurationCustomizerProvider(
            "Tolerance", 3,
            "ScriptBaseClass", "Something",
            "Debug", true);

    provider.applyCustomization(configuration);

    assertEquals(3, configuration.getTolerance());
    assertEquals("Something", configuration.getScriptBaseClass());
    assertEquals(true, configuration.getDebug());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:20,代码来源:ConfigurationCustomizerProviderTest.java

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

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

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

示例13: run

import org.codehaus.groovy.control.CompilerConfiguration; //导入依赖的package包/类
@Override
public Object run(String dsl, Binding binding) {
    CompilerConfiguration compilerConfiguration = prepareCompilerConfiguration();
    ClassLoader classLoader = prepareClassLoader(AbstractDSLLauncher.class.getClassLoader());
    GroovyCodeSource groovyCodeSource = prepareGroovyCodeSource(dsl);

    // Groovy shell
    GroovyShell shell = new GroovyShell(
            classLoader,
            new Binding(),
            compilerConfiguration
    );

    // Groovy script
    Script groovyScript = shell.parse(groovyCodeSource);

    // Binding
    groovyScript.setBinding(binding);

    // Runs the script
    return run(groovyScript);
}
 
开发者ID:jenkinsci,项目名称:ontrack-plugin,代码行数:23,代码来源:AbstractDSLLauncher.java

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

示例15: open

import org.codehaus.groovy.control.CompilerConfiguration; //导入依赖的package包/类
@Override
public void open() {
  CompilerConfiguration conf = new CompilerConfiguration();
  conf.setDebug(true);
  shell = new GroovyShell(conf);
  String classes = getProperty("GROOVY_CLASSES");
  if (classes == null || classes.length() == 0) {
    try {
      File jar = new File(
          GroovyInterpreter.class.getProtectionDomain().getCodeSource().getLocation().toURI()
              .getPath());
      classes = new File(jar.getParentFile(), "classes").toString();
    } catch (Exception e) {
    }
  }
  log.info("groovy classes classpath: " + classes);
  if (classes != null && classes.length() > 0) {
    File fClasses = new File(classes);
    if (!fClasses.exists()) {
      fClasses.mkdirs();
    }
    shell.getClassLoader().addClasspath(classes);
  }
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:25,代码来源:GroovyInterpreter.java


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