initial integration of the quick silver feature.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@4060 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2007-08-04 18:40:17 +00:00
1 parent 813f9a8be6
commit e12dd79534
16 files changed
+165 -23

No files matched your search

@@ -139,6 +139,10 @@ public abstract class AbstractItem extends Actionable implements Item {
return getParent().getUrlChildPrefix()+'/'+getName()+'/';
}
public String getSearchUrl() {
return getShortUrl();
}
@Exported(visibility=2,name="url")
public final String getAbsoluteUrl() {
StaplerRequest request = Stapler.getCurrentRequest();
@@ -6,12 +6,15 @@ import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import hudson.search.SearchableModelObject;
import hudson.search.SearchIndex;
/**
* {@link ModelObject} with some convenience methods.
*
* @author Kohsuke Kawaguchi
*/
public abstract class AbstractModelObject implements ModelObject {
public abstract class AbstractModelObject implements SearchableModelObject {
/**
* Displays the error in a page.
*/
@@ -23,4 +26,18 @@ public abstract class AbstractModelObject implements ModelObject {
req.setAttribute("message",message);
rsp.forward(this,"error",req);
}
/**
* Default implementation that returns empty index.
*/
public SearchIndex getSearchIndex() {
return SearchIndex.EMPTY;
}
/**
* Default implementation that returns the display name.
*/
public String getSearchName() {
return getDisplayName();
}
}
+4
View File
@@ -43,6 +43,10 @@ public class Api extends AbstractModelObject {
return "API";
}
public String getSearchUrl() {
return "api";
}
/**
* Exposes the bean as XML.
*/
+13 -5
View File
@@ -15,7 +15,6 @@ import hudson.TcpSlaveAgentListener;
import hudson.Util;
import static hudson.Util.fixEmpty;
import hudson.XmlFile;
import hudson.node_monitors.NodeMonitor;
import hudson.model.Descriptor.FormException;
import hudson.model.listeners.ItemListener;
import hudson.model.listeners.JobListener;
@@ -29,6 +28,8 @@ import hudson.scm.RepositoryBrowsers;
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
import hudson.scm.SCMS;
import hudson.search.SearchIndex;
import hudson.search.SearchIndexBuilder;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrappers;
@@ -40,12 +41,12 @@ import hudson.tasks.Publisher;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import hudson.triggers.Triggers;
import hudson.util.ClockDifference;
import hudson.util.CopyOnWriteList;
import hudson.util.CopyOnWriteMap;
import hudson.util.FormFieldValidator;
import hudson.util.MultipartFormDataParser;
import hudson.util.XStream2;
import hudson.util.ClockDifference;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
@@ -678,6 +679,15 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
return "";
}
@Override
public SearchIndex getSearchIndex() {
return new SearchIndexBuilder()
.add(super.getSearchIndex())
.add("configure", "config","configure")
.add("log", "log")
.make();
}
public String getUrlChildPrefix() {
return "job";
}
@@ -758,9 +768,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
return getItem(name);
}
/**
* Gets the {@link TopLevelItem} of the given name.
*/
@Override
public TopLevelItem getItem(String name) {
return items.get(name);
}
+3 -1
View File
@@ -5,6 +5,8 @@ import org.kohsuke.stapler.StaplerRequest;
import java.io.IOException;
import java.util.Collection;
import hudson.search.SearchableModelObject;
/**
* Basic configuration unit in Hudson.
*
@@ -33,7 +35,7 @@ import java.util.Collection;
* @author Kohsuke Kawaguchi
* @see Items
*/
public interface Item extends PersistenceRoot, ModelObject {
public interface Item extends PersistenceRoot, SearchableModelObject {
/**
* Gets the parent that contains this item.
*/
@@ -56,10 +56,14 @@ public class ListView extends View {
return Arrays.asList(items);
}
public TopLevelItem getJob(String name) {
public TopLevelItem getItem(String name) {
return owner.getItem(name);
}
public TopLevelItem getJob(String name) {
return getItem(name);
}
public boolean contains(TopLevelItem item) {
return jobNames.contains(item.getName());
}
+4
View File
@@ -395,6 +395,10 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
return project.getAbsoluteUrl()+getNumber()+'/';
}
public final String getSearchUrl() {
return getNumber()+"/";
}
/**
* Unique ID of this build.
*/
+5 -1
View File
@@ -87,7 +87,11 @@ public class User extends AbstractModelObject {
}
public String getUrl() {
return "user/"+ id;
return "user/"+id;
}
public String getSearchUrl() {
return "/user/"+id;
}
/**
+25 -3
View File
@@ -1,13 +1,16 @@
package hudson.model;
import hudson.Util;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;
import hudson.scm.ChangeLogSet.Entry;
import hudson.search.CollectionSearchIndex;
import hudson.search.SearchIndex;
import hudson.search.SearchIndexBuilder;
import hudson.util.RunList;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import javax.servlet.ServletException;
import java.io.IOException;
@@ -36,6 +39,11 @@ public abstract class View extends AbstractModelObject {
@Exported(name="jobs")
public abstract Collection<TopLevelItem> getItems();
/**
* Gets the {@link TopLevelItem} of the given name.
*/
public abstract TopLevelItem getItem(String name);
/**
* Checks if the job is in this collection.
*/
@@ -58,6 +66,10 @@ public abstract class View extends AbstractModelObject {
*/
public abstract String getUrl();
public String getSearchUrl() {
return getUrl();
}
/**
* Gets the absolute URL of this view.
*/
@@ -168,6 +180,16 @@ public abstract class View extends AbstractModelObject {
return r;
}
@Override
public SearchIndex getSearchIndex() {
return new SearchIndexBuilder()
.add(new CollectionSearchIndex() {
protected TopLevelItem get(String key) { return getItem(key); }
protected Collection<TopLevelItem> all() { return getItems(); }
})
.make();
}
/**
* Creates a new {@link Item} in this collection.
*
@@ -51,6 +51,10 @@ public abstract class AbstractScmTagAction extends AbstractModelObject implement
return "tagBuild";
}
public String getSearchUrl() {
return getUrlName();
}
public AbstractBuild getBuild() {
return build;
}
@@ -0,0 +1,28 @@
package hudson.search;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* {@link SearchIndex} built on a {@link Map}.
*
* @author Kohsuke Kawaguchi
*/
public abstract class CollectionSearchIndex implements SearchIndex {
protected abstract SearchItem get(String key);
protected abstract Collection<? extends SearchableModelObject> all();
public void find(String token, List<SearchItem> result) {
SearchItem p = get(token);
if(p!=null)
result.add(p);
}
public void suggest(String token, List<SearchItem> result) {
for (SearchableModelObject o : all()) {
if(o.getDisplayName().contains(token))
result.add(o);
}
}
}
@@ -1,10 +1,39 @@
package hudson.search;
import hudson.model.Build;
/**
* Represents an item reachable from {@link SearchIndex}.
*
* <p>
* The act of searching in this package is really a traversal of a directed graph.
* And in that notion, this interface represents an edge, not a node.
* So it's possible for single entity (let's say {@link Build}) to
* have multiple {@link SearchItem}s representing it (for example,
* a 'last successful build' search item and '#123' search item.)
*
* @author Kohsuke Kawaguchi
*/
public interface SearchItem {
/**
* Name of this item. This is matched against the query.
*/
String getSearchName();
String getSearchUrlFragment();
/**
* Returns the URL of this item relative to the parent {@link SearchItem}.
*
* @return
* URL like "foo" or "foo/bar". The path can end with '/'.
* The path that starts with '/' will be interpreted as the absolute path
* (within the context path of Hudson.)
*/
String getSearchUrl();
/**
* Returns the {@link SearchIndex} to further search into this item.
*
* @return
* {@link SearchIndex#EMPTY} if this is a leaf.
*/
SearchIndex getSearchIndex();
}
@@ -14,7 +14,7 @@ public class SearchItems {
return searchName;
}
public String getSearchUrlFragment() {
public String getSearchUrl() {
return url;
}
@@ -30,7 +30,7 @@ public class SearchItems {
return searchName;
}
public String getSearchUrlFragment() {
public String getSearchUrl() {
return url;
}
@@ -4,9 +4,14 @@ import hudson.model.ModelObject;
/**
* {@link ModelObject} that has {@link SearchIndex}.
*
*
* <p>
* This interface also extends {@link SearchItem} since
* often {@link ModelObject}s form a natural tree structure,
* and it's convenient for the model objects themselves to implement
* the {@link SearchItem} for the edges that form this tree.
*
* @author Kohsuke Kawaguchi
*/
public interface SearchableModelObject extends ModelObject {
SearchIndex getSearchIndex();
public interface SearchableModelObject extends ModelObject, SearchItem {
}
@@ -45,6 +45,14 @@ public class SuggestedItem {
if(parent!=null) {
parent.getUrl(buf);
}
buf.append('/').append(item.getSearchUrlFragment());
String f = item.getSearchUrl();
if(f.startsWith("/")) {
buf.setLength(0);
buf.append(f);
} else {
if(buf.charAt(buf.length()-1)!='/')
buf.append('/');
buf.append(f);
}
}
}
@@ -3,7 +3,7 @@ package hudson.tasks;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.util.FormFieldValidator;
import hudson.model.AbstractItem;
import hudson.model.Action;
import hudson.model.Build;
import hudson.model.BuildListener;
@@ -12,8 +12,7 @@ import hudson.model.DirectoryBrowserSupport;
import hudson.model.Project;
import hudson.model.ProminentProjectAction;
import hudson.model.Result;
import hudson.model.Actionable;
import hudson.model.AbstractItem;
import hudson.util.FormFieldValidator;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
@@ -81,7 +80,7 @@ public class JavadocArchiver extends Publisher {
public static final Descriptor<Publisher> DESCRIPTOR = new DescriptorImpl();
public static final class JavadocAction extends Actionable implements ProminentProjectAction {
public static final class JavadocAction implements ProminentProjectAction {
private final AbstractItem project;
public JavadocAction(AbstractItem project) {