public GroovyHookScript bind(String name, Object o) { bindings.setProperty(name,o); return this; }
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; }
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); } }
binding.setProperty("out", new PrintWriter(stdout,true)); binding.setProperty("hudson", Jenkins.getActiveInstance()); // backward compatibility binding.setProperty("jenkins", Jenkins.getActiveInstance());
context.setProperty("args", args);
binding.setProperty("args", args);
public GroovyHookScript bind(String name, Object o) { bindings.setProperty(name,o); return this; }
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; }
private void addToBinding(Map<String, Object> fieldsToValues, Binding binding) { for (Map.Entry<String, Object> entry : fieldsToValues.entrySet()) { binding.setProperty(entry.getKey(), entry.getValue()); } }
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(); } }
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(); } }
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); } }
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); } }
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); } }
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(); } }
@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; } }
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; }
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; }
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); }
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(); } }