]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5191 fix some usage of java list.sort in ruby code
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 2 Apr 2014 13:35:37 +0000 (15:35 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 2 Apr 2014 13:35:48 +0000 (15:35 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/account_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/updatecenter_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/widgets_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/permission_templates_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/roles_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/rules_configuration_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb

index d16315a478307d5aec74d0fd1ca3d9bd7324c99a..a90cd7539b2b5d799164451edeed196f4ab8bddf 100644 (file)
@@ -97,7 +97,7 @@ class AccountController < ApplicationController
   end
   
   def dispatchers_for_scope(scope)
-    notification_service.getDispatcherKeysForProperty(scope, "true").sort {|x,y| dispatcher_name(x) <=> dispatcher_name(y)}
+    notification_service.getDispatcherKeysForProperty(scope, "true").to_a.sort {|x,y| dispatcher_name(x) <=> dispatcher_name(y)}
   end
   
   def dispatcher_name(dispatcher_key)
index 9816fed0f15a57ffee3da6571f18757bb0c9f2c5..555eb77744d7f10955eca522d0fd18ac9056340e 100644 (file)
@@ -65,6 +65,6 @@ class Api::UpdatecenterController < Api::ApiController
   end
 
   def user_plugins
-    java_facade.getPluginsMetadata().select{|plugin| !plugin.isCore()}.sort
+    java_facade.getPluginsMetadata().select{|plugin| !plugin.isCore()}.to_a.sort
   end
 end
index b47631ca6ee7b2fcd5c8f5522a5d437786493415..2f0fb8f32ee8950eac11028de37c5b30cf1c6a29 100644 (file)
@@ -20,7 +20,7 @@
 class Api::WidgetsController < Api::ApiController
 
   def index
-    widget_definitions = java_facade.getWidgets().sort_by{|w| w.getId()}
+    widget_definitions = java_facade.getWidgets().to_a.sort_by{|w| w.getId()}
     render :json => jsonp(widgets_to_json(widget_definitions))
   end
 
index 9a963391275f04c285635f637e6c0b890af124fe..a65dc801b75303390f698546853e95127a2a584a 100644 (file)
@@ -212,9 +212,9 @@ class DashboardController < ApplicationController
   end
 
   def load_widget_definitions(filter_on_category)
-    @widget_definitions=java_facade.getWidgets().sort {|w1,w2| widgetL10nName(w1) <=> widgetL10nName(w2)}
+    @widget_definitions=java_facade.getWidgets().to_a.sort {|w1,w2| widgetL10nName(w1) <=> widgetL10nName(w2)}
 
-    @widget_categories=@widget_definitions.map(&:getWidgetCategories).flatten.uniq.sort
+    @widget_categories=@widget_definitions.map(&:getWidgetCategories).to_a.flatten.uniq.sort
     unless filter_on_category.blank?
       @widget_definitions=@widget_definitions.select { |definition| definition.getWidgetCategories().to_a.include?(filter_on_category) }
     end
index ef8f6aa9149b7218275f3abea013642cf8fd0b65..fc073ec0ddb3b709f95ddc499d164a96e309349b 100644 (file)
@@ -273,7 +273,7 @@ class PermissionTemplatesController < ApplicationController
   # GET (modal form)
   #
   def default_templates_form
-    all_templates = Internal.permission_templates.selectAllPermissionTemplates
+    all_templates = Internal.permission_templates.selectAllPermissionTemplates.to_a
 
     @permission_templates_options = all_templates.sort_by {|t| t.name.downcase}.collect {|t| [t.name, t.key]}
     @root_qualifiers = get_root_qualifiers
@@ -300,7 +300,7 @@ class PermissionTemplatesController < ApplicationController
   private
 
   def get_root_qualifiers
-    Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceRootTypes().map {|type| type.getQualifier()}.sort
+    Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceRootTypes().map {|type| type.getQualifier()}.to_a.sort
   end
 
   def get_default_templates_per_qualifier(root_qualifiers)
index cc95b4f7d65d924b1a5817df022d8516a952bfb1..40a0f37b3952c003eb5c0d76d1b94fd32de16555 100644 (file)
@@ -38,7 +38,7 @@ class RolesController < ApplicationController
     params['qualifiers'] ||= 'TRK'
     @query_result = Internal.component_api.findWithUncompleteProjects(params)
 
-    @available_qualifiers = java_facade.getQualifiersWithProperty('hasRolePolicy').collect { |qualifier| [message("qualifiers.#{qualifier}"), qualifier] }.sort
+    @available_qualifiers = java_facade.getQualifiersWithProperty('hasRolePolicy').collect { |qualifier| [message("qualifiers.#{qualifier}"), qualifier] }.to_a.sort
 
     # For the moment, we return projects from rails models, but it should be replaced to return java components (this will need methods on ComponentQueryResult to return roles from component)
     @projects = Project.all(
@@ -96,9 +96,9 @@ class RolesController < ApplicationController
 
     if @components && @components.size == 1
       project = Project.by_key(@components.first)
-      @permission_templates = Internal.permission_templates.selectAllPermissionTemplates(project.key).sort_by {|t| t.name.downcase}.collect {|pt| [pt.name, pt.key]}
+      @permission_templates = Internal.permission_templates.selectAllPermissionTemplates(project.key).to_a.sort_by {|t| t.name.downcase}.collect {|pt| [pt.name, pt.key]}
     else
-      @permission_templates = Internal.permission_templates.selectAllPermissionTemplates().sort_by {|t| t.name.downcase}.collect {|pt| [pt.name, pt.key]}
+      @permission_templates = Internal.permission_templates.selectAllPermissionTemplates().to_a.sort_by {|t| t.name.downcase}.collect {|pt| [pt.name, pt.key]}
     end
 
     render :partial => 'apply_template_form'
index f2ccf7afba4058ecfcfe7760a5e74386d27293c7..96d071981ed297bf7a4ad3eb60e8faa100f5f814 100644 (file)
@@ -68,7 +68,7 @@ class RulesConfigurationController < ApplicationController
 
       @current_rules = result.rules
 
-      @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }.sort
+      @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }.to_a.sort
       @select_priority = ANY_SELECTION + RULE_PRIORITIES
       @select_activation = [[message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
       @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'],
@@ -77,7 +77,7 @@ class RulesConfigurationController < ApplicationController
                                         [message('rules.status.deprecated'), Rule::STATUS_DEPRECATED],
                                         [message('rules.status.ready'), Rule::STATUS_READY]]
       @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]]
