From 10b20952addbdd025cb95817f5c3ad1fc6c7bcea Mon Sep 17 00:00:00 2001 From: kohsuke Date: Thu, 31 Jul 2008 17:45:54 +0000 Subject: [PATCH] collapse the structure to remain backward compatible with the JSON structure before 1.238. Updated Ant and Maven to use the newer style, but there are plugins out there that expect older form submission format. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11151 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/Hudson.java | 11 +++++++++-- core/src/main/java/hudson/tasks/Ant.java | 5 +++-- core/src/main/java/hudson/tasks/Maven.java | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index 93d2e8cfd5..5c78727a0b 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -1544,10 +1544,10 @@ public final class Hudson extends View implements ItemGroup, Node, boolean result = true; for( Descriptor d : BuildStep.BUILDERS ) - result &= d.configure(req,json.getJSONObject(d.getJsonSafeClassName())); + result &= configureDescriptor(req,json,d); for( Descriptor d : BuildStep.PUBLISHERS ) - result &= d.configure(req,json.getJSONObject(d.getJsonSafeClassName())); + result &= configureDescriptor(req,json,d); for( Descriptor d : BuildWrappers.WRAPPERS ) result &= d.configure(req); @@ -1574,6 +1574,13 @@ public final class Hudson extends View implements ItemGroup, Node, } } + private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor d) throws FormException { + // collapse the structure to remain backward compatible with the JSON structure before 1.238 + JSONObject js = json.getJSONObject(d.getJsonSafeClassName()); + json.putAll(js); + return d.configure(req, js); + } + /** * Accepts submission from the configuration page. */ diff --git a/core/src/main/java/hudson/tasks/Ant.java b/core/src/main/java/hudson/tasks/Ant.java index 4047e49828..8aed9609d5 100644 --- a/core/src/main/java/hudson/tasks/Ant.java +++ b/core/src/main/java/hudson/tasks/Ant.java @@ -260,9 +260,10 @@ public class Ant extends Builder { return installations; } - public boolean configure(StaplerRequest req) { + @Override + public boolean configure(StaplerRequest req, JSONObject json) throws FormException { installations = req.bindJSONToList( - AntInstallation.class, req.getSubmittedForm().get("ant")).toArray(new AntInstallation[0]); + AntInstallation.class, json.get("ant")).toArray(new AntInstallation[0]); save(); return true; } diff --git a/core/src/main/java/hudson/tasks/Maven.java b/core/src/main/java/hudson/tasks/Maven.java index 88f448ae68..3f709cb77f 100644 --- a/core/src/main/java/hudson/tasks/Maven.java +++ b/core/src/main/java/hudson/tasks/Maven.java @@ -225,9 +225,9 @@ public class Maven extends Builder { return installations; } - public boolean configure(StaplerRequest req) { - this.installations = req.bindJSONToList(MavenInstallation.class, req.getSubmittedForm().get("maven")) - .toArray(new MavenInstallation[0]); + @Override + public boolean configure(StaplerRequest req, JSONObject json) throws FormException { + this.installations = req.bindJSONToList(MavenInstallation.class, json.get("maven")).toArray(new MavenInstallation[0]); save(); return true; } -- GitLab