groovy.lang.Binding.setProperty()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(252)

本文整理了Java中groovy.lang.Binding.setProperty()方法的一些代码示例,展示了Binding.setProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binding.setProperty()方法的具体详情如下:
包路径:groovy.lang.Binding
类名称:Binding
方法名:setProperty

Binding.setProperty介绍

[英]Overloaded to make variables appear as bean properties or via the subscript operator
[中]重载以使变量显示为bean属性或通过下标运算符

代码示例

代码示例来源:origin: jenkinsci/jenkins

public GroovyHookScript bind(String name, Object o) {
  bindings.setProperty(name,o);
  return this;
}

代码示例来源:origin: jenkinsci/jenkins

protected int run() throws Exception {
  // this allows the caller to manipulate the JVM state, so require the execute script privilege.
  Jenkins.getActiveInstance().checkPermission(Jenkins.RUN_SCRIPTS);
  Binding binding = new Binding();
  binding.setProperty("out",new PrintWriter(stdout,true));
  binding.setProperty("stdin",stdin);
  binding.setProperty("stdout",stdout);
  binding.setProperty("stderr",stderr);
  binding.setProperty("channel",channel);
  if (channel != null) {
    String j = getClientEnvironmentVariable("JOB_NAME");
    if (j != null) {
      Item job = Jenkins.getActiveInstance().getItemByFullName(j);
      binding.setProperty("currentJob", job);
      String b = getClientEnvironmentVariable("BUILD_NUMBER");
      if (b != null && job instanceof AbstractProject) {
        Run r = ((AbstractProject) job).getBuildByNumber(Integer.parseInt(b));
        binding.setProperty("currentBuild", r);
      }
    }
  }
  GroovyShell groovy = new GroovyShell(Jenkins.getActiveInstance().getPluginManager().uberClassLoader, binding);
  groovy.run(loadScript(),"RemoteClass",remaining.toArray(new String[remaining.size()]));
  return 0;
}

代码示例来源:origin: org.codehaus.groovy/groovy

private void doSetProperty(String property, Object newValue) {
  Closure[] accessors = resolveExplicitProperty(property);
  if (accessors != null) {
    if (accessors[1] == null) {
      // read only property
      throw new MissingPropertyException(property + " is declared as read only");
    } else {
      accessors[1].call(newValue);
    }
  } else {
    super.setProperty(property, newValue);
  }
}

代码示例来源:origin: jenkinsci/jenkins

binding.setProperty("out", new PrintWriter(stdout,true));
binding.setProperty("hudson", Jenkins.getActiveInstance()); // backward compatibility
binding.setProperty("jenkins", Jenkins.getActiveInstance());

代码示例来源:origin: org.codehaus.groovy/groovy

context.setProperty("args", args);

代码示例来源:origin: crashub/crash

binding.setProperty("args", args);

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public GroovyHookScript bind(String name, Object o) {
  bindings.setProperty(name,o);
  return this;
}

代码示例来源:origin: com.anrisoftware.sscontrol/sscontrol-core

private Binding createBinding(Map<String, Object> variables,
    ProfileService profile) {
  Binding binding = new Binding();
  binding.setProperty("scriptBuilderLogger", scriptBuilderLogger);
  binding.setProperty("profile", profile);
  binding.setProperty("injector", parent);
  for (Map.Entry<String, Object> entry : variables.entrySet()) {
    binding.setProperty(entry.getKey(), entry.getValue());
  }
  return binding;
}

代码示例来源:origin: hortonworks/streamline

private void addToBinding(Map<String, Object> fieldsToValues, Binding binding) {
  for (Map.Entry<String, Object> entry : fieldsToValues.entrySet()) {
    binding.setProperty(entry.getKey(), entry.getValue());
  }
}

代码示例来源:origin: disney/groovity

public void run(String path) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException{
  PrintWriter pw = new PrintWriter(System.out);
  try{
    pw.println("RUNNING "+path);
    Binding binding = new Binding();
    binding.setProperty("out", pw);
    Object o = groovity.run(path, binding);
    pw.println();
    if(o!=null && !(o instanceof Closeable)){
      pw.println("DONE "+path+", return value was "+o);
    }
    else{
      pw.println("DONE "+path);
    }
  }
  finally{
    pw.flush();
  }
}

代码示例来源:origin: com.disney.groovity/groovity-servlet-container

public void run(String path) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException{
  PrintWriter pw = new PrintWriter(System.out);
  try{
    pw.println("RUNNING "+path);
    Binding binding = new Binding();
    binding.setProperty("out", pw);
    Object o = groovity.run(path, binding);
    pw.println();
    if(o!=null && !(o instanceof Closeable)){
      pw.println("DONE "+path+", return value was "+o);
    }
    else{
      pw.println("DONE "+path);
    }
  }
  finally{
    pw.flush();
  }
}

代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm

