本文整理汇总了Java中groovy.lang.Binding.setVariable方法的典型用法代码示例。如果您正苦于以下问题:Java Binding.setVariable方法的具体用法?Java Binding.setVariable怎么用?Java Binding.setVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类groovy.lang.Binding
的用法示例。
在下文中一共展示了Binding.setVariable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import groovy.lang.Binding; //导入方法依赖的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);
}
}
}
示例2: applyConfigurationScript
import groovy.lang.Binding; //导入方法依赖的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);
}
}
示例3: getGroovyAttributeValue
import groovy.lang.Binding; //导入方法依赖的package包/类
private static Object getGroovyAttributeValue(final String groovyScript,
final Map<String, Object> resolvedAttributes) {
try {
final Binding binding = new Binding();
final GroovyShell shell = new GroovyShell(binding);
binding.setVariable("attributes", resolvedAttributes);
binding.setVariable("logger", LOGGER);
LOGGER.debug("Executing groovy script [{}] with attributes binding of [{}]",
StringUtils.abbreviate(groovyScript, groovyScript.length() / 2), resolvedAttributes);
final Object res = shell.evaluate(groovyScript);
return res;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
示例4: getValue
import groovy.lang.Binding; //导入方法依赖的package包/类
@Nonnull
@Override
public Object getValue(@Nonnull CpsScript script) throws Exception {
Binding binding = script.getBinding();
script.println();
Object openshift;
if (binding.hasVariable(getName())) {
openshift = binding.getVariable(getName());
} else {
// Note that if this were a method rather than a constructor, we
// would need to mark it @NonCPS lest it throw
// CpsCallableInvocation.
openshift = script.getClass().getClassLoader()
.loadClass("com.openshift.jenkins.plugins.OpenShiftDSL")
.getConstructor(CpsScript.class).newInstance(script);
binding.setVariable(getName(), openshift);
}
return openshift;
}
示例5: createBinding
import groovy.lang.Binding; //导入方法依赖的package包/类
private Binding createBinding(Map<String, Object> objects, OutputStream out, OutputStream err)
throws UnsupportedEncodingException {
Binding binding = new Binding();
if (objects != null)
for (Map.Entry<String, Object> row : objects.entrySet())
binding.setVariable(row.getKey(), row.getValue());
binding.setVariable("out", createPrintStream(out));
binding.setVariable("err", createPrintStream(err));
binding.setVariable("activeSessions", new Closure<List<AbstractSession>>(this) {
@Override
public List<AbstractSession> call() {
return sshd.getActiveSessions();
}
});
return binding;
}
示例6: initClassStubData
import groovy.lang.Binding; //导入方法依赖的package包/类
@BeforeClass
public static void initClassStubData() throws IOException {
GroovyEvaluator groovyEvaluator = new GroovyEvaluator("123", "345");
GroovyDefaultVariables var = new GroovyDefaultVariables();
HashMap<String, Object> params = new HashMap<>();
params.put(KernelControlSetShellHandler.IMPORTS, var.getImports());
params.put(KernelControlSetShellHandler.CLASSPATH, var.getClassPath());
KernelParameters kernelParameters = new KernelParameters(params);
groovyEvaluator.setShellOptions(kernelParameters);
groovyClassLoader = groovyEvaluator.newEvaluator();
scriptBinding = new Binding();
scriptBinding.setVariable("beaker", NamespaceClient.getBeaker("345"));
groovyKernel = new GroovyKernelMock();
KernelManager.register(groovyKernel);
}
示例7: buildBinding
import groovy.lang.Binding; //导入方法依赖的package包/类
private Binding buildBinding(LepManagerService managerService,
LepMethod method) {
Binding binding = new Binding();
// add execution context values
ScopedContext executionContext = managerService.getContext(ContextScopes.EXECUTION);
if (executionContext != null) {
executionContext.getValues().forEach(binding::setVariable);
}
// add method arg values
final String[] parameterNames = method.getMethodSignature().getParameterNames();
final Object[] methodArgValues = method.getMethodArgValues();
for (int i = 0; i < parameterNames.length; i++) {
String paramName = parameterNames[i];
Object paramValue = methodArgValues[i];
binding.setVariable(paramName, paramValue);
}
return binding;
}
示例8: canBeAddedTo
import groovy.lang.Binding; //导入方法依赖的package包/类
/**
* Returns how many times the supplied item can be added to the given slot
* in the given bag by the given container. 0 means the item cannot be added
* to the slot at all.
*
* @param slot
* @return
*/
public int canBeAddedTo(BagType bag, int slot, InventoryContainer container) {
if (BagType.EQUIPPED.equals(bag)) {
if (!checkEquippedSlot(slot, container)) {
return 0;
}
if (s_equipCondition != null) {
Binding binding = new Binding();
binding.setVariable("slot", slot);
binding.setVariable("item", this);
return s_equipCondition.execute(container.getInventory().getConditionTarget(), binding) ? getStackSize() : 0;
}
} else if (BagType.QUICKUSE.equals(bag)) {
if (!Condition.areResultsOk(canBeAddedToQuickUse(container))) {
return 0;
}
}
InventoryCheckResult checkResult = container.getInventory().canAddItem(this);
if (checkResult.getError() != null) {
Log.log(checkResult.getError(), LogType.INVENTORY);
}
return checkResult.getAllowedStackSize();
}
示例9: main
import groovy.lang.Binding; //导入方法依赖的package包/类
public static void main(String[] args) {
List<String> rules = Lists.newArrayList();
rules.add("S <= 10");
rules.add("S + A <= 20");
rules.add("S + A + BP <= 55");
rules.add("C >= 5");
Binding binding = new Binding();
binding.setVariable("S", 5.0);
binding.setVariable("A", 5.0);
binding.setVariable("BP", 30.0);
binding.setVariable("B", 30.0);
binding.setVariable("C", 30.0);
GroovyShell shell = new GroovyShell(binding);
for (String rule : rules) {
Object result = shell.evaluate(rule);
System.out.println(result);
}
}
示例10: loadFolderQuantity
import groovy.lang.Binding; //导入方法依赖的package包/类
protected boolean loadFolderQuantity(Binding binding, AppFolder folder) {
if (!StringUtils.isBlank(folder.getQuantityScript())) {
binding.setVariable("folder", folder);
String styleVariable = "style";
binding.setVariable(styleVariable, null);
try {
Number qty = runScript(folder.getQuantityScript(), binding);
folder.setItemStyle((String) binding.getVariable(styleVariable));
folder.setQuantity(qty == null ? null : qty.intValue());
} catch (Exception e) {
log.warn("Unable to evaluate AppFolder quantity script for folder: id: {} , name: {}",
folder.getId(), folder.getName(), e);
return false;
}
}
return true;
}
示例11: run
import groovy.lang.Binding; //导入方法依赖的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);
}
}
示例12: runGroovyScript
import groovy.lang.Binding; //导入方法依赖的package包/类
@Authenticated
@Override
public String runGroovyScript(String scriptName) {
try {
Binding binding = new Binding();
binding.setVariable("persistence", persistence);
binding.setVariable("metadata", metadata);
binding.setVariable("configuration", configuration);
binding.setVariable("dataManager", dataManager);
Object result = scripting.runGroovyScript(scriptName, binding);
return String.valueOf(result);
} catch (Exception e) {
log.error("Error runGroovyScript", e);
return ExceptionUtils.getStackTrace(e);
}
}
示例13: evaluate
import groovy.lang.Binding; //导入方法依赖的package包/类
public Object evaluate(String expression, Map<String, Object> bindings)
throws ExecutionException {
binding = new Binding();
for (String bindName : bindings.keySet()) {
Object value = bindings.get(bindName);
DocumentReferenceTranslator docRefTranslator = getDocRefTranslator(value);
if (docRefTranslator != null) {
try {
if (!(docRefTranslator instanceof XmlBeanWrapperTranslator)) {
value = new XmlSlurper().parseText(docRefTranslator.realToString(value));
}
}
catch (Exception ex) {
throw new ExecutionException("Cannot parse document content: '" + bindName + "'", ex);
}
}
binding.setVariable(bindName, value);
}
return runScript(expression);
}
示例14: getValue
import groovy.lang.Binding; //导入方法依赖的package包/类
@Override
public String getValue(String orginData)
{
String value;
Binding binding = new Binding();
GroovyShell shell = new GroovyShell(binding);
binding.setVariable("globalMap", globalMap);
Object resObj = null;
try
{
resObj = shell.evaluate(groovyCls + orginData);
if(resObj != null)
{
value = resObj.toString();
}
else
{
value = "groovy not return!";
}
}
catch(CompilationFailedException e)
{
value = e.getMessage();
logger.error("Groovy动态数据语法错误!", e);
}
return value;
}
示例15: main
import groovy.lang.Binding; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
Binding binding = new Binding();
binding.setVariable("language", "Groovy");
GroovyShell shell = new GroovyShell(binding);
GroovyScriptEngine engine = new GroovyScriptEngine(new URL[]{GroovyTest.class.getClassLoader().getResource("/")});
Script script = shell.parse(GroovyTest.class.getClassLoader().getResource("random.groovy").toURI());
// System.out.println(script);
// script.invokeMethod("new SuRenRandom()", null);
// script.evaluate("new SuRenRandom()");
// engine.run("random.groovy", binding);
InputStream stream = GroovyTest.class.getClassLoader().getResource("random.groovy").openStream();
StringBuffer buf = new StringBuffer();
byte[] bf = new byte[1024];
int len = -1;
while((len = stream.read(bf)) != -1)
{
buf.append(new String(bf, 0, len));
}
buf.append("\n");
for(int i = 0; i < 30; i++)
{
System.out.println(shell.evaluate(buf.toString() + "new SuRenRandom().randomPhoneNum()"));
System.out.println(shell.evaluate(buf.toString() + "new SuRenRandom().randomEmail()"));
System.out.println(shell.evaluate(buf.toString() + "new SuRenRandom().randomZipCode()"));
}
}