aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-03-29 19:48:56 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-03-29 19:49:06 +0200
commitc7ce2ed60891b92de020374d976821694a3ed269 (patch)
tree41449668d438ffe499b9eff284e87c54df6bd3c4
parentb9f8b710d6f7c3ae5799fbacb9e93403b3babf08 (diff)
downloadsonarqube-c7ce2ed60891b92de020374d976821694a3ed269.tar.gz
sonarqube-c7ce2ed60891b92de020374d976821694a3ed269.zip
Generic search engine in order to handle all the ResourceType extensions
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java10
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb8
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/search/_autocomplete.html.erb11
3 files changed, 18 insertions, 11 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
index 8f2bcb7cd97..a55d5e2c28f 100644
--- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
+++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java
@@ -25,7 +25,9 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.config.License;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
-import org.sonar.api.platform.*;
+import org.sonar.api.platform.ComponentContainer;
+import org.sonar.api.platform.PluginMetadata;
+import org.sonar.api.platform.PluginRepository;
import org.sonar.api.profiles.ProfileExporter;
import org.sonar.api.profiles.ProfileImporter;
import org.sonar.api.resources.Language;
@@ -78,6 +80,10 @@ public final class JRubyFacade {
return getContainer().getComponentByType(ResourceTypes.class).getAll(ResourceTypes.AVAILABLE_FOR_FILTERS);
}
+ public Collection<ResourceType> getResourceTypes() {
+ return getContainer().getComponentByType(ResourceTypes.class).getAll();
+ }
+
public ResourceType getResourceType(String qualifier) {
return getContainer().getComponentByType(ResourceTypes.class).get(qualifier);
}
@@ -418,7 +424,7 @@ public final class JRubyFacade {
public String generateRandomSecretKey() {
return getContainer().getComponentByType(Settings.class).getEncryption().generateRandomSecretKey();
}
-
+
public License parseLicense(String base64) {
return License.readBase64(base64);
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb
index 5bc3e0bc9c7..171edc8a637 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb
@@ -41,11 +41,11 @@ class SearchController < ApplicationController
@total = results.size
resource_ids=[]
- @results_by_qualifier={}
+ @resource_indexes_by_qualifier={}
results.each do |resource_index|
qualifier = fix_qualifier(resource_index.qualifier)
- @results_by_qualifier[qualifier]||=[]
- array=@results_by_qualifier[qualifier]
+ @resource_indexes_by_qualifier[qualifier]||=[]
+ array=@resource_indexes_by_qualifier[qualifier]
if array.size<MAX_RESULTS
resource_ids<<resource_index.resource_id
array<<resource_index
@@ -54,7 +54,7 @@ class SearchController < ApplicationController
@resources_by_id = {}
unless resource_ids.empty?
- Project.find(:all, :conditions => ['id in (?)', resource_ids]).each do |resource|
+ Project.find(:all, :conditions => ['id in (?) and enabled=?', resource_ids, true]).each do |resource|
@resources_by_id[resource.id]=resource
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/search/_autocomplete.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/search/_autocomplete.html.erb
index 9dce955da7b..39341c87f0e 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/search/_autocomplete.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/search/_autocomplete.html.erb
@@ -1,15 +1,16 @@
-<% unless @results_by_qualifier.empty? %>
+<% unless @resource_indexes_by_qualifier.empty? %>
<ul>
<%
- Resourceable::QUALIFIERS.each do |qualifier|
- if @results_by_qualifier[qualifier]
+ controller.java_facade.getResourceTypes().each do |resource_type|
+ resource_indexes = @resource_indexes_by_qualifier[resource_type.getQualifier()]
+ if resource_indexes
first=true
- @results_by_qualifier[qualifier].each do |resource_index|
+ resource_indexes.each do |resource_index|
resource=@resources_by_id[resource_index.resource_id]
if resource
%>
<li id="<%= resource.id -%>">
- <div class="q"><%= message("qualifiers.#{qualifier}") if first -%></div>
+ <div class="q"><%= message("qualifiers.#{resource.qualifier}") if first -%></div>
<%= qualifier_icon resource -%> <%= highlight(truncate(resource.name(true), :length => 65), params[:s]) -%>
</li>
<% first=false