本文整理汇总了Java中groovy.lang.Binding.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java Binding.setProperty方法的具体用法?Java Binding.setProperty怎么用?Java Binding.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类groovy.lang.Binding
的用法示例。
在下文中一共展示了Binding.setProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
public void run(CommandLine line, ToolRunningContext context) throws Exception {
Path file = context.getFileSystem().getPath(line.getOptionValue(FILE));
Writer writer = new OutputStreamWriter(context.getOutputStream());
try {
AppLogger logger = new AppLogger() {
@Override
public void log(String message, Object... args) {
context.getOutputStream().println(String.format(message, args));
}
@Override
public AppLogger tagged(String tag) {
return this;
}
};
try (AppData data = new AppData(context.getComputationManager(), fileSystemProviders,
fileExtensions, projectFileExtensions, serviceExtensions, () -> logger)) {
if (file.getFileName().toString().endsWith(".groovy")) {
try {
Binding binding = new Binding();
binding.setProperty("args", line.getArgs());
GroovyScripts.run(file, data, binding, writer);
} catch (Throwable t) {
Throwable rootCause = StackTraceUtils.sanitizeRootCause(t);
rootCause.printStackTrace(context.getErrorStream());
}
} else {
throw new IllegalArgumentException("Script type not supported");
}
}
} finally {
writer.flush();
}
}
示例2: init
import groovy.lang.Binding; //导入方法依赖的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());
}
示例3: createBinding
import groovy.lang.Binding; //导入方法依赖的package包/类
private Binding createBinding() {
Binding binding = new Binding();
binding.setProperty("service", hostServices);
binding.setProperty("targets", hostServices.getTargets());
for (Map.Entry<String, Object> entry : variables.entrySet()) {
binding.setProperty(entry.getKey(), entry.getValue());
}
return binding;
}
示例4: reloadAppFolders
import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
public List<AppFolder> reloadAppFolders(List<AppFolder> folders) {
log.debug("Reloading AppFolders {}", folders);
StopWatch stopWatch = new Slf4JStopWatch("AppFolders");
stopWatch.start();
try {
if (!folders.isEmpty()) {
Binding binding = new Binding();
binding.setVariable("persistence", persistence);
binding.setVariable("metadata", metadata);
binding.setProperty("userSession", userSessionSource.getUserSession());
for (AppFolder folder : folders) {
Transaction tx = persistence.createTransaction();
try {
if (loadFolderQuantity(binding, folder)) {
tx.commit();
}
} finally {
tx.end();
}
}
}
return folders;
} finally {
stopWatch.stop();
}
}
示例5: executeGroovyScript
import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
protected boolean executeGroovyScript(final ScriptResource file) {
Binding bind = new Binding();
bind.setProperty("ds", getDataSource());
bind.setProperty("log", LoggerFactory.getLogger(String.format("%s$%s", DbUpdaterEngine.class.getName(),
StringUtils.removeEndIgnoreCase(file.getName(), ".groovy"))));
if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + UPGRADE_GROOVY_EXTENSION)) {
bind.setProperty("postUpdate", new PostUpdateScripts() {
@Override
public void add(Closure closure) {
postUpdateScripts.put(closure, file);
postUpdate.add(closure);
}
@Override
public List<Closure> getUpdates() {
return postUpdate.getUpdates();
}
});
}
try {
scripting.evaluateGroovy(file.getContent(), bind, ScriptExecutionPolicy.DO_NOT_USE_COMPILE_CACHE);
} catch (Exception e) {
throw new RuntimeException(ERROR + "Error executing Groovy script " + file.name + "\n" + e.getMessage(), e);
}
return !postUpdateScripts.containsValue(file);
}
示例6: executeGroovyScript
import groovy.lang.Binding; //导入方法依赖的package包/类
protected boolean executeGroovyScript(ScriptResource file) {
try {
ClassLoader classLoader = getClass().getClassLoader();
CompilerConfiguration cc = new CompilerConfiguration();
cc.setRecompileGroovySource(true);
Binding bind = new Binding();
bind.setProperty("ds", getDataSource());
bind.setProperty("log", LoggerFactory.getLogger(String.format("%s$%s", DbUpdaterEngine.class.getName(),
StringUtils.removeEndIgnoreCase(file.getName(), ".groovy"))));
if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + UPGRADE_GROOVY_EXTENSION)) {
bind.setProperty("postUpdate", new PostUpdateScripts() {
@Override
public void add(Closure closure) {
super.add(closure);
log.warn("Added post update action will be ignored");
}
});
}
GroovyShell shell = new GroovyShell(classLoader, bind, cc);
//noinspection UnnecessaryLocalVariable
Script script = shell.parse(file.getContent());
script.run();
} catch (Exception e) {
throw new RuntimeException(ERROR + "Error executing Groovy script " + file.name + "\n" + e.getMessage(), e);
}
return true;
}