diff --git a/changelog.html b/changelog.html index de9fe51ae28d..a77d911c66c7 100644 --- a/changelog.html +++ b/changelog.html @@ -100,6 +100,8 @@
  • Added a new extension point for custom checkout behaviour, especially targeted for matrix projects. (pull 482) +
  • + Allow the tree parameter and the xpath parameter to be used together in the REST API.
  • Enabled concurrent build support for matrix projects (issue 6747) diff --git a/core/src/main/java/hudson/model/Api.java b/core/src/main/java/hudson/model/Api.java index 3ed37331a47a..829c0a1ccac9 100644 --- a/core/src/main/java/hudson/model/Api.java +++ b/core/src/main/java/hudson/model/Api.java @@ -35,6 +35,7 @@ import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.export.*; +import org.kohsuke.stapler.export.TreePruner.ByDepth; import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; @@ -79,6 +80,7 @@ public String getSearchUrl() { public void doXml(StaplerRequest req, StaplerResponse rsp, @QueryParameter String xpath, @QueryParameter String wrapper, + @QueryParameter String tree, @QueryParameter int depth) throws IOException, ServletException { String[] excludes = req.getParameterValues("exclude"); @@ -92,7 +94,8 @@ public void doXml(StaplerRequest req, StaplerResponse rsp, // first write to String Model p = MODEL_BUILDER.get(bean.getClass()); - p.writeTo(bean,depth,Flavor.XML.createDataWriter(bean,sw)); + TreePruner pruner = (tree!=null) ? new NamedPathPruner(tree) : new ByDepth(1 - depth); + p.writeTo(bean,pruner,Flavor.XML.createDataWriter(bean,sw)); // apply XPath Object result; diff --git a/core/src/main/resources/hudson/model/Api/index.jelly b/core/src/main/resources/hudson/model/Api/index.jelly index 87f57a0a02c5..2ca5b63f6e47 100644 --- a/core/src/main/resources/hudson/model/Api/index.jelly +++ b/core/src/main/resources/hudson/model/Api/index.jelly @@ -48,13 +48,21 @@ THE SOFTWARE. For XPath that matches multiple nodes, you need to also specify the "wrapper" query parameter to specify the name of the root XML element to be create so that the resulting XML becomes well-formed. -

    +

    Similarly exclude query parameter can be used to exclude nodes that match the given XPath from the result. This is useful for trimming down the amount of data you fetch (but again see below). This query parameter can be specified multiple times.

    +

    + XPath filtering is powerful, and you can have it only return a very small data, but note that + the server still has to build a full DOM of the raw data, which could cause a large memory spike. + To avoid overloading the server, consider using the tree parameter, or use the xpath parameter + in conjunction with the tree parameter. When used together, the result of the tree parameter + filtering is built into DOM, then the XPath is applied to compute the final return value. In this way, + you can often substantially reduce the size of DOM built in memory. +

    JSON API