本文整理匯總了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);
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}