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

hudson.tasks.BuildWrappers 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
 *
 *
 *******************************************************************************/ 

package hudson.tasks;

import hudson.model.AbstractProject;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.AbstractProject.AbstractProjectDescriptor;
import hudson.Extension;
import hudson.util.DescriptorList;

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

/**
 * List of all installed {@link BuildWrapper}.
 *
 * @author Kohsuke Kawaguchi
 */
public class BuildWrappers {

    /**
     * @deprecated as of 1.281. Use {@link Extension} for registration, and use
     * {@link BuildWrapper#all()} for listing them.
     */
    public static final List> WRAPPERS = new DescriptorList(BuildWrapper.class);

    /**
     * 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> getFor(AbstractProject project) {
        List> result = new ArrayList>();
        Descriptor pd = Hudson.getInstance().getDescriptor((Class) project.getClass());

        for (Descriptor w : BuildWrapper.all()) {
            if (pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor) pd).isApplicable(w)) {
                continue;
            }
            if (w instanceof BuildWrapperDescriptor) {
                BuildWrapperDescriptor bwd = (BuildWrapperDescriptor) w;
                if (bwd.isApplicable(project)) {
                    result.add(bwd);
                }
            } else {
                // old BuildWrapper that doesn't implement BuildWrapperDescriptor
                result.add(w);
            }
        }
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy