提交 3417dc04 编写于 作者: K Kohsuke Kawaguchi

- modified to use <descriptorList> for better reuse&consistency.

- support invisible JobProperty
上级 27705234
......@@ -26,6 +26,7 @@ package hudson.model;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import com.google.common.collect.Iterables;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.ExtensionPoint;
import hudson.PermalinkList;
......@@ -46,6 +47,7 @@ import hudson.util.ChartUtil;
import hudson.util.ColorPalette;
import hudson.util.CopyOnWriteList;
import hudson.util.DataSetBuilder;
import hudson.util.DescribableList;
import hudson.util.IOException2;
import hudson.util.RunList;
import hudson.util.ShiftedCategoryAxis;
......@@ -936,25 +938,19 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
keepDependencies = req.getParameter("keepDependencies") != null;
try {
properties.clear();
JSONObject json = req.getSubmittedForm();
if (req.getParameter("logrotate") != null)
logRotator = LogRotator.DESCRIPTOR.newInstance(req,json.getJSONObject("logrotate"));
else
logRotator = null;
int i = 0;
for (JobPropertyDescriptor d : JobPropertyDescriptor
.getPropertyDescriptors(Job.this.getClass())) {
String name = "jobProperty" + (i++);
JSONObject config = json.getJSONObject(name);
JobProperty prop = d.newInstance(req, config);
if (prop != null) {
prop.setOwner(this);
properties.add(prop);
}
DescribableList<JobProperty<?>, JobPropertyDescriptor> t = new DescribableList<JobProperty<?>, JobPropertyDescriptor>(NOOP,getAllProperties());
t.rebuild(req,json.optJSONObject("properties"),JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass()));
properties.clear();
for (JobProperty p : t) {
p.setOwner(this);
properties.add(p);
}
submit(req, rsp);
......
......@@ -26,6 +26,7 @@ package hudson.model;
import hudson.ExtensionPoint;
import hudson.Launcher;
import hudson.Plugin;
import hudson.model.Descriptor.FormException;
import hudson.model.queue.SubTask;
import hudson.tasks.BuildStep;
import hudson.tasks.Builder;
......@@ -36,6 +37,8 @@ import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.export.ExportedBean;
/**
......@@ -69,7 +72,7 @@ import org.kohsuke.stapler.export.ExportedBean;
* @since 1.72
*/
@ExportedBean
public abstract class JobProperty<J extends Job<?,?>> implements Describable<JobProperty<?>>, BuildStep, ExtensionPoint {
public abstract class JobProperty<J extends Job<?,?>> implements ReconfigurableDescribable<JobProperty<?>>, BuildStep, ExtensionPoint {
/**
* The {@link Job} object that owns this property.
* This value will be set by the Hudson code.
......@@ -169,6 +172,10 @@ public abstract class JobProperty<J extends Job<?,?>> implements Describable<Job
return Collections.emptyList();
}
public JobProperty<?> reconfigure(StaplerRequest req, JSONObject form) throws FormException {
return form==null ? null : getDescriptor().newInstance(req,form);
}
/**
* Contributes {@link SubTask}s to {@link AbstractProject#getSubTasks()}
*
......
......@@ -53,17 +53,7 @@ THE SOFTWARE.
</j:if>
<!-- job property configurations. This should have been <f:descriptorList> -->
<j:set var="instances" value="${it.properties}" />
<j:forEach var="d" items="${h.getJobPropertyDescriptors(it.getClass())}" varStatus="loop">
<j:scope>
<j:set var="descriptor" value="${d}" />
<j:set var="instance" value="${instances[d]}" />
<f:rowSet name="jobProperty${loop.index}">
<st:include from="${d}" page="${d.configPage}" optional="true"/>
</f:rowSet>
</j:scope>
</j:forEach>
<f:descriptorList field="properties" descriptors="${h.getJobPropertyDescriptors(it.getClass())}" forceRowSet="true" />
<!-- additional entries from derived classes -->
<st:include page="configure-entries.jelly" />
......
......@@ -50,6 +50,9 @@ THE SOFTWARE.
the type for which descriptors will be configured.
default to ${it.class}
</st:attribute>
<st:attribute name="forceRowSet">
If specified, instead of a sequence of &lt;f:optionalBlock>s, draw a sequence of &lt;rowSet>s.
</st:attribute>
</st:documentation>
<j:if test="${attrs.field==null}">
......@@ -73,7 +76,7 @@ THE SOFTWARE.
<d:invokeBody />
<j:forEach var="d" items="${descriptors}">
<f:optionalBlock name="${d.jsonSafeClassName}" help="${d.helpFile}"
title="${d.displayName}" checked="${instances.get(d)!=null}">
title="${attrs.forceRowSet!=null?null:d.displayName}" checked="${instances.get(d)!=null}">
<j:set var="descriptor" value="${d}" />
<j:set var="instance" value="${instances.get(d)}" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册