All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.scm.RepositoryBrowsers Maven / Gradle / Ivy

package hudson.scm;

import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.scm.browsers.*;
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}.
 *
 * @author Kohsuke Kawaguchi
 */
public class RepositoryBrowsers {
    /**
     * List of all installed {@link RepositoryBrowsers}.
     */
    public static final List>> LIST = Descriptor.toList(
        ViewCVS.DESCRIPTOR,
        ViewSVN.DescriptorImpl.INSTANCE,
        FishEyeSVN.DESCRIPTOR,
        FishEyeCVS.DESCRIPTOR,
        WebSVN.DESCRIPTOR,
        Sventon.DESCRIPTOR,
        CollabNetSVN.DESCRIPTOR
    );

    /**
     * Only returns those {@link RepositoryBrowser} descriptors that extend from the given type.
     */
    public static List>> filter(Class t) {
        List>> r = new ArrayList>>();
        for (Descriptor> d : LIST)
            if(t.isAssignableFrom(d.clazz))
                r.add(d);
        return r;
    }

    /**
     * Creates an instance of {@link RepositoryBrowser} from a form submission.
     *
     * @deprecated
     *      Use {@link #createInstance(Class, StaplerRequest, JSONObject, String)}.
     */
    public static 
    T createInstance(Class type, StaplerRequest req, String fieldName) throws FormException {
        List>> list = filter(type);
        String value = req.getParameter(fieldName);
        if(value==null || value.equals("auto"))
            return null;

        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 createInstance(Class type, StaplerRequest req, JSONObject parent, String fieldName) throws FormException {
        JSONObject o = (JSONObject)parent.get(fieldName);
        if(o==null) return null;

        return req.bindJSON(type,o);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy