提交 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
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<P extends AbstractProject<P,R>,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<P extends AbstractProject<P,R>,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<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)
return FormValidation.error(Messages.AbstractProject_CustomWorkspaceEmpty());
else
......@@ -2090,7 +2076,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
return candidates;
}
public AutoCompletionCandidates doAutoCompleteAssignedLabelString(@QueryParameter String value) {
public AutoCompletionCandidates doAutoCompleteLabel(@QueryParameter String value) {
AutoCompletionCandidates c = new AutoCompletionCandidates();
Set<Label> labels = Jenkins.getInstance().getLabels();
List<String> queries = new AutoCompleteSeeder(value).getSeeds();
......
......@@ -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">
<!-- master/slave -->
<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:entry title="${%Label Expression}" field="assignedLabelString">
<f:textbox autoCompleteDelimChar=" "/>
<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="label">
<f:textbox autoCompleteDelimChar=" " value="${it.assignedLabelString}"/>
</f:entry>
</f:optionalBlock>
</j:if>
......
......@@ -25,9 +25,10 @@ THE SOFTWARE.
<!-- custom workspace -->
<?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">
<f:optionalBlock name="customWorkspace" title="${%Use custom workspace}" checked="${it.customWorkspace!=null}" help="/help/project-config/custom-workspace.html">
<f:entry title="${%Directory}">
<f:textbox name="customWorkspace.directory" field="customWorkspace" />
<f:optionalBlock name="hasCustomWorkspace" title="${%Use custom workspace}" checked="${it.customWorkspace!=null}"
help="/help/project-config/custom-workspace.html" inline="true">
<f:entry title="${%Directory}" field="customWorkspace">
<f:textbox />
</f:entry>
</f:optionalBlock>
</j:jelly>
......@@ -26,7 +26,7 @@ THE SOFTWARE.
<?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">
<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}"
description="${%Number of seconds}">
<f:number clazz="number" name="quiet_period" value="${it.quietPeriod}" min="0" step="1"/>
......
......@@ -26,7 +26,7 @@ THE SOFTWARE.
<?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">
<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:number clazz="number" name="scmCheckoutRetryCount" value="${it.scmCheckoutRetryCount}" min="0" step="1"/>
</f:entry>
......
......@@ -233,11 +233,11 @@ public class LabelExpressionTest extends HudsonTestCase {
Label l = jenkins.getLabel("foo");
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("goo"));
msg = d.doCheckAssignedLabelString(null, "master && goo").renderHtml();
msg = d.doCheckLabel(null, "master && goo").renderHtml();
assertTrue(msg.contains("foo"));
assertTrue(msg.contains("goo"));
return null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册