mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 14:02:22 +00:00
adding structured form submission support to Descriptor.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@5041 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
d903939d80
commit
33f9fe78e1
11 files changed
+65
-18
No files matched your search
@@ -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<MavenModule,MavenBui
|
||||
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
|
||||
super.submit(req, rsp);
|
||||
|
||||
reporters.rebuild(req,MavenReporters.getConfigurableList(),"reporter");
|
||||
reporters.rebuild(req,StructuredForm.get(req),MavenReporters.getConfigurableList(),"reporter");
|
||||
|
||||
goals = Util.fixEmpty(req.getParameter("goals").trim());
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import hudson.CopyOnWrite;
|
||||
import hudson.FilePath;
|
||||
import hudson.Indenter;
|
||||
import hudson.Util;
|
||||
import hudson.StructuredForm;
|
||||
import hudson.search.SearchIndexBuilder;
|
||||
import hudson.search.CollectionSearchIndex;
|
||||
import hudson.model.*;
|
||||
@@ -417,7 +418,7 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
|
||||
mavenName = req.getParameter("maven_version");
|
||||
aggregatorStyleBuild = req.getParameter("maven.perModuleBuild")==null;
|
||||
|
||||
reporters.rebuild(req,MavenReporters.getConfigurableList(),"reporter");
|
||||
reporters.rebuild(req, StructuredForm.get(req),MavenReporters.getConfigurableList(),"reporter");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ import hudson.FeedAdapter;
|
||||
import hudson.FilePath;
|
||||
import hudson.Launcher;
|
||||
import hudson.AbortException;
|
||||
import hudson.StructuredForm;
|
||||
import hudson.maven.MavenModule;
|
||||
import hudson.model.Descriptor.FormException;
|
||||
import hudson.model.Fingerprint.RangeSet;
|
||||
@@ -43,6 +44,7 @@ import javax.servlet.ServletException;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.kohsuke.stapler.export.Exported;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Base implementation of {@link Job}s that build software.
|
||||
@@ -755,10 +757,12 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
|
||||
protected final <T extends Describable<T>> List<T> buildDescribable(StaplerRequest req, List<? extends Descriptor<T>> descriptors, String prefix)
|
||||
throws FormException {
|
||||
|
||||
JSONObject data = StructuredForm.get(req);
|
||||
List<T> r = new Vector<T>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public final class ComputerSet implements ModelObject {
|
||||
ArrayList<NodeMonitor> r = new ArrayList<NodeMonitor>();
|
||||
for (Descriptor<NodeMonitor> d : NodeMonitor.LIST)
|
||||
try {
|
||||
r.add(d.newInstance(null));
|
||||
r.add(d.newInstance(null,null));
|
||||
} catch (FormException e) {
|
||||
// so far impossible. TODO: report
|
||||
}
|
||||
|
||||
@@ -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<T extends Describable<T>> {
|
||||
*/
|
||||
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<T extends Describable<T>> {
|
||||
* 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.
|
||||
|
||||
@@ -664,7 +664,7 @@ public abstract class Job<JobT extends Job<JobT,RunT>, RunT extends Run<JobT,Run
|
||||
try {
|
||||
properties.clear();
|
||||
for (JobPropertyDescriptor d : JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass())) {
|
||||
JobProperty prop = d.newInstance(req);
|
||||
JobProperty prop = d.newInstance(req,null);
|
||||
if (prop != null) {
|
||||
prop.setOwner(this);
|
||||
properties.add(prop);
|
||||
|
||||
@@ -268,7 +268,7 @@ public class User extends AbstractModelObject {
|
||||
|
||||
List<UserProperty> props = new ArrayList<UserProperty>();
|
||||
for (Descriptor<UserProperty> d : UserProperties.LIST)
|
||||
props.add(d.newInstance(req));
|
||||
props.add(d.newInstance(req,null));
|
||||
this.properties = props;
|
||||
|
||||
save();
|
||||
|
||||
@@ -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*/));
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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<T extends Describable<T>, D extends Descriptor<T>>
|
||||
* <p>
|
||||
* 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<? extends Descriptor<T>> descriptors, String prefix) throws FormException {
|
||||
public void rebuild(StaplerRequest req, JSONObject json, List<? extends Descriptor<T>> descriptors, String prefix) throws FormException {
|
||||
List<T> newList = new ArrayList<T>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user