Skip to main content

[Hudson-Dev] Re: HUDSON-8735: allow PluginStrategy implementations complete control over finding components

  • From: Jason Dillon <jason@...>
  • To: Winston Prakash <winston.prakash@...>
  • Cc: dev@...
  • Subject: [Hudson-Dev] Re: HUDSON-8735: allow PluginStrategy implementations complete control over finding components
  • Date: Tue, 15 Feb 2011 15:11:40 -0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:subject:mime-version:content-type:from:in-reply-to:date:cc :message-id:references:to:x-mailer; b=u91Lli3kgKKCNAjk0wJmTx3ZhilTmkrkOPxkofbDWjjCqiWb4JT4FflFqPSfgnNmlN KHkKBPEWXB7GhE7HRXV+Ee9hScU1js5BkTEX+8yg/TFAAP3yFCBBRlUW6Vjr9waHE2vz GiIBZIT7Q12n3TackEOTq/e85RnvYz7sNjzec=

Cool.  I didn't see any mail on the list which is why I asked.  Then about ~20 minutes ago I got bunch of emails.

--jason


On Feb 15, 2011, at 3:06 PM, Winston Prakash wrote:

Applied already in  https://github.com/hudson/hudson

- Winston
What is the process of getting this change committed?  I've not seen any objections... can this be applied?

--jason


On Feb 13, 2011, at 11:08 PM, Jason van Zyl wrote:

On Feb 13, 2011, at 10:09 PM, Stuart McCulloch wrote:

Hi folks,

I've raised a new feature request to allow PluginStrategy implementations complete control over finding components:


Unfortunately JIRA won't let me comment on the issue I just created :) so I'm attaching my proposed patch below.


If this preserves all previous behavior but allows us to move forward with different approaches that are more flexible I don't see any downsides.

--
Cheers, Stuart

diff --git a/hudson-core/src/main/java/hudson/ClassicPluginStrategy.java b/hudson-core/src/main/java/hudson/ClassicPluginStrategy.java
index 57d7cff..87d069e 100644
--- a/hudson-core/src/main/java/hudson/ClassicPluginStrategy.java
+++ b/hudson-core/src/main/java/hudson/ClassicPluginStrategy.java
@@ -24,6 +24,7 @@
 package hudson;
 
 import hudson.PluginWrapper.Dependency;
+import hudson.model.Hudson;
 import hudson.util.IOException2;
 import hudson.util.MaskingClassLoader;
 import hudson.util.VersionNumber;
@@ -47,6 +48,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.jar.Manifest;
 import java.util.jar.Attributes;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.tools.ant.BuildException;
@@ -256,6 +258,42 @@ public class ClassicPluginStrategy implements PluginStrategy {
     public void initializeComponents(PluginWrapper plugin) {
     }
 
+    public <T> List<ExtensionComponent<T>> findComponents(Class<T> type, Hudson hudson) {
+
+        scoutLoad(type, hudson);
+
+        List<ExtensionComponent<T>> r = new ArrayList<ExtensionComponent<T>>();
+        for (ExtensionFinder finder : finders(type, hudson)) {
+            try {
+                r.addAll(finder._find(type, hudson));
+            } catch (AbstractMethodError e) {
+                // backward compatibility
+                for (T t : finder.findExtensions(type, hudson))
+                    r.add(new ExtensionComponent<T>(t));
+            }
+        }
+        return r;
+    }
+
+    /**
+     * See {@link ExtensionFinder#scout(Class, Hudson)} for the dead lock issue and what this does.
+     */
+    protected void scoutLoad(Class<?> type, Hudson hudson) {
+        if (LOGGER.isLoggable(Level.FINER))
+            LOGGER.log(Level.FINER,"Scout-loading ExtensionList: "+type, new Throwable());
+        for (ExtensionFinder finder : finders(type, hudson)) {
+            finder.scout(type, hudson);
+        }
+    }
+
+    protected List<? extends ExtensionFinder> finders(Class<?> type, Hudson hudson) {
+        if (type==ExtensionFinder.class) {
+            // Avoid infinite recursion when finding extension finders
+            return Collections.singletonList(new ExtensionFinder.Sezpoz());
+        }
+        return hudson.getExtensionList(ExtensionFinder.class);
+    }
+
     public void load(PluginWrapper wrapper) throws IOException {
         // override the context classloader so that XStream activity in plugin.start()
         // will be able to resolve classes in this plugin
diff --git a/hudson-core/src/main/java/hudson/DescriptorExtensionList.java b/hudson-core/src/main/java/hudson/DescriptorExtensionList.java
index 7e72fca..e0265b3 100644
--- a/hudson-core/src/main/java/hudson/DescriptorExtensionList.java
+++ b/hudson-core/src/main/java/hudson/DescriptorExtensionList.java
@@ -143,11 +143,6 @@ public class DescriptorExtensionList<T extends Describable<T>, D extends Descrip
         return this;
     }
 
-    @Override
-    protected void scoutLoad() {
-        // no-op, since our load() doesn't by itself do any classloading
-    }
-
     /**
      * Loading the descriptors in this case means filtering the descriptor from the master {@link ExtensionList}.
      */
diff --git a/hudson-core/src/main/java/hudson/ExtensionList.java b/hudson-core/src/main/java/hudson/ExtensionList.java
index 4290c25..22fc9fb 100644
--- a/hudson-core/src/main/java/hudson/ExtensionList.java
+++ b/hudson-core/src/main/java/hudson/ExtensionList.java
@@ -23,7 +23,6 @@
  */
 package hudson;
 
-import hudson.ExtensionFinder.Sezpoz;
 import hudson.init.InitMilestone;
 import hudson.model.Hudson;
 import hudson.util.AdaptedIterator;
@@ -31,6 +30,7 @@ import hudson.util.DescriptorList;
 import hudson.util.Memoizer;
 import hudson.util.Iterators;
 import hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson;
+import hudson.PluginStrategy;
 
 import java.util.AbstractList;
 import java.util.ArrayList;
@@ -197,22 +197,12 @@ public class ExtensionList<T> extends AbstractList<T> {
         return null;
     }
 
-
-    /**
-     * Returns {@link ExtensionFinder}s used to search for the extension instances.
-     */
-    protected Iterable<? extends ExtensionFinder> finders() {
-        return hudson.getExtensionList(ExtensionFinder.class);
-    }
-
     private List<ExtensionComponent<T>> ensureLoaded() {
         if(extensions!=null)
             return extensions; // already loaded
         if(Hudson.getInstance().getInitLevel().compareTo(InitMilestone.PLUGINS_PREPARED)<0)
             return legacyInstances; // can't perform the auto discovery until all plugins are loaded, so just make the legacy instances visible
 
-        scoutLoad();
-
         synchronized (getLoadLock()) {
             if(extensions==null) {
                 List<ExtensionComponent<T>> r = load();
@@ -238,34 +228,13 @@ public class ExtensionList<T> extends AbstractList<T> {
     private static final class Lock {}
 
     /**
-     * See {@link ExtensionFinder#scout(Class, Hudson)} for the dead lock issue and what this does.
-     */
-    protected void scoutLoad() {
-        if (LOGGER.isLoggable(Level.FINER))
-            LOGGER.log(Level.FINER,"Scout-loading ExtensionList: "+extensionType, new Throwable());
-        for (ExtensionFinder finder : finders()) {
-            finder.scout(extensionType, hudson);
-        }
-    }
-
-    /**
      * Loads all the extensions.
      */
     protected List<ExtensionComponent<T>> load() {
         if (LOGGER.isLoggable(Level.FINE))
             LOGGER.log(Level.FINE,"Loading ExtensionList: "+extensionType, new Throwable());
 
-        List<ExtensionComponent<T>> r = new ArrayList<ExtensionComponent<T>>();
-        for (ExtensionFinder finder : finders()) {
-            try {
-                r.addAll(finder._find(extensionType, hudson));
-            } catch (AbstractMethodError e) {
-                // backward compatibility
-                for (T t : finder.findExtensions(extensionType, hudson))
-                    r.add(new ExtensionComponent<T>(t));
-            }
-        }
-        return r;
+        return hudson.getPluginManager().getPluginStrategy().findComponents(extensionType, hudson);
     }
 
     /**
@@ -282,19 +251,6 @@ public class ExtensionList<T> extends AbstractList<T> {
     }
 
     public static <T> ExtensionList<T> create(Hudson hudson, Class<T> type) {
-        if(type==ExtensionFinder.class)
-            return new ExtensionList<T>(hudson,type) {
-                Set<Sezpoz> finders = Collections.singleton(new Sezpoz());
-
-                /**
-                 * If this ExtensionList is searching for ExtensionFinders, calling hudson.getExtensionList
-                 * results in infinite recursion.
-                 */
-                @Override
-                protected Iterable<? extends ExtensionFinder> finders() {
-                    return finders;
-                }
-            };
         if(type.getAnnotation(LegacyInstancesAreScopedToHudson.class)!=null)
             return new ExtensionList<T>(hudson,type);
         else {
diff --git a/hudson-core/src/main/java/hudson/PluginStrategy.java b/hudson-core/src/main/java/hudson/PluginStrategy.java
index 0fe0e72..dad2b64 100644
--- a/hudson-core/src/main/java/hudson/PluginStrategy.java
+++ b/hudson-core/src/main/java/hudson/PluginStrategy.java
@@ -23,8 +23,11 @@
  */
 package hudson;
 
+import hudson.model.Hudson;
+
 import java.io.File;
 import java.io.IOException;
+import java.util.List;
 
 /**
  * Pluggability point for how to create {@link PluginWrapper}.
@@ -63,4 +66,13 @@ public interface PluginStrategy extends ExtensionPoint {
  */
  public abstract void initializeComponents(PluginWrapper plugin);
 
+ /**
+ * Find components of the given type using the assigned strategy.
+ *
+ * @param type The component type
+ * @param hudson The Hudson scope
+ * @return Sequence of components
+ * @since 1.397
+ */
+ public abstract <T> List<ExtensionComponent<T>> findComponents(Class<T> type, Hudson hudson);
 }


Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder,  Apache Maven
http://twitter.com/jvanzyl
---------------------------------------------------------

A party which is not afraid of letting culture,
business, and welfare go to ruin completely can
be omnipotent for a while.

  -- Jakob Burckhardt








[Hudson-Dev] HUDSON-8735: allow PluginStrategy implementations complete control over finding components

Stuart McCulloch 02/14/2011

[Hudson-Dev] Re: HUDSON-8735: allow PluginStrategy implementations complete control over finding components

Jason van Zyl 02/14/2011

[Hudson-Dev] Re: HUDSON-8735: allow PluginStrategy implementations complete control over finding components

Jason Dillon 02/14/2011

[Hudson-Dev] Re: HUDSON-8735: allow PluginStrategy implementations complete control over finding components

Jason Dillon 02/15/2011

[Hudson-Dev] Re: HUDSON-8735: allow PluginStrategy implementations complete control over finding components

Winston Prakash 02/15/2011

[Hudson-Dev] Re: HUDSON-8735: allow PluginStrategy implementations complete control over finding components

Jason Dillon 02/15/2011

[Hudson-Dev] Re: HUDSON-8735: allow PluginStrategy implementations complete control over finding components

Jason van Zyl 02/15/2011

[Hudson-Dev] Re: HUDSON-8735: allow PluginStrategy implementations complete control over finding components

Winston Prakash 02/15/2011
 
 
Close
loading
Please Confirm
Close