private void doSetProperty(String property, Object newValue) {
  Closure[] accessors = resolveExplicitProperty(property);
  if (accessors != null) {
    if (accessors[1] == null) {
      // read only property
      throw new MissingPropertyException(property + " is declared as read only");
    } else {
      accessors[1].call(newValue);
    }
  } else {
    super.setProperty(property, newValue);
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy-jdk14

private void doSetProperty(String property, Object newValue) {
  Closure[] accessors = resolveExplicitProperty(property);
  if (accessors != null) {
    if (accessors[1] == null) {
      // read only property
      throw new MissingPropertyException(property + " is declared as read only");
    } else {
      accessors[1].call(newValue);
    }
  } else {
    super.setProperty(property, newValue);
  }
}

代码示例来源:origin: org.kohsuke.droovy/groovy

private void doSetProperty(String property, Object newValue) {
  Closure[] accessors = resolveExplicitProperty(property);
  if (accessors != null) {
    if (accessors[1] == null) {
      // read only property
      throw new MissingPropertyException(property + " is declared as read only");
    } else {
      accessors[1].call(newValue);
    }
  } else {
    super.setProperty(property, newValue);
  }
}

代码示例来源:origin: iTransformers/netTransformer

public void transformRawDataToGraphml(Reader in, Writer out) {
    try {

      GPathResult response = new XmlSlurper().parse(new InputSource(in));
      Binding binding = new Binding();
      binding.setProperty("input", response);
      binding.setProperty("output", out);

      // binding = new Binding();
      // Expect4Groovy.createBindings(connection, binding, true);
      // binding.setProperty("params", params);

      // String gseRoots = new File().toURI().toURL().toString();
      String[] roots =  new String[]{projectPath+"/iDiscover/conf/groovy/"+File.separator};
      GroovyScriptEngine gse = new GroovyScriptEngine(roots);
      gse.run("RawData2GraphmlTransformer.groovy", binding);

//            Class clazz = Class.forName(new File(projectPath,rawData2GraphmlGroovyTransformer).toURI().toURL().toString());
//            Constructor constructor = clazz.getDeclaredConstructor(Binding.class);
//            Script script = (Script) constructor.newInstance(binding);
//            script.run();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

代码示例来源:origin: PerfCake/PerfCake

@Override
  public synchronized Scenario getScenario() throws PerfCakeException {
   if (scenario == null) {
     final Binding binding = new Binding();
     binding.setProperty("dslScript", scenarioDefinition);

     final ScenarioDelegate scenarioDelegate = new ScenarioDelegate();
     scenarioDelegate.setBinding(binding);
     scenario = (Scenario) scenarioDelegate.run();
   }

   return scenario;
  }
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

protected int run() throws Exception {
  // this allows the caller to manipulate the JVM state, so require the admin privilege.
  Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
  Binding binding = new Binding();
  binding.setProperty("out",new PrintWriter(stdout,true));
  String j = getClientEnvironmentVariable("JOB_NAME");
  if (j!=null) {
    Item job = Hudson.getInstance().getItemByFullName(j);
    binding.setProperty("currentJob", job);
    String b = getClientEnvironmentVariable("BUILD_NUMBER");
    if (b!=null && job instanceof AbstractProject) {
      Run r = ((AbstractProject) job).getBuildByNumber(Integer.parseInt(b));
      binding.setProperty("currentBuild", r);
    }
  }
  GroovyShell groovy = new GroovyShell(binding);
  groovy.run(loadScript(),"RemoteClass",remaining.toArray(new String[remaining.size()]));
  return 0;
}

代码示例来源:origin: hudson/hudson-2.x

protected int run() throws Exception {
  // this allows the caller to manipulate the JVM state, so require the admin privilege.
  Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
  Binding binding = new Binding();
  binding.setProperty("out",new PrintWriter(stdout,true));
  String j = getClientEnvironmentVariable("JOB_NAME");
  if (j!=null) {
    Item job = Hudson.getInstance().getItemByFullName(j);
    binding.setProperty("currentJob", job);
    String b = getClientEnvironmentVariable("BUILD_NUMBER");
    if (b!=null && job instanceof AbstractProject) {
      Run r = ((AbstractProject) job).getBuildByNumber(Integer.parseInt(b));
      binding.setProperty("currentBuild", r);
    }
  }
  GroovyShell groovy = new GroovyShell(binding);
  groovy.run(loadScript(),"RemoteClass",remaining.toArray(new String[remaining.size()]));
  return 0;
}

代码示例来源:origin: freeplane/freeplane

private void updateBinding(final NodeModel node, ScriptContext scriptContext) {
  Binding binding = compiledScript.getBinding();
  binding.setVariable("c", ProxyFactory.createController(scriptContext));
  binding.setVariable("node", ProxyFactory.createNode(node, scriptContext));
  for (Entry<String, Object> entry : ScriptingConfiguration.getStaticProperties().entrySet()) {
    binding.setProperty(entry.getKey(), entry.getValue());
  }
  compiledScript.setBinding(binding);
}

代码示例来源:origin: io.vertx/vertx-rx-groovy

private void runScript(String script) throws Exception {
 Vertx vertx = Vertx.vertx();
 try {
  GroovyShell gcl = new GroovyShell();
  Script s = gcl.parse(new File(script));
  Binding binding = new Binding();
  binding.setProperty("test", this);
  binding.setProperty("vertx", vertx);
  s.setBinding(binding);
  s.run();
 } finally {
  CountDownLatch latch = new CountDownLatch(1);
  vertx.close(v -> {
   latch.countDown();
  });
  latch.await();
 }
}

相关文章