本文整理汇总了Java中org.codehaus.groovy.control.customizers.ImportCustomizer类的典型用法代码示例。如果您正苦于以下问题:Java ImportCustomizer类的具体用法?Java ImportCustomizer怎么用?Java ImportCustomizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImportCustomizer类属于org.codehaus.groovy.control.customizers包,在下文中一共展示了ImportCustomizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyConfigurationScript
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的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.customizers.ImportCustomizer; //导入依赖的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.customizers.ImportCustomizer; //导入依赖的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: applyImports
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的package包/类
@Override
public void applyImports(ImportCustomizer imports) {
imports.addImports("org.springframework.batch.repeat.RepeatStatus",
"org.springframework.batch.core.scope.context.ChunkContext",
"org.springframework.batch.core.step.tasklet.Tasklet",
"org.springframework.batch.core.configuration.annotation.StepScope",
"org.springframework.batch.core.configuration.annotation.JobBuilderFactory",
"org.springframework.batch.core.configuration.annotation.StepBuilderFactory",
"org.springframework.batch.core.configuration.annotation.EnableBatchProcessing",
"org.springframework.batch.core.Step",
"org.springframework.batch.core.StepExecution",
"org.springframework.batch.core.StepContribution",
"org.springframework.batch.core.Job",
"org.springframework.batch.core.JobExecution",
"org.springframework.batch.core.JobParameter",
"org.springframework.batch.core.JobParameters",
"org.springframework.batch.core.launch.JobLauncher",
"org.springframework.batch.core.converter.JobParametersConverter",
"org.springframework.batch.core.converter.DefaultJobParametersConverter");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:SpringBatchCompilerAutoConfiguration.java
示例5: call
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的package包/类
@Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode)
throws CompilationFailedException {
ImportCustomizer importCustomizer = new SmartImportCustomizer(source, context,
classNode);
ClassNode mainClassNode = MainClass.get(source.getAST().getClasses());
// Additional auto configuration
for (CompilerAutoConfiguration autoConfiguration : GroovyCompiler.this.compilerAutoConfigurations) {
if (autoConfiguration.matches(classNode)) {
if (GroovyCompiler.this.configuration.isGuessImports()) {
autoConfiguration.applyImports(importCustomizer);
importCustomizer.call(source, context, classNode);
}
if (classNode.equals(mainClassNode)) {
autoConfiguration.applyToMainClass(GroovyCompiler.this.loader,
GroovyCompiler.this.configuration, context, source,
classNode);
}
autoConfiguration.apply(GroovyCompiler.this.loader,
GroovyCompiler.this.configuration, context, source,
classNode);
}
}
importCustomizer.call(source, context, classNode);
}
示例6: applyConfigurationScript
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的package包/类
private static void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
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);
try {
new GroovyShell(binding, configuratorConfig).evaluate(configScript);
}
catch (Exception e) {
e.printStackTrace();
}
}
示例7: configureCompiler
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的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);
}
}
}
示例8: addImport
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的package包/类
private void addImport(final ImportCustomizer customizer, final Object value) {
if (value==null) return;
if (value instanceof Collection) {
for (Object e : (Collection)value) {
addImport(customizer, e);
}
} else if (value instanceof String) {
customizer.addImports((String)value);
} else if (value instanceof Class) {
customizer.addImports(((Class) value).getName());
} else if (value instanceof GString) {
customizer.addImports(value.toString());
} else {
throw new RuntimeException("Unsupported import value type ["+value+"]");
}
}
示例9: createFromScript
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的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);
}
}
示例10: getShell
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的package包/类
private GroovyShell getShell(Binding binding, GroovyInterceptor sandbox, GenericUserMessageEvent event) {
binding.setVariable("eval", getEvalFunction(binding, sandbox, event));
binding.setVariable("commands", new DynamicCommandHandler(this, event));
CompilerConfiguration cc = new CompilerConfiguration();
cc.addCompilationCustomizers(
new SandboxTransformer(),
new ASTTransformationCustomizer(ImmutableMap.of("value", TIMEOUT), TimedInterrupt.class),
new ImportCustomizer()
.addStarImports("java.lang.reflect")
.addImports(HttpRequest.class.getName())
.addImports(CommandCall.class.getName())
);
GroovyShell shell = new GroovyShell(manager.pluginClassLoader, binding, cc);
sandbox.register();
return shell;
}
示例11: newEvaluator
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的package包/类
public static GroovyClassLoader newEvaluator(Imports imports, Classpath classpath, String outDir, ImportCustomizer icz,ClassLoader parent) {
try {
Class.forName("org.codehaus.groovy.control.customizers.ImportCustomizer");
} catch (ClassNotFoundException e1) {
String gjp = System.getenv(GROOVY_JAR_PATH);
String errorMsg = null;
if (gjp != null && !gjp.isEmpty()) {
errorMsg = "Groovy libary not found, GROOVY_JAR_PATH = " + gjp;
} else {
errorMsg = "Default groovy libary not found. No GROOVY_JAR_PATH variable set.";
}
throw new GroovyNotFoundException(errorMsg);
}
icz = addImportsCustomizer(icz, imports);
CompilerConfiguration config = new CompilerConfiguration().addCompilationCustomizers(icz);
String acloader_cp = Joiner.on(File.pathSeparatorChar).join(classpath.getPathsAsStrings());
config.setClasspath(acloader_cp);
return new GroovyClassLoader(parent, config);
}
示例12: GroovyConditionShell
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的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);
}
示例13: createImportCustomizer
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的package包/类
private static ImportCustomizer createImportCustomizer() {
ImportCustomizer importCustomizer = new ImportCustomizer();
importCustomizer.addImports(ResourceHandler.class.getCanonicalName());
importCustomizer.addImports(SubjectHandler.class.getCanonicalName());
importCustomizer.addImports(AbstractHandler.class.getCanonicalName());
return importCustomizer;
}
示例14: init
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的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());
}
示例15: ConfigManager
import org.codehaus.groovy.control.customizers.ImportCustomizer; //导入依赖的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());
}