Branch: refs/heads/user-defined-global-libs Home: https://github.com/jenkinsci/workflow-plugin Commit: 7b6d786dfaf98006113d3d076a57ed46c24d8258 https://github.com/jenkinsci/workflow-plugin/commit/7b6d786dfaf98006113d3d076a57ed46c24d8258 Author: Kohsuke Kawaguchi <k...@kohsuke.org> Date: 2015-06-20 (Sat, 20 Jun 2015)
Changed paths: M cps/pom.xml A cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsClosure2.java M cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsGroovyShell.java M cps/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsScript.java Log Message: ----------- Use a modified version of CpsClosure to make the 'sleep' method work. The method selection logic in the body of a closure is such that a method defined on groovy.lang.Closure object takes a precedence over any methods exposed via 'owner' or 'delegate'. This applies to so-called expando methods that are added externally (such as sleep), not just methods inheretently defined by JDK (such as hashCode). The following code illustrates this behavior: ===== class Foo { public void test() { sleep(3); // this prints fake-sleep(3) def c = { sleep(4); } // this does NOT print fake-sleep(4) c(); } public void sleep(long l) { System.out.println("fake-sleep(${l})"); } } new Foo().test() ===== Before PR 131, CPS transformation was incorrectly converting 'sleep(4)' above to 'this.sleep(4)', which will print out fake-sleep(4) because 'this' points to the Foo instance and not the closure instance. In PR 131, I fixed this bug in groovy-cps, which means now the sleep() call in the workflow is not calling into SleepStep, and instead rather goes into 'java.lang.Object.sleep(long)' added by Groovy. This change fixes it, in conjunction with cloudbees/groovy-sandbox #13, by defining the sleep() method explicitly on the closure class we use (CpsClosure2), and delegate that call to the closure 'owner'. The net result is that in workflow, such call will get routed to the DSL.invokeMethod() which then goes to SleepStep. See: https://github.com/cloudbees/groovy-cps/pull/13 -- You received this message because you are subscribed to the Google Groups "Jenkins Commits" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-commits+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.