BuildWrappers.java 3.0 KB
Newer Older
K
kohsuke 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * The MIT License
 * 
 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
24 25
package hudson.tasks;

26
import hudson.model.AbstractProject;
27
import hudson.model.Descriptor;
28
import jenkins.model.Jenkins;
K
kohsuke 已提交
29
import hudson.model.AbstractProject.AbstractProjectDescriptor;
K
kohsuke 已提交
30
import hudson.Extension;
K
bug fix  
kohsuke 已提交
31
import hudson.util.DescriptorList;
32

33
import java.util.ArrayList;
34 35 36 37 38 39 40 41
import java.util.List;

/**
 * List of all installed {@link BuildWrapper}.
 *
 * @author Kohsuke Kawaguchi
 */
public class BuildWrappers {
K
kohsuke 已提交
42 43 44 45 46
    /**
     * @deprecated
     *      as of 1.281. Use {@link Extension} for registration, and use {@link BuildWrapper#all()}
     *      for listing them.
     */
47
    @Deprecated
K
bug fix  
kohsuke 已提交
48
    public static final List<Descriptor<BuildWrapper>> WRAPPERS = new DescriptorList<BuildWrapper>(BuildWrapper.class);
49 50 51 52 53 54 55 56 57 58

    /**
     * List up all {@link BuildWrapperDescriptor}s that are applicable for the given project.
     *
     * @return
     *      The signature doesn't use {@link BuildWrapperDescriptor} to maintain compatibility
     *      with {@link BuildWrapper} implementations before 1.150.
     */
    public static List<Descriptor<BuildWrapper>> getFor(AbstractProject<?, ?> project) {
        List<Descriptor<BuildWrapper>> result = new ArrayList<Descriptor<BuildWrapper>>();
59
        Descriptor pd = Jenkins.getInstance().getDescriptor((Class)project.getClass());
K
kohsuke 已提交
60

K
kohsuke 已提交
61
        for (Descriptor<BuildWrapper> w : BuildWrapper.all()) {
62
            if (pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor)pd).isApplicable(w))
K
kohsuke 已提交
63
                continue;
64 65 66 67 68 69
            if (w instanceof BuildWrapperDescriptor) {
                BuildWrapperDescriptor bwd = (BuildWrapperDescriptor) w;
                if(bwd.isApplicable(project))
                    result.add(bwd);
            } else {
                // old BuildWrapper that doesn't implement BuildWrapperDescriptor
K
kohsuke 已提交
70
                result.add(w);
71 72 73 74
            }
        }
        return result;
    }
75
}