提交 eec43983 编写于 作者: M Matt Moore

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.
上级 86c911e8
...@@ -1789,38 +1789,27 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -1789,38 +1789,27 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
super.submit(req,rsp); super.submit(req,rsp);
JSONObject json = req.getSubmittedForm(); JSONObject json = req.getSubmittedForm();
// "disable": true
makeDisabled(json.optBoolean("disable")); makeDisabled(json.optBoolean("disable"));
jdk = json.optString("jdk", null); jdk = json.optString("jdk", null);
// "hasCustomQuietPeriod": {"quiet_period": "3"} if(json.optBoolean("hasCustomQuietPeriod", json.has("quiet_period"))) {
JSONObject customQuietPeriodJson = json.optJSONObject("hasCustomQuietPeriod"); quietPeriod = json.optInt("quiet_period");
if(customQuietPeriodJson!=null && !customQuietPeriodJson.isNullObject()) {
quietPeriod = customQuietPeriodJson.optInt("quiet_period");
} else { } else {
quietPeriod = null; quietPeriod = null;
} }
// "hasCustomScmCheckoutRetryCount": {"scmCheckoutRetryCount": "12"} if(json.optBoolean("hasCustomScmCheckoutRetryCount", json.has("scmCheckoutRetryCount"))) {
JSONObject customRetryJson = json.optJSONObject("hasCustomScmCheckoutRetryCount"); scmCheckoutRetryCount = json.optInt("scmCheckoutRetryCount");
if(customRetryJson!=null && !customRetryJson.isNullObject()) {
scmCheckoutRetryCount = customRetryJson.optInt("scmCheckoutRetryCount");
} else { } else {
scmCheckoutRetryCount = null; scmCheckoutRetryCount = null;
} }
// "blockBuildWhenDownstreamBuilding": true
blockBuildWhenDownstreamBuilding = json.optBoolean("blockBuildWhenDownstreamBuilding"); blockBuildWhenDownstreamBuilding = json.optBoolean("blockBuildWhenDownstreamBuilding");
// "blockBuildWhenUpstreamBuilding": true
blockBuildWhenUpstreamBuilding = json.optBoolean("blockBuildWhenUpstreamBuilding"); blockBuildWhenUpstreamBuilding = json.optBoolean("blockBuildWhenUpstreamBuilding");
// "customWorkspace": {"directory": "aaa"} if(json.optBoolean("hasCustomWorkspace", json.has("customWorkspace"))) {
JSONObject customWorkspaceJson = json.optJSONObject("customWorkspace"); customWorkspace = Util.fixEmptyAndTrim(json.optString("customWorkspace"));
if(customWorkspace!=null && !customWorkspaceJson.isNullObject()) {
customWorkspace = Util.fixEmptyAndTrim(
customWorkspaceJson.optString("directory"));
} else { } else {
customWorkspace = null; customWorkspace = null;
} }
...@@ -1831,11 +1820,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -1831,11 +1820,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
else else
scmCheckoutStrategy = null; scmCheckoutStrategy = null;
if(json.optBoolean("hasSlaveAffinity", json.has("label"))) {
JSONObject slaveAffinity = json.getJSONObject("hasSlaveAffinity"); assignedNode = Util.fixEmptyAndTrim(json.optString("label"));
if(slaveAffinity!=null && !slaveAffinity.isNullObject()) {
assignedNode = Util.fixEmptyAndTrim(
slaveAffinity.optString("assignedLabelString"));
} else { } else {
assignedNode = null; assignedNode = null;
} }
...@@ -2032,8 +2018,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -2032,8 +2018,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
return true; return true;
} }
public FormValidation doCheckAssignedLabelString(@AncestorInPath AbstractProject<?,?> project, public FormValidation doCheckLabel(@AncestorInPath AbstractProject<?,?> project,
@QueryParameter String value) { @QueryParameter String value) {
if (Util.fixEmpty(value)==null) if (Util.fixEmpty(value)==null)
return FormValidation.ok(); // nothing typed yet return FormValidation.ok(); // nothing typed yet
try { try {
...@@ -2070,7 +2056,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -2070,7 +2056,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
)); ));
} }
public FormValidation doCheckCustomWorkspace(@QueryParameter(value="customWorkspace.directory") String customWorkspace){ public FormValidation doCheckCustomWorkspace(@QueryParameter String customWorkspace){
if(Util.fixEmptyAndTrim(customWorkspace)==null) if(Util.fixEmptyAndTrim(customWorkspace)==null)
return FormValidation.error(Messages.AbstractProject_CustomWorkspaceEmpty()); return FormValidation.error(Messages.AbstractProject_CustomWorkspaceEmpty());
else else
...@@ -2090,7 +2076,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A ...@@ -2090,7 +2076,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
return candidates; return candidates;
} }
public AutoCompletionCandidates doAutoCompleteAssignedLabelString(@QueryParameter String value) { public AutoCompletionCandidates doAutoCompleteLabel(@QueryParameter String value) {
AutoCompletionCandidates c = new AutoCompletionCandidates(); AutoCompletionCandidates c = new AutoCompletionCandidates();
Set<Label> labels = Jenkins.getInstance().getLabels(); Set<Label> labels = Jenkins.getInstance().getLabels();
List<String> queries = new AutoCompleteSeeder(value).getSeeds(); List<String> queries = new AutoCompleteSeeder(value).getSeeds();
......
...@@ -29,9 +29,9 @@ THE SOFTWARE. ...@@ -29,9 +29,9 @@ THE SOFTWARE.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<!-- master/slave --> <!-- master/slave -->
<j:if test="${app.labels.size() gt 1 || app.clouds.size() gt 0 || (it.assignedLabel!=null and it.assignedLabel!=app.selfLabel)}"> <j:if test="${app.labels.size() gt 1 || app.clouds.size() gt 0 || (it.assignedLabel!=null and it.assignedLabel!=app.selfLabel)}">
<f:optionalBlock name="hasSlaveAffinity" title="${%Restrict where this project can be run}" checked="${it.assignedLabel!=null}" field="slaveAffinity"> <f:optionalBlock name="hasSlaveAffinity" title="${%Restrict where this project can be run}" checked="${it.assignedLabel!=null}" field="slaveAffinity" inline="true">
<f:entry title="${%Label Expression}" field="assignedLabelString"> <f:entry title="${%Label Expression}" field="label">
<f:textbox autoCompleteDelimChar=" "/> <f:textbox autoCompleteDelimChar=" " value="${it.assignedLabelString}"/>
</f:entry> </f:entry>
</f:optionalBlock> </f:optionalBlock>
</j:if> </j:if>
......
...@@ -25,9 +25,10 @@ THE SOFTWARE. ...@@ -25,9 +25,10 @@ THE SOFTWARE.
<!-- custom workspace --> <!-- custom workspace -->
<?jelly escape-by-default='true'?> <?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:optionalBlock name="customWorkspace" title="${%Use custom workspace}" checked="${it.customWorkspace!=null}" help="/help/project-config/custom-workspace.html"> <f:optionalBlock name="hasCustomWorkspace" title="${%Use custom workspace}" checked="${it.customWorkspace!=null}"
<f:entry title="${%Directory}"> help="/help/project-config/custom-workspace.html" inline="true">
<f:textbox name="customWorkspace.directory" field="customWorkspace" /> <f:entry title="${%Directory}" field="customWorkspace">
<f:textbox />
</f:entry> </f:entry>
</f:optionalBlock> </f:optionalBlock>
</j:jelly> </j:jelly>
...@@ -26,7 +26,7 @@ THE SOFTWARE. ...@@ -26,7 +26,7 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?> <?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:optionalBlock name="hasCustomQuietPeriod" title="${%Quiet period}" checked="${it.hasCustomQuietPeriod}" <f:optionalBlock name="hasCustomQuietPeriod" title="${%Quiet period}" checked="${it.hasCustomQuietPeriod}"
help="/descriptor/jenkins.model.GlobalQuietPeriodConfiguration/help/quietPeriod"> help="/descriptor/jenkins.model.GlobalQuietPeriodConfiguration/help/quietPeriod" inline="true">
<f:entry title="${%Quiet period}" <f:entry title="${%Quiet period}"
description="${%Number of seconds}"> description="${%Number of seconds}">
<f:number clazz="number" name="quiet_period" value="${it.quietPeriod}" min="0" step="1"/> <f:number clazz="number" name="quiet_period" value="${it.quietPeriod}" min="0" step="1"/>
......
...@@ -26,7 +26,7 @@ THE SOFTWARE. ...@@ -26,7 +26,7 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?> <?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:optionalBlock name="hasCustomScmCheckoutRetryCount" title="${%Retry Count}" checked="${it.hasCustomScmCheckoutRetryCount()}" <f:optionalBlock name="hasCustomScmCheckoutRetryCount" title="${%Retry Count}" checked="${it.hasCustomScmCheckoutRetryCount()}"
help="/help/project-config/scmCheckoutRetryCount.html"> help="/help/project-config/scmCheckoutRetryCount.html" inline="true">
<f:entry title="${%SCM checkout retry count}"> <f:entry title="${%SCM checkout retry count}">
<f:number clazz="number" name="scmCheckoutRetryCount" value="${it.scmCheckoutRetryCount}" min="0" step="1"/> <f:number clazz="number" name="scmCheckoutRetryCount" value="${it.scmCheckoutRetryCount}" min="0" step="1"/>
</f:entry> </f:entry>
......
...@@ -233,11 +233,11 @@ public class LabelExpressionTest extends HudsonTestCase { ...@@ -233,11 +233,11 @@ public class LabelExpressionTest extends HudsonTestCase {
Label l = jenkins.getLabel("foo"); Label l = jenkins.getLabel("foo");
DumbSlave s = createSlave(l); DumbSlave s = createSlave(l);
String msg = d.doCheckAssignedLabelString(null, "goo").renderHtml(); String msg = d.doCheckLabel(null, "goo").renderHtml();
assertTrue(msg.contains("foo")); assertTrue(msg.contains("foo"));
assertTrue(msg.contains("goo")); assertTrue(msg.contains("goo"));
msg = d.doCheckAssignedLabelString(null, "master && goo").renderHtml(); msg = d.doCheckLabel(null, "master && goo").renderHtml();
assertTrue(msg.contains("foo")); assertTrue(msg.contains("foo"));
assertTrue(msg.contains("goo")); assertTrue(msg.contains("goo"));
return null; return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册