From 873de8cd22738150e49bd8cda0d0b510b554fa7d Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Sun, 28 Sep 2014 19:33:47 -0700 Subject: [PATCH 1/3] Switch the source of a number of AbstractProject config options from StaplerRequest to JSONObject. This change shifts the way a number of form elements are accessed when handling AbstractProject's doConfigSubmit from using "req.getParameter(...)" style access to using JSON-style (structured form submission) access through "reg.getSubmittedForm()". --- .../java/hudson/model/AbstractProject.java | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 947c5179f7..5041dab8a8 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1789,24 +1789,38 @@ public abstract class AbstractProject

,R extends A super.submit(req,rsp); JSONObject json = req.getSubmittedForm(); - makeDisabled(req.getParameter("disable")!=null); + // "disable": {} + makeDisabled(json.has("disable")); - jdk = req.getParameter("jdk"); - if(req.getParameter("hasCustomQuietPeriod")!=null) { - quietPeriod = Integer.parseInt(req.getParameter("quiet_period")); + jdk = json.optString("jdk", null); + + // "hasCustomQuietPeriod": {"quiet_period": "3"} + JSONObject customQuietPeriodJson = json.optJSONObject("hasCustomQuietPeriod"); + if(customQuietPeriodJson!=null && !customQuietPeriodJson.isNullObject()) { + quietPeriod = customQuietPeriodJson.optInt("quiet_period"); } else { quietPeriod = null; } - if(req.getParameter("hasCustomScmCheckoutRetryCount")!=null) { - scmCheckoutRetryCount = Integer.parseInt(req.getParameter("scmCheckoutRetryCount")); + + // "hasCustomScmCheckoutRetryCount": {"scmCheckoutRetryCount": "12"} + JSONObject customRetryJson = json.optJSONObject("hasCustomScmCheckoutRetryCount"); + if(customRetryJson!=null && !customRetryJson.isNullObject()) { + scmCheckoutRetryCount = customRetryJson.optInt("scmCheckoutRetryCount"); } else { scmCheckoutRetryCount = null; } - blockBuildWhenDownstreamBuilding = req.getParameter("blockBuildWhenDownstreamBuilding")!=null; - blockBuildWhenUpstreamBuilding = req.getParameter("blockBuildWhenUpstreamBuilding")!=null; - if(req.hasParameter("customWorkspace")) { - customWorkspace = Util.fixEmptyAndTrim(req.getParameter("customWorkspace.directory")); + // "blockBuildWhenDownstreamBuilding": {} + blockBuildWhenDownstreamBuilding = json.has("blockBuildWhenDownstreamBuilding"); + + // "blockBuildWhenUpstreamBuilding": {} + blockBuildWhenUpstreamBuilding = json.has("blockBuildWhenUpstreamBuilding"); + + // "customWorkspace": {"directory": "aaa"} + JSONObject customWorkspaceJson = json.optJSONObject("customWorkspace"); + if(customWorkspace!=null && !customWorkspaceJson.isNullObject()) { + customWorkspace = Util.fixEmptyAndTrim( + customWorkspaceJson.optString("directory")); } else { customWorkspace = null; } @@ -1817,17 +1831,19 @@ public abstract class AbstractProject

,R extends A else scmCheckoutStrategy = null; - - if(req.getParameter("hasSlaveAffinity")!=null) { - assignedNode = Util.fixEmptyAndTrim(req.getParameter("_.assignedLabelString")); + + JSONObject slaveAffinity = json.getJSONObject("hasSlaveAffinity"); + if(slaveAffinity!=null && !slaveAffinity.isNullObject()) { + assignedNode = Util.fixEmptyAndTrim( + slaveAffinity.optString("assignedLabelString")); } else { assignedNode = null; } canRoam = assignedNode==null; - keepDependencies = req.getParameter("keepDependencies") != null; + keepDependencies = json.has("keepDependencies"); - concurrentBuild = req.getSubmittedForm().has("concurrentBuild"); + concurrentBuild = json.has("concurrentBuild"); authToken = BuildAuthorizationToken.create(req); From 86c911e8b9ba31cef77a7cf44179017dc9dc35db Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Sun, 28 Sep 2014 21:10:40 -0700 Subject: [PATCH 2/3] Switch to using inline optionalBlock for several AbstractProject checkboxes so that we are passed a boolean, instead of either null or {}. NOTE: The discrepancy between inline-optionalBlock and f:entry/f:checkbox is the text alignment, which optionalBlock keeps consistent with other elements (and what is done for these today). --- .../main/java/hudson/model/AbstractProject.java | 14 +++++++------- .../config-blockWhenDownstreamBuilding.jelly | 3 ++- .../project/config-blockWhenUpstreamBuilding.jelly | 3 ++- .../hudson/project/config-concurrentBuild.jelly | 2 +- .../lib/hudson/project/config-disableBuild.jelly | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 5041dab8a8..7f55e4b9c1 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1789,8 +1789,8 @@ public abstract class AbstractProject

,R extends A super.submit(req,rsp); JSONObject json = req.getSubmittedForm(); - // "disable": {} - makeDisabled(json.has("disable")); + // "disable": true + makeDisabled(json.optBoolean("disable")); jdk = json.optString("jdk", null); @@ -1810,11 +1810,11 @@ public abstract class AbstractProject

,R extends A scmCheckoutRetryCount = null; } - // "blockBuildWhenDownstreamBuilding": {} - blockBuildWhenDownstreamBuilding = json.has("blockBuildWhenDownstreamBuilding"); + // "blockBuildWhenDownstreamBuilding": true + blockBuildWhenDownstreamBuilding = json.optBoolean("blockBuildWhenDownstreamBuilding"); - // "blockBuildWhenUpstreamBuilding": {} - blockBuildWhenUpstreamBuilding = json.has("blockBuildWhenUpstreamBuilding"); + // "blockBuildWhenUpstreamBuilding": true + blockBuildWhenUpstreamBuilding = json.optBoolean("blockBuildWhenUpstreamBuilding"); // "customWorkspace": {"directory": "aaa"} JSONObject customWorkspaceJson = json.optJSONObject("customWorkspace"); @@ -1843,7 +1843,7 @@ public abstract class AbstractProject

