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

hudson.scm.RepositoryBrowsers Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2009 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: 
*
*    Kohsuke Kawaguchi, Daniel Dyer, Stephen Connolly
 *     
 *
 *******************************************************************************/ 

package hudson.scm;

import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.util.DescriptorList;
import hudson.Extension;
import org.kohsuke.stapler.StaplerRequest;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONObject;

/**
 * List of all installed {@link RepositoryBrowsers}.
 *
 * @author Kohsuke Kawaguchi
 */
public class RepositoryBrowsers {
    /**
     * List of all installed {@link RepositoryBrowsers}.
     *
     * @deprecated as of 1.286.
     *      Use {@link RepositoryBrowser#all()} for read access and {@link Extension} for registration.
     */
    public static final List>> LIST = new DescriptorList>((Class)RepositoryBrowser.class);

    /**
     * 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 : RepositoryBrowser.all())
            if(d.isSubTypeOf(t))
                r.add(d);
        return r;
    }

    /**
     * Creates an instance of {@link RepositoryBrowser} from a form submission.
     *
     * @deprecated since 2008-06-19.
     *      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