/* * The MIT License * * Copyright (c) 2004-2010, Sun Microsystems, Inc., InfraDNA, Inc. * * 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. */ package hudson; import com.google.common.collect.ImmutableList; import hudson.init.InitMilestone; import net.java.sezpoz.Index; import net.java.sezpoz.IndexItem; import hudson.model.Jenkins; import hudson.model.Descriptor; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; import java.util.Collections; import java.util.logging.Logger; import java.util.logging.Level; import java.util.List; import java.util.ArrayList; import java.util.Collection; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Field; import java.lang.reflect.Method; /** * Discovers the implementations of an extension point. * *
* This extension point allows you to write your implementations of {@link ExtensionPoint}s * in arbitrary DI containers, and have Hudson discover them. * *
* {@link ExtensionFinder} itself is an extension point, but to avoid infinite recursion,
* Hudson discovers {@link ExtensionFinder}s through {@link Sezpoz} and that alone.
*
* @author Kohsuke Kawaguchi
* @since 1.286
*/
public abstract class ExtensionFinder implements ExtensionPoint {
/**
* @deprecated as of 1.356
* Use and implement {@link #find(Class, hudson.model.Jenkins)} that allows us to put some metadata.
*/
@Restricted(NoExternalUse.class)
public
* This method is called only once per the given type after all the plugins are loaded,
* so implementations need not worry about caching.
*
* @param
* That is, one thread can try to list extensions, which results in {@link ExtensionFinder}
* loading and initializing classes. This happens inside a context of a lock, so that
* another thread that tries to list the same extensions don't end up creating different
* extension instances. So this activity locks extension list first, then class initialization next.
*
*
* In the mean time, another thread can load and initialize a class, and that initialization
* can eventually results in listing up extensions, for example through static initializer.
* Such activity locks class initialization first, then locks extension list.
*
*
* This inconsistent locking order results in a dead lock, you see.
*
*
* So to reduce the likelihood, this method is called in prior to {@link #find(Class, hudson.model.Jenkins)} invocation,
* but from outside the lock. The implementation is expected to perform all the class initialization activities
* from here.
*
*
* See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6459208 for how to force a class initialization.
* Also see http://kohsuke.org/2010/09/01/deadlock-that-you-cant-avoid/ for how class initialization
* can results in a dead lock.
*/
public void scout(Class extensionType, Jenkins hudson) {
}
/**
* The default implementation that looks for the {@link Extension} marker.
*
*
* Uses Sezpoz as the underlying mechanism.
*/
@Extension
public static final class Sezpoz extends ExtensionFinder {
private volatile List