diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index dc63df9e42..a5e4cdefc0 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -70,7 +70,6 @@ import hudson.scm.SCMDescriptor; import hudson.util.Secret; import hudson.views.MyViewsTabBar; import hudson.views.ViewsTabBar; -import hudson.widgets.HeteroListConfigPageRenderer; import hudson.widgets.RenderOnDemandClosure; import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken; import org.apache.commons.jelly.JellyContext; diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index 7bf2a608f0..d991487dc1 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -305,6 +305,11 @@ public abstract class Descriptor> implements Saveable { */ public static String getCurrentDescriptorByNameUrl() { StaplerRequest req = Stapler.getCurrentRequest(); + + // this override allows RenderOnDemandClosure to preserve the proper value + Object url = req.getAttribute("currentDescriptorByNameUrl"); + if (url!=null) return url.toString(); + Ancestor a = req.findAncestor(DescriptorByNameOwner.class); return a.getUrl(); } diff --git a/core/src/main/java/hudson/widgets/RenderOnDemandClosure.java b/core/src/main/java/hudson/widgets/RenderOnDemandClosure.java index d6cf06225c..14ae1a0e93 100644 --- a/core/src/main/java/hudson/widgets/RenderOnDemandClosure.java +++ b/core/src/main/java/hudson/widgets/RenderOnDemandClosure.java @@ -24,12 +24,15 @@ package hudson.widgets; import hudson.Util; +import hudson.model.DescriptorByNameOwner; import hudson.util.IOException2; import hudson.util.PackedMap; import org.apache.commons.jelly.JellyContext; import org.apache.commons.jelly.JellyTagException; import org.apache.commons.jelly.Script; +import org.kohsuke.stapler.Ancestor; import org.kohsuke.stapler.HttpResponse; +import org.kohsuke.stapler.Stapler; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.bind.JavaScriptMethod; @@ -37,8 +40,12 @@ import org.kohsuke.stapler.jelly.DefaultScriptInvoker; import javax.servlet.ServletException; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Captured Jelly {@link Script} that can be rendered later on demand from JavaScript. @@ -46,15 +53,32 @@ import java.util.Map; * @author Kohsuke Kawaguchi */ public class RenderOnDemandClosure { - private final Script body; + /** + * Captures the recursive taglib call stack. + */ + private final Script[] bodyStack; private final Map variables; + private final String currentDescriptorByNameUrl; public RenderOnDemandClosure(JellyContext context, String attributesToCapture) { - body = (Script) context.getVariable("org.apache.commons.jelly.body"); + List