diff --git a/core/src/main/java/hudson/maven/MavenModule.java b/core/src/main/java/hudson/maven/MavenModule.java index 14f9f6372a..47e0fa21fc 100644 --- a/core/src/main/java/hudson/maven/MavenModule.java +++ b/core/src/main/java/hudson/maven/MavenModule.java @@ -2,10 +2,22 @@ package hudson.maven; import hudson.CopyOnWrite; import hudson.FilePath; +import hudson.StructuredForm; import hudson.Util; import hudson.maven.reporters.MavenMailer; -import hudson.model.*; +import hudson.model.AbstractProject; +import hudson.model.Action; +import hudson.model.DependencyGraph; +import hudson.model.Descriptor; import hudson.model.Descriptor.FormException; +import hudson.model.Hudson; +import hudson.model.Item; +import hudson.model.ItemGroup; +import hudson.model.JDK; +import hudson.model.Job; +import hudson.model.Label; +import hudson.model.Node; +import hudson.model.Resource; import hudson.tasks.LogRotator; import hudson.util.DescribableList; import org.apache.maven.project.MavenProject; @@ -14,7 +26,12 @@ import org.kohsuke.stapler.StaplerResponse; import javax.servlet.ServletException; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * {@link Job} that builds projects based on Maven2. @@ -320,7 +337,7 @@ public final class MavenModule extends AbstractMavenProject,R extends A protected final > List buildDescribable(StaplerRequest req, List> descriptors, String prefix) throws FormException { + JSONObject data = StructuredForm.get(req); List r = new Vector(); for( int i=0; i< descriptors.size(); i++ ) { - if(req.getParameter(prefix +i)!=null) { - T instance = descriptors.get(i).newInstance(req); + String name = prefix + i; + if(req.getParameter(name)!=null) { + T instance = descriptors.get(i).newInstance(req,data.getJSONObject(name)); r.add(instance); } } diff --git a/core/src/main/java/hudson/model/ComputerSet.java b/core/src/main/java/hudson/model/ComputerSet.java index 3e41a5e9c5..965f581269 100644 --- a/core/src/main/java/hudson/model/ComputerSet.java +++ b/core/src/main/java/hudson/model/ComputerSet.java @@ -26,7 +26,7 @@ public final class ComputerSet implements ModelObject { ArrayList r = new ArrayList(); for (Descriptor d : NodeMonitor.LIST) try { - r.add(d.newInstance(null)); + r.add(d.newInstance(null,null)); } catch (FormException e) { // so far impossible. TODO: report } diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index 52c6b90ae7..69bd25b0eb 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -14,6 +14,8 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import net.sf.json.JSONObject; + /** * Metadata about a configurable instance. * @@ -84,6 +86,15 @@ public abstract class Descriptor> { */ public abstract String getDisplayName(); + /** + * @deprecated + * Implement {@link #newInstance(StaplerRequest, JSONObject)} method instead. + * Deprecated as of 1.145. + */ + public T newInstance(StaplerRequest req) throws FormException { + throw new UnsupportedOperationException(getClass()+" should implement newInstance(StaplerRequest,JSONObject)"); + } + /** * Creates a configured instance from the submitted form. * @@ -92,12 +103,19 @@ public abstract class Descriptor> { * So there's no need to check that in the implementation. * * @param req - * Always non-null. This object includes all the submitted form values. + * Always non-null. This object includes represents the entire submisison. + * @param formData + * The JSON object that captures the configuration data for this {@link Descriptor}. + * See http://hudson.gotdns.com/wiki/display/HUDSON/Structured+Form+Submission * * @throws FormException * Signals a problem in the submitted form. + * @since 1.145 */ - public abstract T newInstance(StaplerRequest req) throws FormException; + public T newInstance(StaplerRequest req, JSONObject formData) throws FormException { + // backward compatibility. + return newInstance(req); + } /** * Returns the resource path to the help screen HTML, if any. diff --git a/core/src/main/java/hudson/model/Job.java b/core/src/main/java/hudson/model/Job.java index fb4575ce50..f202e34195 100644 --- a/core/src/main/java/hudson/model/Job.java +++ b/core/src/main/java/hudson/model/Job.java @@ -664,7 +664,7 @@ public abstract class Job, RunT extends Run props = new ArrayList(); for (Descriptor d : UserProperties.LIST) - props.add(d.newInstance(req)); + props.add(d.newInstance(req,null)); this.properties = props; save(); diff --git a/core/src/main/java/hudson/scm/RepositoryBrowsers.java b/core/src/main/java/hudson/scm/RepositoryBrowsers.java index 08e4321277..431ea0e4f2 100644 --- a/core/src/main/java/hudson/scm/RepositoryBrowsers.java +++ b/core/src/main/java/hudson/scm/RepositoryBrowsers.java @@ -46,6 +46,6 @@ public class RepositoryBrowsers { if(value==null || value.equals("auto")) return null; - return type.cast(list.get(Integer.parseInt(value)).newInstance(req)); + return type.cast(list.get(Integer.parseInt(value)).newInstance(req,null/*TODO*/)); } } diff --git a/core/src/main/java/hudson/scm/SCMS.java b/core/src/main/java/hudson/scm/SCMS.java index ee4c3e31d4..26dcad219a 100644 --- a/core/src/main/java/hudson/scm/SCMS.java +++ b/core/src/main/java/hudson/scm/SCMS.java @@ -2,6 +2,7 @@ package hudson.scm; import hudson.model.Descriptor; import hudson.model.Descriptor.FormException; +import hudson.StructuredForm; import java.util.List; @@ -33,6 +34,6 @@ public class SCMS { int scmidx = Integer.parseInt(scm); SCMDescriptor d = SCMS.get(scmidx); d.generation++; - return d.newInstance(req); + return d.newInstance(req,StructuredForm.get(req).getJSONObject("scm")); } } diff --git a/core/src/main/java/hudson/tasks/LogRotator.java b/core/src/main/java/hudson/tasks/LogRotator.java index e8e3b82a11..887638a166 100644 --- a/core/src/main/java/hudson/tasks/LogRotator.java +++ b/core/src/main/java/hudson/tasks/LogRotator.java @@ -12,6 +12,8 @@ import java.io.IOException; import java.util.Calendar; import java.util.GregorianCalendar; +import net.sf.json.JSONObject; + /** * Deletes old log files. * diff --git a/core/src/main/java/hudson/util/DescribableList.java b/core/src/main/java/hudson/util/DescribableList.java index ca1ae5a699..ec7912ea52 100644 --- a/core/src/main/java/hudson/util/DescribableList.java +++ b/core/src/main/java/hudson/util/DescribableList.java @@ -10,15 +10,15 @@ import com.thoughtworks.xstream.mapper.Mapper; import hudson.model.Describable; import hudson.model.Descriptor; import hudson.model.Descriptor.FormException; -import hudson.maven.MavenReporterDescriptor; +import net.sf.json.JSONObject; import org.kohsuke.stapler.StaplerRequest; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Collection; /** * Persisted list of {@link Describable}s with some operations specific @@ -93,13 +93,17 @@ public class DescribableList, D extends Descriptor> *

* This method is almost always used by the owner. * This method does not invoke the save method. + * + * @param json + * Structured form data that includes the data for nested descriptor list. */ - public void rebuild(StaplerRequest req, List> descriptors, String prefix) throws FormException { + public void rebuild(StaplerRequest req, JSONObject json, List> descriptors, String prefix) throws FormException { List newList = new ArrayList(); for( int i=0; i< descriptors.size(); i++ ) { - if(req.getParameter(prefix +i)!=null) { - T instance = descriptors.get(i).newInstance(req); + String name = prefix + i; + if(req.getParameter(name)!=null) { + T instance = descriptors.get(i).newInstance(req,json.getJSONObject(name)); newList.add(instance); } }