mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 14:02:22 +00:00
[FIXED HUDSON-1891] Fixed NPE in configuring repository browsers.
This was due to the push to use JSON binding. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@10236 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
7ee77f4fcc
commit
7af77ee70a
4 files changed
+35
-4
No files matched your search
@@ -969,7 +969,7 @@ public class CVSSCM extends SCM implements Serializable {
|
||||
@Override
|
||||
public SCM newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
CVSSCM scm = req.bindJSON(CVSSCM.class,formData);
|
||||
scm.repositoryBrowser = RepositoryBrowsers.createInstance(CVSRepositoryBrowser.class,req,"cvs.browser");
|
||||
scm.repositoryBrowser = RepositoryBrowsers.createInstance(CVSRepositoryBrowser.class,req,formData,"browser");
|
||||
return scm;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ import org.kohsuke.stapler.StaplerRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
import net.sf.json.JSONArray;
|
||||
|
||||
/**
|
||||
* List of all installed {@link RepositoryBrowsers}.
|
||||
*
|
||||
@@ -40,6 +43,9 @@ public class RepositoryBrowsers {
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link RepositoryBrowser} from a form submission.
|
||||
*
|
||||
* @deprecated
|
||||
* Use {@link #createInstance(Class, StaplerRequest, JSONObject, String)}.
|
||||
*/
|
||||
public static <T extends RepositoryBrowser>
|
||||
T createInstance(Class<T> type, StaplerRequest req, String fieldName) throws FormException {
|
||||
@@ -50,4 +56,27 @@ public class RepositoryBrowsers {
|
||||
|
||||
return type.cast(list.get(Integer.parseInt(value)).newInstance(req,null/*TODO*/));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link RepositoryBrowser} from a form submission.
|
||||
*
|
||||
* @since 1.227
|
||||
*/
|
||||
public static <T extends RepositoryBrowser>
|
||||
T createInstance(Class<T> type, StaplerRequest req, JSONObject parent, String fieldName) throws FormException {
|
||||
List<Descriptor<RepositoryBrowser<?>>> list = filter(type);
|
||||
|
||||
Object o = parent.get(fieldName);
|
||||
if(o==null) return null;
|
||||
|
||||
if(o instanceof String && "auto".equals(o))
|
||||
return null;
|
||||
|
||||
if (o instanceof JSONArray) {
|
||||
JSONArray a = (JSONArray) o;
|
||||
return type.cast(list.get(a.getInt(0)).newInstance(req,a.getJSONObject(1)));
|
||||
}
|
||||
|
||||
throw new AssertionError(o.getClass());
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,8 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Subversion SCM.
|
||||
*
|
||||
@@ -1020,12 +1022,12 @@ public class SubversionSCM extends SCM implements Serializable {
|
||||
return "Subversion";
|
||||
}
|
||||
|
||||
public SCM newInstance(StaplerRequest req) throws FormException {
|
||||
public SCM newInstance(StaplerRequest req, JSONObject formData) throws FormException {
|
||||
return new SubversionSCM(
|
||||
req.getParameterValues("svn.location_remote"),
|
||||
req.getParameterValues("svn.location_local"),
|
||||
req.getParameter("svn_use_update") != null,
|
||||
RepositoryBrowsers.createInstance(SubversionRepositoryBrowser.class, req, "svn.browser"));
|
||||
RepositoryBrowsers.createInstance(SubversionRepositoryBrowser.class, req, formData, "browser"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user