Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-5940

Direct specification of desired paths in /api/xml

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • core
    • None

      Using .../api/xml?depth=...&exclude=//... has proven to be extremely inefficient in some cases, as well as difficult to use (since you have to constantly be adding exclusions for newly visible elements you have no interest in). Here is a typical negative list:

      ...&exclude=//view/job/url&exclude=//view/job/color&exclude=//description&exclude=//job/build&exclude=//healthReport&exclude=//firstBuild&exclude=//keepDependencies&exclude=//nextBuildNumber&exclude=//property&exclude=//action&exclude=//upstreamProject&exclude=//downstreamProject&exclude=//queueItem&exclude=//scm

      Would prefer to be able to directly specify the kinds of things you do want to have returned. This would mean changes to Stapler.

      For example:

      .../api/xml?paths=job/name,job/displayName,job/color,view/name,view/job/name

      would return only elements matching //job/name, //job/displayName, etc. (The root element need not be listed.)

      Alternate syntax (harder to parse by Hudson but arguably easier to read):

      .../api/xml?paths=job[name,displayName,color],view[name,job[name]]

      Might be feasible to do for JSON and Python formats as well as XML, which would also be nice since those lack XPath support.

          [JENKINS-5940] Direct specification of desired paths in /api/xml

          Jesse Glick added a comment -

          Do you need a patch for this?

          Jesse Glick added a comment - Do you need a patch for this?

          Code changed in stapler
          User: : jglick
          Path:
          trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java
          https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java?view=diff&rev=1561&p1=trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java&p2=trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java&r1=1560&r2=1561
          trunk/stapler/core/src/main/java/org/kohsuke/stapler/StaplerResponse.java
          https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/main/java/org/kohsuke/stapler/StaplerResponse.java?view=diff&rev=1561&p1=trunk/stapler/core/src/main/java/org/kohsuke/stapler/StaplerResponse.java&p2=trunk/stapler/core/src/main/java/org/kohsuke/stapler/StaplerResponse.java&r1=1560&r2=1561
          trunk/stapler/core/src/main/java/org/kohsuke/stapler/export/NamedPathPruner.java
          https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/main/java/org/kohsuke/stapler/export/NamedPathPruner.java?view=auto&rev=1561
          trunk/stapler/core/src/test/java/org/kohsuke/stapler/export/NamedPathPrunerTest.java
          https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/test/java/org/kohsuke/stapler/export/NamedPathPrunerTest.java?view=auto&rev=1561

          Log:
          JENKINS-5940 Ability to directly specify desired paths in Stapler API output, rather than printing to a given depth and then excluding unwanted subtrees.
          For some purposes this is easier to use, more reliable, and faster than the former facility. Also supports JSON/Python output, not just XML.
          Demo query: http://localhost:8080/api/xml?tree=jobs[name,displayName,color,url,lastBuild[number]],views[name,url,jobs[name]],primaryView[name]
          (Note that since TreePruner can only reject a subtree, not reorder properties, the output will remain alphabetized regardless of the order given in the tree spec.)
          Will take effect in Hudson as soon as main/core requires stapler/core >=1.146.

          SCM/JIRA link daemon added a comment - Code changed in stapler User: : jglick Path: trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java?view=diff&rev=1561&p1=trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java&p2=trunk/stapler/core/src/main/java/org/kohsuke/stapler/ResponseImpl.java&r1=1560&r2=1561 trunk/stapler/core/src/main/java/org/kohsuke/stapler/StaplerResponse.java https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/main/java/org/kohsuke/stapler/StaplerResponse.java?view=diff&rev=1561&p1=trunk/stapler/core/src/main/java/org/kohsuke/stapler/StaplerResponse.java&p2=trunk/stapler/core/src/main/java/org/kohsuke/stapler/StaplerResponse.java&r1=1560&r2=1561 trunk/stapler/core/src/main/java/org/kohsuke/stapler/export/NamedPathPruner.java https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/main/java/org/kohsuke/stapler/export/NamedPathPruner.java?view=auto&rev=1561 trunk/stapler/core/src/test/java/org/kohsuke/stapler/export/NamedPathPrunerTest.java https://stapler.dev.java.net/source/browse/stapler/trunk/stapler/core/src/test/java/org/kohsuke/stapler/export/NamedPathPrunerTest.java?view=auto&rev=1561 Log: JENKINS-5940 Ability to directly specify desired paths in Stapler API output, rather than printing to a given depth and then excluding unwanted subtrees. For some purposes this is easier to use, more reliable, and faster than the former facility. Also supports JSON/Python output, not just XML. Demo query: http://localhost:8080/api/xml?tree=jobs[name,displayName,color,url,lastBuild[number]],views[name,url,jobs[name]],primaryView[name ] (Note that since TreePruner can only reject a subtree, not reorder properties, the output will remain alphabetized regardless of the order given in the tree spec.) Will take effect in Hudson as soon as main/core requires stapler/core >=1.146.

          Code changed in hudson
          User: : jglick
          Path:
          trunk/hudson/main/core/src/main/resources/hudson/model/Api/index.jelly
          http://jenkins-ci.org/commit/32846
          Log:
          JENKINS-5940 Documenting.

          SCM/JIRA link daemon added a comment - Code changed in hudson User: : jglick Path: trunk/hudson/main/core/src/main/resources/hudson/model/Api/index.jelly http://jenkins-ci.org/commit/32846 Log: JENKINS-5940 Documenting.

          Code changed in hudson
          User: : jglick
          Path:
          trunk/hudson/main/core/src/main/resources/hudson/model/Api/index.jelly
          http://jenkins-ci.org/commit/32847
          Log:
          JENKINS-5940 Documenting further.

          SCM/JIRA link daemon added a comment - Code changed in hudson User: : jglick Path: trunk/hudson/main/core/src/main/resources/hudson/model/Api/index.jelly http://jenkins-ci.org/commit/32847 Log: JENKINS-5940 Documenting further.

          Code changed in hudson
          User: : jglick
          Path:
          trunk/www/changelog.html
          http://jenkins-ci.org/commit/32909
          Log:
          [FIXED JENKINS-5940] Integrated into Hudson POM.

          SCM/JIRA link daemon added a comment - Code changed in hudson User: : jglick Path: trunk/www/changelog.html http://jenkins-ci.org/commit/32909 Log: [FIXED JENKINS-5940] Integrated into Hudson POM.

            jglick Jesse Glick
            jglick Jesse Glick
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: