Skip to content
Permalink
Browse files
Add support of newInstance() invocation
Plugin invokes newInstance() instead of DataBoundConstructor.
Signed-off-by: Oleg Nenashev <nenashev@synopsys.com>

[FIXED JENKINS-19818]
[FIXED JENKINS-9287]
  • Loading branch information
oleg-nenashev authored and rodrigc committed May 20, 2015
1 parent 0a91e53 commit 78c5c7d81c3a2c5410138137153838d46f28e0ce
Showing 1 changed file with 28 additions and 2 deletions.
@@ -10,6 +10,7 @@
import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Run;
import hudson.model.Hudson;
import hudson.scm.ChangeLogParser;
import hudson.scm.PollingResult;
import hudson.scm.PollingResult.Change;
@@ -25,8 +26,10 @@
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;

import net.sf.json.JSONObject;

@@ -212,9 +215,32 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
@Override
public SCM newInstance(StaplerRequest req, JSONObject formData)
throws FormException {
return super.newInstance(req, formData);
// Read descriptions and invoke newInstance() for each of them
List<SCM> scmList = new LinkedList<SCM>();
if (formData.containsKey("scmList")) {
JSONObject scm = formData.optJSONObject("scmList");
if (scm == null) {
for (Object obj : formData.getJSONArray("scmList")) {
readItem(req, (JSONObject)obj, scmList);
}
} else {
readItem(req, scm, scmList);
}
}

// return list and wrap exception
try {
return new MultiSCM(scmList);
} catch (IOException ex) {
throw new FormException(ex, "scmList");
}
}


private static void readItem(StaplerRequest req, JSONObject obj, List<SCM> dest) throws FormException {
String staplerClass = obj.getString("stapler-class");
Descriptor<SCM> d = (Descriptor<SCM>) Hudson.getInstance().getDescriptor(staplerClass);
dest.add(d.newInstance(req, obj));
}
}
}

0 comments on commit 78c5c7d

Please sign in to comment.