From 658fd226bad47e826df1cff45fd9e7bd99ad2ce3 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Tue, 5 Jun 2012 15:51:35 -0700 Subject: [PATCH] allowed plugins to implement subtypes of the Search class to provide different search implementations --- .../hudson/model/AbstractModelObject.java | 6 +++ .../java/hudson/search/SearchFactory.java | 45 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 core/src/main/java/hudson/search/SearchFactory.java diff --git a/core/src/main/java/hudson/model/AbstractModelObject.java b/core/src/main/java/hudson/model/AbstractModelObject.java index 6214af95d1..c104a3179c 100644 --- a/core/src/main/java/hudson/model/AbstractModelObject.java +++ b/core/src/main/java/hudson/model/AbstractModelObject.java @@ -23,6 +23,7 @@ */ package hudson.model; +import hudson.search.SearchFactory; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.Stapler; @@ -99,6 +100,11 @@ public abstract class AbstractModelObject implements SearchableModelObject { } public Search getSearch() { + for (SearchFactory sf : SearchFactory.all()) { + Search s = sf.createFor(this); + if (s!=null) + return s; + } return new Search(); } diff --git a/core/src/main/java/hudson/search/SearchFactory.java b/core/src/main/java/hudson/search/SearchFactory.java new file mode 100644 index 0000000000..5f01917dba --- /dev/null +++ b/core/src/main/java/hudson/search/SearchFactory.java @@ -0,0 +1,45 @@ +package hudson.search; + +import hudson.Extension; +import hudson.ExtensionList; +import hudson.ExtensionPoint; +import jenkins.model.Jenkins; + +/** + * Creates a {@link Search} instance for a {@link SearchableModelObject}. + * + *

+ * This allows you to plug in different backends to the search, such as full-text search, + * or more intelligent user-sensitive search, etc. Puts @{@link Extension} annotation + * on your implementation to have it registered. + * + *

+ * Right now, there's no user control over which {@link SearchFactory} takes priority, + * but we may do so later. + * + * @author Kohsuke Kawaguchi + * @since 1.469 + */ +public abstract class SearchFactory implements ExtensionPoint { + /** + * Creates a {@link Search} object. + * + * This method needs to execute quickly (without actually executing any search), + * since it is created per incoming HTTP response. + * + * @param owner + * The {@link SearchableModelObject} object for which we are creating the search. + * The returned object will provide the search for this object. + * @return + * null if your factory isn't interested in creating a {@link Search} object. + * The next factory will get a chance to act on it. + */ + public abstract Search createFor(SearchableModelObject owner); + + /** + * Returns all the registered {@link SearchFactory} instances. + */ + public static ExtensionList all() { + return Jenkins.getInstance().getExtensionList(SearchFactory.class); + } +} -- GitLab