當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。