# HG changeset patch # User cin # Date 2025-08-17 19:47:17 # Node ID 4277fa4026087eaaeba8f7b4efb137f481a93b9d # Parent 0e291927620c14942a6d20b55d21c2329e5fb399 sync diff --git a/common/src/main/java/org/implab/gradle/common/utils/Closures.java b/common/src/main/java/org/implab/gradle/common/utils/Closures.java --- a/common/src/main/java/org/implab/gradle/common/utils/Closures.java +++ b/common/src/main/java/org/implab/gradle/common/utils/Closures.java @@ -10,12 +10,25 @@ public final class Closures { private Closures() { } + /** + * Wraps {@link Action} around the specified closure. The parameter + * of the action will be used as delegate in the specified closure. + * + * @param The type of the action parameter + * @param closure The closure + * @return + */ public static Action action(Closure closure) { return arg -> apply(closure, arg); } public static void apply(Closure action, Object target) { - action.setDelegate(target); - action.call(target); + var prevDelegate = action.getDelegate(); + try { + action.setDelegate(target); + action.call(target); + } finally { + action.setDelegate(prevDelegate); + } } }