diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-02-22 00:33:15 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-02-22 00:33:15 +0100 |
commit | 323ace33d564b236e17bce37c8513ee0148aa262 (patch) | |
tree | 76197f8c44109aaa24904f30a49fabe91f5c7507 /sonar-server | |
parent | 58d94501900849959346beb5988454122c623470 (diff) | |
download | sonarqube-323ace33d564b236e17bce37c8513ee0148aa262.tar.gz sonarqube-323ace33d564b236e17bce37c8513ee0148aa262.zip |
SONAR-3208 new extension point to declare tree of resource types
* new extension point org.sonar.api.resources.ResourceTypeTree
* new component org.sonar.api.resources.ResourceTypes to access resource types
* fix compatibility of hotspots, clouds and treemaps with PROJECT_MEASURES.PERSON_ID
* ApplicationController share ruby methods to load the selected resource
Diffstat (limited to 'sonar-server')
28 files changed, 163 insertions, 278 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index 439c51b2183..13f29b6b079 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -28,6 +28,7 @@ import org.sonar.api.profiles.AnnotationProfileParser; import org.sonar.api.profiles.XMLProfileParser; import org.sonar.api.profiles.XMLProfileSerializer; import org.sonar.api.resources.Languages; +import org.sonar.api.resources.ResourceTypes; import org.sonar.api.rules.AnnotationRuleParser; import org.sonar.api.rules.DefaultRulesManager; import org.sonar.api.rules.XMLRuleParser; @@ -66,7 +67,10 @@ import org.sonar.server.qualitymodel.DefaultModelManager; import org.sonar.server.rules.ProfilesConsole; import org.sonar.server.rules.RulesConsole; import org.sonar.server.startup.*; -import org.sonar.server.ui.*; +import org.sonar.server.ui.CodeColorizers; +import org.sonar.server.ui.JRubyI18n; +import org.sonar.server.ui.SecurityRealmFactory; +import org.sonar.server.ui.Views; import javax.servlet.ServletContext; @@ -205,7 +209,7 @@ public final class Platform { servicesContainer.addSingleton(I18nManager.class); servicesContainer.addSingleton(RuleI18nManager.class); servicesContainer.addSingleton(GwtI18n.class); - servicesContainer.addSingleton(ResourceDefinitionRepository.class); + servicesContainer.addSingleton(ResourceTypes.class); // Notifications servicesContainer.addSingleton(NotificationService.class); 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 d20f65a6cb5..5ec0171e4ef 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 @@ -29,7 +29,8 @@ import org.sonar.api.platform.PluginRepository; import org.sonar.api.profiles.ProfileExporter; import org.sonar.api.profiles.ProfileImporter; import org.sonar.api.resources.Language; -import org.sonar.api.resources.ResourceDefinition; +import org.sonar.api.resources.ResourceType; +import org.sonar.api.resources.ResourceTypes; import org.sonar.api.rules.RulePriority; import org.sonar.api.rules.RuleRepository; import org.sonar.api.utils.ValidationMessages; @@ -73,14 +74,22 @@ public final class JRubyFacade { return getContainer().getComponentByType(FilterExecutor.class).execute(filter); } - public Collection<ResourceDefinition> getResourceDefinitionsForFilter() { - return getContainer().getComponentByType(ResourceDefinitionRepository.class).getForFilter(); + public Collection<ResourceType> getResourceTypesForFilter() { + return getContainer().getComponentByType(ResourceTypes.class).getAll(ResourceTypes.AVAILABLE_FOR_FILTERS); } - public ResourceDefinition getResourceDefinition(String qualifier) { - return getContainer().getComponentByType(ResourceDefinitionRepository.class).get(qualifier); + public ResourceType getResourceType(String qualifier) { + return getContainer().getComponentByType(ResourceTypes.class).get(qualifier); } + public Collection<String> getResourceLeavesQualifiers(String qualifier) { + return getContainer().getComponentByType(ResourceTypes.class).getLeavesQualifiers(qualifier); + } + + public Collection<String> getResourceChildrenQualifiers(String qualifier) { + return getContainer().getComponentByType(ResourceTypes.class).getChildrenQualifiers(qualifier); + } + // UPDATE CENTER ------------------------------------------------------------ public void downloadPlugin(String pluginKey, String pluginVersion) { @@ -259,7 +268,7 @@ public final class JRubyFacade { public void ruleSeverityChanged(int parentProfileId, int activeRuleId, int oldSeverityId, int newSeverityId, String userName) { getProfilesManager().ruleSeverityChanged(parentProfileId, activeRuleId, RulePriority.values()[oldSeverityId], - RulePriority.values()[newSeverityId], userName); + RulePriority.values()[newSeverityId], userName); } public void ruleDeactivated(int parentProfileId, int deactivatedRuleId, String userName) { diff --git a/sonar-server/src/main/java/org/sonar/server/ui/ResourceDefinitionRepository.java b/sonar-server/src/main/java/org/sonar/server/ui/ResourceDefinitionRepository.java deleted file mode 100644 index 8f79ca0b526..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/ui/ResourceDefinitionRepository.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.server.ui; - -import com.google.common.annotations.Beta; -import com.google.common.base.Predicate; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import org.sonar.api.BatchComponent; -import org.sonar.api.ServerComponent; -import org.sonar.api.resources.ResourceDefinition; - -import java.util.Collection; -import java.util.Map; - -/** - * @since 2.14 - */ -@Beta -public class ResourceDefinitionRepository implements BatchComponent, ServerComponent { - - private final Map<String, ResourceDefinition> descriptionsByQualifier; - - public ResourceDefinitionRepository(ResourceDefinition[] descriptions) { - ImmutableMap.Builder<String, ResourceDefinition> map = ImmutableMap.builder(); - for (ResourceDefinition description : descriptions) { - map.put(description.getQualifier(), description); - } - descriptionsByQualifier = map.build(); - } - - public ResourceDefinition get(String qualifier) { - ResourceDefinition result = descriptionsByQualifier.get(qualifier); - if (result != null) { - return result; - } - // to avoid NPE on ruby side - return ResourceDefinition.builder(qualifier).build(); - } - - public Collection<ResourceDefinition> getAll() { - return descriptionsByQualifier.values(); - } - - public Collection<ResourceDefinition> getForFilter() { - return ImmutableList.copyOf(Collections2.filter(descriptionsByQualifier.values(), IS_AVAILABLE_FOR_FILTER)); - } - - private static final Predicate<ResourceDefinition> IS_AVAILABLE_FOR_FILTER = new Predicate<ResourceDefinition>() { - public boolean apply(ResourceDefinition input) { - return input.isAvailableForFilters(); - } - }; - -} diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb index 9339498e20a..a705aed664d 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb @@ -147,4 +147,26 @@ class ApplicationController < ActionController::Base end end + + # + # FILTERS + # + def init_resource_for_user_role + init_resource_for_role :user + end + + def init_resource_for_admin_role + init_resource_for_role :admin + end + + def init_resource_for_role(role) + @resource=Project.by_key(params[:id]) + not_found("Project not found") unless @resource + @resource=@resource.permanent_resource + + @snapshot=@resource.last_snapshot + not_found("Snapshot not found") unless @snapshot + + access_denied unless has_role?(role, @resource) + end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/cloud_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/cloud_controller.rb index fb046bb9f9a..5ca6f0925e4 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/cloud_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/cloud_controller.rb @@ -20,14 +20,9 @@ class CloudController < ApplicationController SECTION=Navigation::SECTION_RESOURCE + before_filter :init_resource_for_user_role def index - resource_key = params[:id] - @project = resource_key ? Project.by_key(resource_key) : nil - not_found("Project not found") unless @project - access_denied unless has_role?(:user, @project) - @snapshot=@project.last_snapshot - @size_metric=Metric.by_key(params[:size]||'ncloc') @color_metric=Metric.by_key(params[:color]||'coverage') @@ -35,11 +30,11 @@ class CloudController < ApplicationController @color_metric=Metric.by_key('violations_density') end - snapshot_conditions='snapshots.islast=:islast AND snapshots.scope=:scope AND snapshots.qualifier!=:test_qualifier AND + snapshot_conditions='snapshots.islast=:islast AND snapshots.qualifier in (:qualifiers) AND snapshots.qualifier!=:test_qualifier AND (snapshots.id=:sid OR (snapshots.root_snapshot_id=:root_sid AND snapshots.path LIKE :path))' snapshot_values={ :islast => true, - :scope => 'FIL', + :qualifiers => @snapshot.leaves_qualifiers, :test_qualifier => 'UTS', :sid => @snapshot.id, :root_sid => (@snapshot.root_snapshot_id || @snapshot.id), @@ -57,7 +52,7 @@ class CloudController < ApplicationController color_measures=ProjectMeasure.find(:all, :select => 'project_measures.id,project_measures.value,project_measures.metric_id,project_measures.snapshot_id,project_measures.rule_id,project_measures.rule_priority,project_measures.text_value,project_measures.characteristic_id,project_measures.alert_status', :joins => :snapshot, - :conditions => [snapshot_conditions + " AND project_measures.metric_id=#{@color_metric.id}", snapshot_values], + :conditions => [snapshot_conditions + " AND project_measures.metric_id=#{@color_metric.id} AND project_measures.rule_id IS NULL AND "+ "project_measures.characteristic_id IS NULL AND project_measures.person_id IS NULL", snapshot_values], :order => 'project_measures.value') @size_measure_by_sid={}, @color_measure_by_sid={} diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/components_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/components_controller.rb index 92c1b0bb427..9e8e23cc0f8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/components_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/components_controller.rb @@ -33,12 +33,9 @@ class ComponentsController < ApplicationController TREEMAP_COLOR_METRIC_PROPERTY = 'sonar.core.treemap.colormetric' def index + init_resource_for_user_role @components_configuration = Sonar::ComponentsConfiguration.new - @project = Project.by_key(params[:id]) - not_found("Project not found") unless @project - access_denied unless has_role?(:user, @project) - @snapshot = @project.last_snapshot @snapshots = Snapshot.find(:all, :include => 'project', :conditions => ['snapshots.parent_snapshot_id=? and snapshots.qualifier<>? and projects.qualifier<>?', @snapshot.id, Snapshot::QUALIFIER_UNIT_TEST_CLASS, Snapshot::QUALIFIER_UNIT_TEST_CLASS]) @columns = @components_configuration.selected_columns diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb index f089ad08464..83a3d3dfb88 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb @@ -182,16 +182,8 @@ class DashboardController < ApplicationController end def load_resource - @resource=Project.by_key(params[:id]) - not_found("Resource not found") unless @resource - - @resource=@resource.switch_resource if @resource.switch_resource - - access_denied unless has_role?(:user, @resource) - @snapshot = @resource.last_snapshot - not_found("Snapshot not found") unless @snapshot - - @project=@resource # variable name used in old widgets + init_resource_for_user_role + @project=@resource # for backward compatibility with old widgets end def load_authorized_widget_definitions diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb index 44e001d1d9a..848e046f371 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/drilldown_controller.rb @@ -18,7 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # class DrilldownController < ApplicationController - before_filter :init_project + before_filter :init_resource_for_user_role helper ProjectHelper, DashboardHelper @@ -54,14 +54,14 @@ class DrilldownController < ApplicationController end # load data - @drilldown = Drilldown.new(@project, @metric, selected_rids, options) + @drilldown = Drilldown.new(@resource, @metric, selected_rids, options) @highlighted_resource=@drilldown.highlighted_resource if @highlighted_resource.nil? && @drilldown.columns.empty? - @highlighted_resource=@project + @highlighted_resource=@resource end - @display_viewers=display_metric_viewers?(@highlighted_resource||@project, @highlighted_metric.key) + @display_viewers=display_metric_viewers?(@highlighted_resource||@resource, @highlighted_metric.key) end def violations @@ -112,11 +112,11 @@ class DrilldownController < ApplicationController end # load data - @drilldown = Drilldown.new(@project, @metric, @selected_rids, options) + @drilldown = Drilldown.new(@resource, @metric, @selected_rids, options) @highlighted_resource=@drilldown.highlighted_resource if @highlighted_resource.nil? && @drilldown.columns.empty? - @highlighted_resource=@project + @highlighted_resource=@resource end @@ -143,16 +143,6 @@ class DrilldownController < ApplicationController private - def init_project - project_key = params[:id] - @project = project_key ? Project.by_key(project_key) : nil - # For security reasons, we must not return 404 not found. It would be an information that the resource exists. - not_found("Resource not found") unless @project - - @snapshot = @project.last_snapshot - access_denied unless has_role?(:user, @snapshot) - end - def select_metric(metric_key, default_key) metric=nil if metric_key diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb index 148153659f6..56344f3de57 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/manual_measures_controller.rb @@ -20,7 +20,7 @@ class ManualMeasuresController < ApplicationController SECTION=Navigation::SECTION_RESOURCE - before_filter :load_resource + before_filter :init_resource_for_admin_role verify :method => :post, :only => [:save, :delete], :redirect_to => {:action => :index} helper MetricsHelper @@ -66,13 +66,6 @@ class ManualMeasuresController < ApplicationController private - def load_resource - @resource=Project.by_key(params[:id]) - return redirect_to home_path unless @resource - access_denied unless has_role?(:admin, @resource) - @snapshot=@resource.last_snapshot - end - def load_measures @measures=ManualMeasure.find(:all, :conditions => ['resource_id=?', @resource.id]).select { |m| m.metric.enabled } end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/plugins/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/plugins/resource_controller.rb index 61ffbcd6c9d..4b835e19d4b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/plugins/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/plugins/resource_controller.rb @@ -23,10 +23,11 @@ class Plugins::ResourceController < ApplicationController helper :project def index - @project = ::Project.by_key(params[:id]) - not_found("Not found") unless @project + @resource = ::Project.by_key(params[:id]) + not_found("Not found") unless @resource + @project=@resource # for backward-compatibility - @snapshot=@project.last_snapshot + @snapshot=@resource.last_snapshot page_id=params[:page] @page_proxy=java_facade.getPage(page_id) @@ -36,7 +37,7 @@ class Plugins::ResourceController < ApplicationController authorized=@page_proxy.getUserRoles().size==0 unless authorized @page_proxy.getUserRoles().each do |role| - authorized= (role=='user') || (role=='viewer') || has_role?(role, @project) + authorized= (role=='user') || (role=='viewer') || has_role?(role, @resource) break if authorized end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index 087771bc59c..304b410e35a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -32,6 +32,7 @@ class ResourceController < ApplicationController def index @resource = Project.by_key(params[:id]) not_found("Resource not found") unless @resource + @resource=@resource.permanent_resource access_denied unless has_role?(:user, @resource) params[:layout]='false' diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/timemachine_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/timemachine_controller.rb index 0fa2ae57dad..271849f291f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/timemachine_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/timemachine_controller.rb @@ -28,11 +28,7 @@ class TimemachineController < ApplicationController MAX_SNAPSHOTS = 5 def index - @project = Project.by_key(params[:id]) - return redirect_to home_url unless @project - @snapshot=@project.last_snapshot - - access_denied unless is_user?(@snapshot) + init_resource_for_user_role if params[:sid] @sids = params[:sid].split(',').collect {|s| s.to_i} @@ -42,9 +38,9 @@ class TimemachineController < ApplicationController # @snapshots=Snapshot.find(:all, :include => 'events', - :conditions => {:id => @sids, :project_id => @project.id, :scope => @project.scope, :qualifier => @project.qualifier}, :order => 'snapshots.created_at ASC') + :conditions => {:id => @sids, :project_id => @resource.id, :scope => @resource.scope, :qualifier => @resource.qualifier}, :order => 'snapshots.created_at ASC') else - @snapshots=Snapshot.for_timemachine_matrix(@project) + @snapshots=Snapshot.for_timemachine_matrix(@resource) @sids = @snapshots.collect{|s| s.id}.uniq end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/treemap_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/treemap_controller.rb index 1406b0e2a8d..eda7f53536b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/treemap_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/treemap_controller.rb @@ -44,6 +44,8 @@ class TreemapController < ApplicationController bad_request('Unknown resource: ' + params[:resource]) unless resource bad_request('Data not available') unless resource.last_snapshot access_denied unless has_role?(:user, resource) + resource = resource.permanent_resource + elsif params[:filter] filter=::Filter.find(params[:filter]) bad_request('Unknown filter: ' + params[:filter]) unless filter diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb index 81c4a3915c5..2197090c2c0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb @@ -38,11 +38,11 @@ module ApplicationHelper end end + # TODO this method should be moved in resourceable.rb def qualifier_icon(object) qualifier=(object.respond_to?('qualifier') ? object.qualifier : object.to_s) if qualifier - definition = Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceDefinition(qualifier) - image_tag definition.getIconPath(), :alt => '', :size => '16x16' + image_tag Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceType(qualifier).getIconPath(), :alt => '', :size => '16x16' else image_tag 'e16.gif' end @@ -198,8 +198,8 @@ module ApplicationHelper def url_for_resource_gwt(page, options={}) if options[:resource] "#{ApplicationController.root_context}/plugins/resource/#{options[:resource]}?page=#{page}" - elsif @project - "#{ApplicationController.root_context}/plugins/resource/#{@project.id}?page=#{page}" + elsif @resource + "#{ApplicationController.root_context}/plugins/resource/#{@resource.id}?page=#{page}" else '' end @@ -220,7 +220,7 @@ module ApplicationHelper # url_for_drilldown('ncloc', {:resource => 'org.apache.struts:struts-parent'}) # def url_for_drilldown(metric_or_measure, options={}) - if options[:resource].nil? && !@project + if options[:resource].nil? && !@resource return '' end @@ -232,7 +232,7 @@ module ApplicationHelper metric_key = metric_or_measure end - url_params={:controller => 'drilldown', :action => 'measures', :metric => metric_key, :id => options[:resource]||@project.id} + url_params={:controller => 'drilldown', :action => 'measures', :metric => metric_key, :id => options[:resource]||@resource.id} url_for(options.merge(url_params)) end @@ -328,7 +328,8 @@ module ApplicationHelper period_index=nil if period_index && period_index<=0 if resource.display_dashboard? if options[:dashboard] - link_to(name || resource.name, {:overwrite_params => {:controller => 'dashboard', :action => 'index', :id => resource.id, :period => period_index, :tab => options[:tab], :rule => options[:rule]}}, :title => options[:title]) + link_to(name || resource.name, {:overwrite_params => {:controller => 'dashboard', :action => 'index', :id => resource.id, :period => period_index, + :tab => options[:tab], :rule => options[:rule]}}, :title => options[:title]) else # stay on the same page (for example components) link_to(name || resource.name, {:overwrite_params => {:id => resource.id, :period => period_index, :tab => options[:tab], :rule => options[:rule]}}, :title => options[:title]) @@ -415,7 +416,7 @@ module ApplicationHelper def link_to_favourite(resource, options={}) return '' unless (logged_in?) return '' if resource.nil? - resource_id=(resource.is_a?(Fixnum) ? resource : resource.switch_resource_or_self.id) + resource_id=(resource.is_a?(Fixnum) ? resource : resource.permanent_id) html_id=options['html_id'] || "fav#{resource_id}" initial_class='notfav' initial_tooltip=message('click_to_add_to_favourites') diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb index 1104067b628..40f1a3eadf9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/drilldown.rb @@ -19,24 +19,6 @@ # class Drilldown - DEFAULT=[['TRK'], ['BRC'], ['DIR', 'PAC'], ['FIL', 'CLA', 'UTS']] - VIEWS=[['VW'], ['SVW'], ['TRK']] - PERSONS=[['PERSON'], ['PERSON_PRJ']] - TREES=[DEFAULT, VIEWS, PERSONS] - - def self.qualifier_children(q) - return [] if q==nil - TREES.each do |tree| - tree.each_with_index do |qualifiers, index| - if qualifiers==q || qualifiers.include?(q) - return index+1<tree.size ? tree[index+1] : [] - end - end - end - [] - end - - attr_reader :resource, :metric, :selected_resource_ids attr_reader :snapshot, :columns, :highlighted_resource, :highlighted_snapshot @@ -85,13 +67,13 @@ class DrilldownColumn # switch if @base_snapshot.resource.copy_resource @base_snapshot=@base_snapshot.resource.copy_resource.last_snapshot - @qualifiers = Drilldown.qualifier_children(@base_snapshot.qualifier) + @qualifiers = @base_snapshot.children_qualifiers elsif previous_column - @qualifiers=Drilldown.qualifier_children(previous_column.qualifiers) + @qualifiers=previous_column.qualifiers.map {|q| Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceChildrenQualifiers(q).to_a}.flatten else - @qualifiers=Drilldown.qualifier_children(drilldown.snapshot.qualifier) + @qualifiers=drilldown.snapshot.children_qualifiers end @resource_per_sid={} end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb index 9770cd07802..fd185edcc55 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project.rb @@ -54,9 +54,9 @@ class Project < ActiveRecord::Base def root_project @root_project ||= - begin - parent_module(self) - end + begin + parent_module(self) + end end # bottom-up array of projects, @@ -66,26 +66,30 @@ class Project < ActiveRecord::Base nodes end - def switch_resource - @switch_resource ||= - begin - (copy_resource && copy_resource.qualifier==qualifier) ? copy_resource : nil - end + def resource_link + @resource_link ||= + begin + (copy_resource && copy_resource.qualifier==qualifier) ? copy_resource : nil + end end - def switch_resource_or_self - switch_resource||self + def permanent_resource + resource_link||self + end + + def permanent_id + permanent_resource.id end def last_snapshot @last_snapshot ||= - begin - snapshot=Snapshot.find(:first, :conditions => {:islast => true, :project_id => id}) - if snapshot - snapshot.project=self + begin + snapshot=Snapshot.find(:first, :conditions => {:islast => true, :project_id => id}) + if snapshot + snapshot.project=self + end + snapshot end - snapshot - end end def events_with_snapshot @@ -115,13 +119,13 @@ class Project < ActiveRecord::Base def chart_measures(metric_id) sql = Project.send(:sanitize_sql, ['select s.created_at as created_at, m.value as value ' + - ' from project_measures m, snapshots s ' + - ' where s.id=m.snapshot_id and ' + - " s.status='%s' and " + - ' s.project_id=%s and m.metric_id=%s ', Snapshot::STATUS_PROCESSED, self.id, metric_id]) + - ' and m.rule_id IS NULL and m.rule_priority IS NULL' + - ' and m.person_id IS NULL' + - ' order by s.created_at' + ' from project_measures m, snapshots s ' + + ' where s.id=m.snapshot_id and ' + + " s.status='%s' and " + + ' s.project_id=%s and m.metric_id=%s ', Snapshot::STATUS_PROCESSED, self.id, metric_id]) + + ' and m.rule_id IS NULL and m.rule_priority IS NULL' + + ' and m.person_id IS NULL' + + ' order by s.created_at' create_chart_measures(Project.connection.select_all(sql), 'created_at', 'value') end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/sonar/treemap.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/sonar/treemap.rb index 3bfbc684303..ceea573b8d8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/sonar/treemap.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/sonar/treemap.rb @@ -77,7 +77,7 @@ class Sonar::Treemap metric_ids << @color_metric.id if @color_metric && @color_metric.id!=@size_metric.id sql_conditions = 'snapshots.islast=? AND project_measures.characteristic_id IS NULL and project_measures.rule_id IS NULL ' + - 'and project_measures.rule_priority IS NULL and project_measures.metric_id in (?)' + 'and project_measures.rule_priority IS NULL and project_measures.person_id IS NULL and project_measures.metric_id in (?)' sql_values = [true, metric_ids] if @root_snapshot sql_conditions += " AND snapshots.parent_snapshot_id=?" @@ -107,7 +107,7 @@ class Sonar::Treemap :title => escape_javascript(resource.name(true)), :tooltip => tooltip(resource, size_measure, color_measure), :color => html_color(color_measure), - :rid => resource.switch_resource_or_self.id, + :rid => resource.id, :leaf => resource.source_code?) node.add_child(child) end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/cloud/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/cloud/index.html.erb index d7ac85e483a..39287cc2681 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/cloud/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/cloud/index.html.erb @@ -18,7 +18,7 @@ </script> <div> - <form id="cloudform" action="<%= ApplicationController.root_context -%>/cloud/index/<%= @project.id -%>" method="GET"> + <form id="cloudform" action="<%= ApplicationController.root_context -%>/cloud/index/<%= @resource.id -%>" method="GET"> <ul class="headerLine"> <li> <span><%= message('color') -%>:</span> @@ -53,7 +53,11 @@ size_measure=@size_measure_by_sid[s.id] if size_measure && size_measure.value color_measure=@color_measure_by_sid[s.id] - link="of(#{s.project_id})" + if s.source_code? + link="of(#{s.project_id})" + else + link="ov(#{s.project_id})" + end title="#{s.resource.long_name} | #{@size_metric.short_name}: #{size_measure.formatted_value}" if color_measure && color_measure.value diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/components/_list_edit_mode_controls.rhtml b/sonar-server/src/main/webapp/WEB-INF/app/views/components/_list_edit_mode_controls.rhtml index 9af86fae226..5416e7d7f92 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/components/_list_edit_mode_controls.rhtml +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/components/_list_edit_mode_controls.rhtml @@ -10,7 +10,7 @@ <td width="1%" nowrap><%= message('add_a_column') -%></td> <td> <form action="<%= url_for :controller => "columns", :action => "add" -%>" > - <input type="hidden" name="rid" value="<%= @project.id if @project %>" /> + <input type="hidden" name="rid" value="<%= @resource.id if @resource %>" /> <select name="id" onchange="$('add_column_loading').show();submit();" id="select_add_column"> <option value=""></option> <% addeable_columns.keys.sort.each do |domain| %> @@ -30,7 +30,7 @@ <td width="1%" nowrap><%= message('default_sort_on') -%> </td> <td> <form action="<%= url_for :controller => "columns", :action => "default_sorting" -%>"> - <input type="hidden" name="rid" value="<%= @project.id if @project %>" /> + <input type="hidden" name="rid" value="<%= @resource.id if @resource %>" /> <select name="id" onchange="$('sort_column_loading').show();submit();" id="select_default_sorting"> <option value="project" <%= 'selected' if components_configuration.sorted_by_project_name? -%>><%= message('project_name') -%></option> <% configured_columns.sort_by{|col| col.name}.each do |column| @@ -46,9 +46,9 @@ <tr> <td colspan="2"> <%= link_to( message('enable_treemap'), - {:controller => "columns", :action => "toggle_treemap", :rid => @project.id}, {:class => 'action'} ) if (!components_configuration.treemap_enabled?) %> + {:controller => "columns", :action => "toggle_treemap", :rid => @resource.id}, {:class => 'action'} ) if (!components_configuration.treemap_enabled?) %> <%= link_to( message('disable_treemap'), - {:controller => "columns", :action => "toggle_treemap", :rid => @project.id}, {:class => 'action'} ) if components_configuration.treemap_enabled? %> + {:controller => "columns", :action => "toggle_treemap", :rid => @resource.id}, {:class => 'action'} ) if components_configuration.treemap_enabled? %> <%= image_tag("treemap_icon.png") %> </td> </tr> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/components/_list_table_header_edit_mode.rhtml b/sonar-server/src/main/webapp/WEB-INF/app/views/components/_list_table_header_edit_mode.rhtml index f1f943fcb7d..eb573f153ca 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/components/_list_table_header_edit_mode.rhtml +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/components/_list_table_header_edit_mode.rhtml @@ -16,11 +16,11 @@ <% configured_columns.each do |column| %> <th class="right nosort" nowrap="nowrap"> <%= link_to( image_tag("controls/resultset_previous.png", :alt => message('move_left'), :id => "move_left_" + column.id), - {:controller => "columns", :action => "left", :id => column.id, :rid => @project.id}, :class => 'nolink') if column.position > 0 %> + {:controller => "columns", :action => "left", :id => column.id, :rid => @resource.id}, :class => 'nolink') if column.position > 0 %> <%= link_to( image_tag("bin_closed.png", :alt => message('remove_column'), :id => "remove_" + column.id), - {:controller => "columns", :action => "delete", :id => column.id, :rid => @project.id}, :class => 'nolink') %> + {:controller => "columns", :action => "delete", :id => column.id, :rid => @resource.id}, :class => 'nolink') %> <%= link_to( image_tag("controls/resultset_next.png", :alt => message('move_right'), :id => "move_right_" + column.id), - {:controller => "columns", :action => "right", :id => column.id, :rid => @project.id}, :class => 'nolink') if column.position != configured_columns.size - 1 %> + {:controller => "columns", :action => "right", :id => column.id, :rid => @resource.id}, :class => 'nolink') if column.position != configured_columns.size - 1 %> </th> <% end %> </tr> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/components/_treemap_settings.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/components/_treemap_settings.html.erb index 5d3a0be68ea..54846aa3560 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/components/_treemap_settings.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/components/_treemap_settings.html.erb @@ -1,6 +1,6 @@ <div id="treemap_set_default"> <%= render :partial => 'components/treemap_set_default', - :locals => {:controller => 'components', :size_metric => @treemap.size_metric.key, :color_metric => @treemap.color_metric.key, :rid => @project.id } %> + :locals => {:controller => 'components', :size_metric => @treemap.size_metric.key, :color_metric => @treemap.color_metric.key, :rid => @resource.id } %> </div> <table class="spaced"> <tr> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/components/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/components/index.html.erb index 5077905767d..4ea90f9441a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/components/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/components/index.html.erb @@ -17,7 +17,7 @@ <% if has_role?(:admin) && configuring? %> <%= render :partial => 'list_edit_mode_controls', :locals => {:configured_columns => @columns, :components_configuration => @components_configuration} %> <% end %> -<% if @snapshots.empty? && @project.nil? %> +<% if @snapshots.empty? && @resource.nil? %> <h3><%= message('components.no_projects_have_been_analysed') -%>No projects have been analysed.</h3> <p><%= message('components.explanation_launch_sonar_to_have_results') -%></p> <% else %> @@ -69,7 +69,7 @@ <td width="<%= @treemap.width -%>" valign="top"> <script> new Treemap(1, '<%= @treemap.size_metric ? @treemap.size_metric.key : '' -%>', '<%= @treemap.color_metric ? @treemap.color_metric.key : '' -%>', 100.0).init('resource', - <%= @project.id -%>); + <%= @resource.id -%>); </script> <div id="tm-1" class="treemap" style="height:<%= @treemap.height %>px"> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_header.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_header.html.erb index ad5fc2cb940..3ceb11fb1ce 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_header.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_header.html.erb @@ -10,7 +10,7 @@ if (display_title == undefined) { display_title = true; } - new Ajax.Updater('resource_container', baseUrl + '/resource/index/' + resourceId + '?metric=<%= @metric.id if @metric -%>&rule=<%= @rule ? @rule.id : @severity -%>&period=<%= @period -%>&project=<%= @project.id -%>&display_title=' + display_title, {asynchronous:true, evalScripts:true}); + new Ajax.Updater('resource_container', baseUrl + '/resource/index/' + resourceId + '?metric=<%= @metric.id if @metric -%>&rule=<%= @rule ? @rule.id : @severity -%>&period=<%= @period -%>&project=<%= @resource.id -%>&display_title=' + display_title, {asynchronous:true, evalScripts:true}); return false; } </script> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_severity.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_severity.html.erb index 0162ea7fa98..0703dd90da9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_severity.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/_severity.html.erb @@ -2,7 +2,7 @@ <tr class="<%= css -%> <%= 'selected' if selected -%>"> <td><%= image_tag "priority/#{severity}.png" %></td> <td> - <%= link_to message("severity.#{severity}"), {:controller => 'drilldown', :action => 'violations', :id => @project.id, :severity => (selected ? nil : severity), :period => @period} %> + <%= link_to message("severity.#{severity}"), {:controller => 'drilldown', :action => 'violations', :id => @resource.id, :severity => (selected ? nil : severity), :period => @period} %> </td> <td style="padding-left: 10px;" align="right" nowrap> <%= @period ? format_variation(measure, :index => @period, :style => 'light') : format_measure(measure) -%> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb index dc1b9b21f28..a8ec9cb8a0c 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/filters/new.html.erb @@ -49,14 +49,6 @@ table#columns td { <td> <% qualifiers=(@filter.criterion('qualifier') ? @filter.criterion('qualifier').text_values : []) %> - <% if controller.java_facade.hasPlugin('views') %> - <input type="checkbox" name="qualifiers[]" value="VW" <%= 'checked' if qualifiers.include?('VW') -%> id="q-VW"></input> <label for="q-VW"><%= message('qualifiers.VW') -%></label> - <span class="spacer"> </span> - - <input type="checkbox" name="qualifiers[]" value="SVW" <%= 'checked' if qualifiers.include?('SVW') -%> id="q-SVW"></input> <label for="q-SVW"><%= message('qualifiers.SVW') -%></label> - <span class="spacer"> </span> - <% end %> - <input type="checkbox" name="qualifiers[]" value="TRK" <%= 'checked' if qualifiers.include?('TRK') -%> id="q-TRK"></input> <label for="q-TRK"><%= message('qualifiers.TRK') -%></label> <span class="spacer"> </span> @@ -72,7 +64,7 @@ table#columns td { <input type="checkbox" name="qualifiers[]" value="UTS" <%= 'checked' if qualifiers.include?('UTS') -%> id="q-UTS"></input> <label for="q-UTS"><%= message('qualifiers.UTS') -%></label> <span class="spacer"> </span> - <% for desc in controller.java_facade.getResourceDefinitionsForFilter() + <% for desc in controller.java_facade.getResourceTypesForFilter() qualifier = desc.getQualifier() %> <input type="checkbox" name="qualifiers[]" value="<%= qualifier -%>" <%= 'checked' if qualifiers.include?(qualifier) -%> id="q-<%= qualifier -%>"></input> <label for="q-<%= qualifier -%>"><%= message("qualifiers.#{qualifier}") -%></label> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/timemachine/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/timemachine/index.html.erb index 5aada6364a2..97a323568ae 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/timemachine/index.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/timemachine/index.html.erb @@ -56,7 +56,7 @@ } function refreshTimeMachineChart(jumpToChart) { - var url="<%= url_for :controller => 'charts', :action => 'trends', :id => @project.id, :locale => I18n.locale -%>&sids=" + selectedSnapshots + "&metrics=" + collectSelectedMetrics() + "&format=png&ts=" + (new Date()).getTime(); + var url="<%= url_for :controller => 'charts', :action => 'trends', :id => @resource.id, :locale => I18n.locale -%>&sids=" + selectedSnapshots + "&metrics=" + collectSelectedMetrics() + "&format=png&ts=" + (new Date()).getTime(); $('timemachine_chart').src=url; if (jumpToChart) { @@ -70,11 +70,11 @@ </center> <br/><br/> -<% form_for( :compare, :html => { :id => 'timemachine_form', :method => 'get' }, :url => { :controller => 'timemachine', :action => 'index', :id => @project.id}) do |form| %> +<% form_for( :compare, :html => { :id => 'timemachine_form', :method => 'get' }, :url => { :controller => 'timemachine', :action => 'index', :id => @resource.id}) do |form| %> <input type="hidden" name="sid" id="sid" value=""/> <input type="hidden" name="metrics" id="timemachine_form_metrics" value=""/> <% end %> -<% form_for( :compare, :html => { :id => 'chart_defaults_form', :method => 'post' }, :url => { :controller => 'timemachine', :action => 'set_default_chart_metrics', :id => @project.id}) do |form| %> +<% form_for( :compare, :html => { :id => 'chart_defaults_form', :method => 'post' }, :url => { :controller => 'timemachine', :action => 'set_default_chart_metrics', :id => @resource.id}) do |form| %> <input type="hidden" name="metrics" id="chart_defaults_form_metrics" value=""/> <% end %> <table id="timemachine_matrix" class="matrix"> @@ -87,7 +87,7 @@ <div id="calContainer"> </div> </div><br/> <% - selectable_events = @project.events_with_snapshot.select{|event| !(@sids.include?(event.snapshot_id))} + selectable_events = @resource.events_with_snapshot.select{|event| !(@sids.include?(event.snapshot_id))} unless selectable_events.empty? %> <%= message('time_machine.show_event') -%> @@ -201,7 +201,7 @@ <script type="text/javascript"> var snapshots = new Hash(); - <% @project.processed_snapshots.each do |snapshot| + <% @resource.processed_snapshots.each do |snapshot| date = snapshot.created_at js_date = date.year.to_s + "," + (date.month - 1).to_s + "," + date.day.to_s %> snapshots.set(<%= snapshot.id.to_s %>,new Date(<%= js_date %>)); diff --git a/sonar-server/src/main/webapp/WEB-INF/lib/resourceable.rb b/sonar-server/src/main/webapp/WEB-INF/lib/resourceable.rb index c232c7fc8dd..18daee64fe8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/lib/resourceable.rb +++ b/sonar-server/src/main/webapp/WEB-INF/lib/resourceable.rb @@ -37,16 +37,16 @@ module Resourceable QUALIFIER_LIB='LIB' QUALIFIERS=[QUALIFIER_VIEW, QUALIFIER_SUBVIEW, QUALIFIER_PROJECT, QUALIFIER_MODULE, QUALIFIER_DIRECTORY, QUALIFIER_PACKAGE, QUALIFIER_FILE, QUALIFIER_CLASS, QUALIFIER_UNIT_TEST_CLASS, QUALIFIER_LIB] QUALIFIER_NAMES={ - QUALIFIER_VIEW => 'view', - QUALIFIER_SUBVIEW => 'sub_view', - QUALIFIER_PROJECT => 'project', - QUALIFIER_MODULE => 'sub_project', - QUALIFIER_DIRECTORY => 'directory', - QUALIFIER_PACKAGE => 'package', - QUALIFIER_FILE => 'file', - QUALIFIER_CLASS => 'class', - QUALIFIER_UNIT_TEST_CLASS => 'unit_test', - QUALIFIER_LIB => 'library' + QUALIFIER_VIEW => 'view', + QUALIFIER_SUBVIEW => 'sub_view', + QUALIFIER_PROJECT => 'project', + QUALIFIER_MODULE => 'sub_project', + QUALIFIER_DIRECTORY => 'directory', + QUALIFIER_PACKAGE => 'package', + QUALIFIER_FILE => 'file', + QUALIFIER_CLASS => 'class', + QUALIFIER_UNIT_TEST_CLASS => 'unit_test', + QUALIFIER_LIB => 'library' } def set? @@ -90,18 +90,32 @@ module Resourceable end def source_code? - java_definition.hasSourceCode() + java_resource_type.hasSourceCode() end def display_dashboard? !source_code? end - def java_definition - @java_definition ||= - begin - Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceDefinition(qualifier) - end + def leaves_qualifiers + @leaves_qualifiers ||= + begin + Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceLeavesQualifiers(qualifier) + end + end + + def children_qualifiers + @children_qualifiers ||= + begin + Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceChildrenQualifiers(qualifier) + end + end + + def java_resource_type + @java_resource_type ||= + begin + Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceType(qualifier) + end end def self.qualifier_name(qualifier) diff --git a/sonar-server/src/test/java/org/sonar/server/ui/ResourceDefinitionRepositoryTest.java b/sonar-server/src/test/java/org/sonar/server/ui/ResourceDefinitionRepositoryTest.java deleted file mode 100644 index d514fb15ede..00000000000 --- a/sonar-server/src/test/java/org/sonar/server/ui/ResourceDefinitionRepositoryTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Sonar is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.server.ui; - -import org.junit.Test; -import org.sonar.api.resources.ResourceDefinition; - -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; - -public class ResourceDefinitionRepositoryTest { - - @Test - public void test() { - ResourceDefinition def1 = ResourceDefinition.builder("1").build(); - ResourceDefinition def2 = ResourceDefinition.builder("2").availableForFilters().build(); - ResourceDefinitionRepository repository = new ResourceDefinitionRepository(new ResourceDefinition[] {def1, def2}); - assertThat(repository.getAll(), hasItems(def1, def2)); - assertThat(repository.getForFilter(), hasItem(def2)); - assertThat(repository.get("1"), is(def1)); - assertThat(repository.get("unknown"), notNullValue()); - } - -} |