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