,R extends A keepDependencies = json.has("keepDependencies"); - concurrentBuild = json.has("concurrentBuild"); + concurrentBuild = json.optBoolean("concurrentBuild"); authToken = BuildAuthorizationToken.create(req); diff --git a/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly b/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly index 2b0c94a313..2d52059038 100644 --- a/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly +++ b/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly @@ -28,5 +28,6 @@ THE SOFTWARE. + checked="${it.blockBuildWhenDownstreamBuilding()}" + inline="true" /> diff --git a/core/src/main/resources/lib/hudson/project/config-blockWhenUpstreamBuilding.jelly b/core/src/main/resources/lib/hudson/project/config-blockWhenUpstreamBuilding.jelly index ad1b1f1d1c..aa710e87f9 100644 --- a/core/src/main/resources/lib/hudson/project/config-blockWhenUpstreamBuilding.jelly +++ b/core/src/main/resources/lib/hudson/project/config-blockWhenUpstreamBuilding.jelly @@ -28,5 +28,6 @@ THE SOFTWARE. + checked="${it.blockBuildWhenUpstreamBuilding()}" + inline="true" /> \ No newline at end of file diff --git a/core/src/main/resources/lib/hudson/project/config-concurrentBuild.jelly b/core/src/main/resources/lib/hudson/project/config-concurrentBuild.jelly index 25a19fa3f8..87e05da8a0 100644 --- a/core/src/main/resources/lib/hudson/project/config-concurrentBuild.jelly +++ b/core/src/main/resources/lib/hudson/project/config-concurrentBuild.jelly @@ -27,5 +27,5 @@ THE SOFTWARE. --> - + \ No newline at end of file diff --git a/core/src/main/resources/lib/hudson/project/config-disableBuild.jelly b/core/src/main/resources/lib/hudson/project/config-disableBuild.jelly index ac8347d732..12738ee939 100644 --- a/core/src/main/resources/lib/hudson/project/config-disableBuild.jelly +++ b/core/src/main/resources/lib/hudson/project/config-disableBuild.jelly @@ -28,5 +28,5 @@ THE SOFTWARE. + help="/help/project-config/disable.html" inline="true" /> \ No newline at end of file From eec43983a3bdfce6de45ca0559d8a9f8a1250b71 Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Mon, 29 Sep 2014 09:36:19 -0700 Subject: [PATCH 3/3] This change converts several optionalBlock's wrapping a single field to inline="true". By converting several optionalBlock entries to use inline="true", we convert the submitted JSON from: "hasPropertyFoo": { "propertyFoo": "value" }, which is a somewhat unnatural naming scheme, to: "hasPropertyFoo": true, "propertyFoo": "value", This enables us to use the pattern: if(json.optBoolean("hasPropertyFoo", json.has("propertyFoo"))) { ... } To permit either of the following as JSON blobs, for specifying a value for "propertyFoo": 1) "hasPropertyFoo": true, # What comes through from jelly "propertyFoo": "value", 2) "propertyFoo": "value", It also allows any of the following as JSON blobs, for NOT specifying a value for "propertyFoo": 3) "hasPropertyFoo": false, # What comes through from jelly "propertyFoo": "value", 4) "hasPropertyFoo": false, 5) (nothing specified) NOTE: The main interest in flexibility in what JSON comes through is in support of: https://wiki.jenkins-ci.org/display/JENKINS/YAML+Project+Plugin, this is also the purpose of the couple renames that are mixed in with this. --- .../java/hudson/model/AbstractProject.java | 38 ++++++------------- .../hudson/project/config-assignedLabel.jelly | 6 +-- .../project/config-customWorkspace.jelly | 7 ++-- .../hudson/project/config-quietPeriod.jelly | 2 +- .../hudson/project/config-retryCount.jelly | 2 +- .../model/labels/LabelExpressionTest.java | 4 +- 6 files changed, 23 insertions(+), 36 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 7f55e4b9c1..3383aafaf5 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1789,38 +1789,27 @@ public abstract class AbstractProject