-      @select_tags = ANY_SELECTION + Internal.rule_tags.listAllTags().sort
+      @select_tags = ANY_SELECTION + Internal.rule_tags.listAllTags().to_a.sort
     end
   end
 
@@ -408,7 +408,7 @@ class RulesConfigurationController < ApplicationController
   end
 
   def tag_selection_for_rule(rule)
-    Internal.rule_tags.listAllTags().sort.collect do |tag|
+    Internal.rule_tags.listAllTags().to_a.sort.collect do |tag|
       {
         :value => tag,
         :selected => (rule.systemTags.contains?(tag) || rule.adminTags.contains?(tag)),
index 89ed4d2ea4e1fea7fac4cfc602c54477682d827d..5ba939de87b720d1871046c51c042629781feb0c 100644 (file)
@@ -167,14 +167,18 @@ class Api::Utils
   # Api::Utils.insensitive_sort([foo, bar]) { |elt| elt.nullable_field_to_compare }
   #
   def self.insensitive_sort(arr)
+    ruby_array = arr
+    if arr.respond_to? :to_a
+      ruby_array = arr.to_a
+    end
     if block_given?
-      arr.sort do |a, b|
+      ruby_array.sort do |a, b|
         a_string=yield(a) || ''
         b_string=yield(b) || ''
         a_string.downcase <=> b_string.downcase || a_string <=> b_string
       end
     else
-      arr.sort do |a, b|
+      ruby_array.sort do |a, b|
         a_string=a || ''
         b_string=b || ''
         a_string.downcase <=> b_string.downcase || a_string <=> b_string