,R extends A super.submit(req,rsp); JSONObject json = req.getSubmittedForm(); - // "disable": true makeDisabled(json.optBoolean("disable")); jdk = json.optString("jdk", null); - // "hasCustomQuietPeriod": {"quiet_period": "3"} - JSONObject customQuietPeriodJson = json.optJSONObject("hasCustomQuietPeriod"); - if(customQuietPeriodJson!=null && !customQuietPeriodJson.isNullObject()) { - quietPeriod = customQuietPeriodJson.optInt("quiet_period"); + if(json.optBoolean("hasCustomQuietPeriod", json.has("quiet_period"))) { + quietPeriod = json.optInt("quiet_period"); } else { quietPeriod = null; } - // "hasCustomScmCheckoutRetryCount": {"scmCheckoutRetryCount": "12"} - JSONObject customRetryJson = json.optJSONObject("hasCustomScmCheckoutRetryCount"); - if(customRetryJson!=null && !customRetryJson.isNullObject()) { - scmCheckoutRetryCount = customRetryJson.optInt("scmCheckoutRetryCount"); + if(json.optBoolean("hasCustomScmCheckoutRetryCount", json.has("scmCheckoutRetryCount"))) { + scmCheckoutRetryCount = json.optInt("scmCheckoutRetryCount"); } else { scmCheckoutRetryCount = null; } - // "blockBuildWhenDownstreamBuilding": true blockBuildWhenDownstreamBuilding = json.optBoolean("blockBuildWhenDownstreamBuilding"); - - // "blockBuildWhenUpstreamBuilding": true blockBuildWhenUpstreamBuilding = json.optBoolean("blockBuildWhenUpstreamBuilding"); - // "customWorkspace": {"directory": "aaa"} - JSONObject customWorkspaceJson = json.optJSONObject("customWorkspace"); - if(customWorkspace!=null && !customWorkspaceJson.isNullObject()) { - customWorkspace = Util.fixEmptyAndTrim( - customWorkspaceJson.optString("directory")); + if(json.optBoolean("hasCustomWorkspace", json.has("customWorkspace"))) { + customWorkspace = Util.fixEmptyAndTrim(json.optString("customWorkspace")); } else { customWorkspace = null; } @@ -1831,11 +1820,8 @@ public abstract class AbstractProject

,R extends A else scmCheckoutStrategy = null; - - JSONObject slaveAffinity = json.getJSONObject("hasSlaveAffinity"); - if(slaveAffinity!=null && !slaveAffinity.isNullObject()) { - assignedNode = Util.fixEmptyAndTrim( - slaveAffinity.optString("assignedLabelString")); + if(json.optBoolean("hasSlaveAffinity", json.has("label"))) { + assignedNode = Util.fixEmptyAndTrim(json.optString("label")); } else { assignedNode = null; } @@ -2032,8 +2018,8 @@ public abstract class AbstractProject

,R extends A return true; } - public FormValidation doCheckAssignedLabelString(@AncestorInPath AbstractProject project, - @QueryParameter String value) { + public FormValidation doCheckLabel(@AncestorInPath AbstractProject project, + @QueryParameter String value) { if (Util.fixEmpty(value)==null) return FormValidation.ok(); // nothing typed yet try { @@ -2070,7 +2056,7 @@ public abstract class AbstractProject

,R extends A )); } - public FormValidation doCheckCustomWorkspace(@QueryParameter(value="customWorkspace.directory") String customWorkspace){ + public FormValidation doCheckCustomWorkspace(@QueryParameter String customWorkspace){ if(Util.fixEmptyAndTrim(customWorkspace)==null) return FormValidation.error(Messages.AbstractProject_CustomWorkspaceEmpty()); else @@ -2090,7 +2076,7 @@ public abstract class AbstractProject

,R extends A return candidates; } - public AutoCompletionCandidates doAutoCompleteAssignedLabelString(@QueryParameter String value) { + public AutoCompletionCandidates doAutoCompleteLabel(@QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); Set