diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-02-21 12:31:23 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-02-21 12:31:23 +0100 |
commit | 47f803be07c81dac2396f364deca15a2bb1fa7e8 (patch) | |
tree | 95a94de509eeb0def2aa3d17e03f88becb002f7d | |
parent | b27c50696631e0b9d4183a576e7c9783d5084ad7 (diff) | |
download | sonarqube-47f803be07c81dac2396f364deca15a2bb1fa7e8.tar.gz sonarqube-47f803be07c81dac2396f364deca15a2bb1fa7e8.zip |
Add ResourceDefinition#hasSourceCode
13 files changed, 105 insertions, 37 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/resources/DefaultResources.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/resources/DefaultResources.java index ab954783c3e..e2ae90b40bd 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/resources/DefaultResources.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/resources/DefaultResources.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.core.resources; +import org.sonar.api.BatchExtension; import org.sonar.api.ExtensionProvider; import org.sonar.api.ServerExtension; import org.sonar.api.resources.Qualifiers; @@ -27,7 +28,7 @@ import org.sonar.api.resources.ResourceDefinition; import java.util.Arrays; import java.util.List; -public class DefaultResources extends ExtensionProvider implements ServerExtension { +public class DefaultResources extends ExtensionProvider implements BatchExtension, ServerExtension { @Override public List<ResourceDefinition> provide() { @@ -38,9 +39,9 @@ public class DefaultResources extends ExtensionProvider implements ServerExtensi ResourceDefinition.builder(Qualifiers.MODULE).build(), ResourceDefinition.builder(Qualifiers.DIRECTORY).build(), ResourceDefinition.builder(Qualifiers.PACKAGE).build(), - ResourceDefinition.builder(Qualifiers.FILE).build(), - ResourceDefinition.builder(Qualifiers.CLASS).build(), - ResourceDefinition.builder(Qualifiers.UNIT_TEST_FILE).build(), + ResourceDefinition.builder(Qualifiers.FILE).hasSourceCode().build(), + ResourceDefinition.builder(Qualifiers.CLASS).hasSourceCode().build(), + ResourceDefinition.builder(Qualifiers.UNIT_TEST_FILE).hasSourceCode().build(), ResourceDefinition.builder(Qualifiers.LIBRARY).build()); } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/resources/DefaultResourcesTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/resources/DefaultResourcesTest.java new file mode 100644 index 00000000000..3120c17d488 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/resources/DefaultResourcesTest.java @@ -0,0 +1,36 @@ +/* + * 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.plugins.core.resources; + +import org.junit.Test; +import org.sonar.api.resources.ResourceDefinition; + +import java.util.List; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class DefaultResourcesTest { + @Test + public void provide() { + List<ResourceDefinition> defs = new DefaultResources().provide(); + assertThat(defs.isEmpty(), is(false)); + } +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceDefinition.java index 09a057373cc..a3d89ce7e25 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceDefinition.java @@ -22,18 +22,22 @@ package org.sonar.api.resources; import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import com.google.common.base.Strings; +import org.sonar.api.BatchExtension; import org.sonar.api.ServerExtension; /** + * Experimental extension to declare types of resources. + * * @since 2.14 */ @Beta -public final class ResourceDefinition implements ServerExtension { +public final class ResourceDefinition implements BatchExtension, ServerExtension { public static class Builder { private String qualifier; private String iconPath; private boolean availableForFilters = false; + private boolean hasSourceCode = false; public Builder(String qualifier) { this.qualifier = qualifier; @@ -52,11 +56,16 @@ public final class ResourceDefinition implements ServerExtension { return this; } + public Builder hasSourceCode() { + this.hasSourceCode = true; + return this; + } + public ResourceDefinition build() { if (Strings.isNullOrEmpty(iconPath)) { iconPath = "/images/q/" + qualifier + ".png"; } - return new ResourceDefinition(qualifier, iconPath, availableForFilters); + return new ResourceDefinition(this); } } @@ -68,12 +77,14 @@ public final class ResourceDefinition implements ServerExtension { private final String qualifier; private final String iconPath; + private final boolean hasSourceCode; private final boolean availableForFilters; - private ResourceDefinition(String qualifier, String iconPath, boolean availableForFilters) { - this.qualifier = qualifier; - this.iconPath = iconPath; - this.availableForFilters = availableForFilters; + private ResourceDefinition(Builder builder) { + this.qualifier = builder.qualifier; + this.iconPath = builder.iconPath; + this.availableForFilters = builder.availableForFilters; + this.hasSourceCode = builder.hasSourceCode; } public String getQualifier() { @@ -88,4 +99,7 @@ public final class ResourceDefinition implements ServerExtension { return availableForFilters; } + public boolean hasSourceCode() { + return hasSourceCode; + } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceDefinitionTest.java index c18d59a7f58..1c86725afe4 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceDefinitionTest.java @@ -32,6 +32,7 @@ public class ResourceDefinitionTest { .build(); assertThat(def.getQualifier(), is("qualifier")); assertThat(def.getIconPath(), is("/images/q/qualifier.png")); + assertThat(def.hasSourceCode(), is(false)); } @Test 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 index 4ef8b9d62d0..8f79ca0b526 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/ResourceDefinitionRepository.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/ResourceDefinitionRepository.java @@ -19,17 +19,23 @@ */ 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; -public class ResourceDefinitionRepository implements ServerComponent { +/** + * @since 2.14 + */ +@Beta +public class ResourceDefinitionRepository implements BatchComponent, ServerComponent { private final Map<String, ResourceDefinition> descriptionsByQualifier; 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 1a084c21378..3bfbc684303 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 @@ -108,7 +108,7 @@ class Sonar::Treemap :tooltip => tooltip(resource, size_measure, color_measure), :color => html_color(color_measure), :rid => resource.switch_resource_or_self.id, - :browsable => resource.display_dashboard?) + :leaf => resource.source_code?) node.add_child(child) end end @@ -153,8 +153,8 @@ class Sonar::HtmlOutput < Treemap::HtmlOutput html += "background-color:#FFF;\">" html += "<div rid='#{node.rid}' id=\"tm-node-#{node.id}\" style='margin: 1px;background-color: #{node.color}; height: #{node.bounds.height-4}px; border: 1px solid #{node.color};' alt=\"#{node.tooltip}\" title=\"#{node.tooltip}\"" - if node.browsable - html += "b=1 " + if node.leaf + html += "l=1 " end if @details_at_depth==node.depth html += "onmouseover=\"this.style.borderColor='#444';\" onmouseout=\"this.style.borderColor='#{node.color}';\"" @@ -171,11 +171,11 @@ border: 1px solid #{node.color};' alt=\"#{node.tooltip}\" title=\"#{node.tooltip end def draw_label(node) - if node.browsable - "<a href='#{ApplicationController.root_context}/dashboard/index/#{node.rid}'>#{node_label(node)}</a>" - else + if node.leaf "<a onclick=\"window.open(this.href,'resource','height=800,width=900,scrollbars=1,resizable=1');return false;\" " + - "href=\"#{ApplicationController.root_context}/resource/index/#{node.rid}\">#{node_label(node)}</a>" + "href=\"#{ApplicationController.root_context}/resource/index/#{node.rid}\">#{node_label(node)}</a>" + else + "<a href='#{ApplicationController.root_context}/dashboard/index/#{node.rid}'>#{node_label(node)}</a>" end end end
\ No newline at end of file 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 0b2c1b1d556..5077905767d 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 @@ -47,7 +47,7 @@ </td> <td class="left" x="<%= u(snapshot.project.name) -%>"> <%= qualifier_icon(snapshot) %> - <% if snapshot.project.display_dashboard? %> + <% if snapshot.display_dashboard? %> <a href="<%= ApplicationController.root_context + "/dashboard/index/#{snapshot.project.id}" -%>"><%= snapshot.project.name -%></a> <% else %> <%= snapshot.project.name %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb index e6d9c4650e6..c3848b0c1ed 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/measures.html.erb @@ -63,13 +63,13 @@ %> <tr class="<%= clazz -%>"> <td nowrap> - <% - if !resource.display_dashboard? %> - <%= qualifier_icon(resource) -%> + <% unless resource.source_code? %> + <%= link_to(image_tag('zoom.png'), {:id => resource.id, :metric => @metric.id}, {:class => 'nolink'}) -%> + <% end %> + <%= qualifier_icon(resource) -%> + <% if resource.source_code? %> <a href="#" onclick="d(<%= resource.id -%>)" alt="<%= resource.name(true) -%>" title="<%= resource.name(true) -%>"><%= resource.name(false) -%></a> <% else %> - <%= link_to(image_tag('zoom.png'), {:id => resource.id, :metric => @metric.id}, {:class => 'nolink'}) -%> - <%= qualifier_icon(resource) -%> <%= link_to(resource.name, {:only_path => true, :overwrite_params => {:rids => (selected ? rids-[resource.id] : rids+[resource.id])}}) -%> <% end %> </td> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb index 8d300485af4..b79d399a1d1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/violations.html.erb @@ -140,12 +140,13 @@ %> <tr class="<%= clazz -%>"> <td nowrap> - <% if !resource.display_dashboard? %> - <%= qualifier_icon(resource) -%> + <% unless resource.source_code? %> + <%= link_to(image_tag('zoom.png'), {:id => resource.id}, {:class => 'nolink'}) %> + <% end %> + <%= qualifier_icon(resource) -%> + <% if resource.source_code? %> <a href="#" onclick="d(<%= resource.id -%>, '<%= @period_index -%>', '<%= @rule ? @rule.key : @severity -%>');" alt="<%= resource.name(true) -%>" title="<%= resource.name(true) -%>"><%= resource.name(false) %></a> <% else %> - <%= link_to(image_tag('zoom.png'), {:id => resource.id}, {:class => 'nolink'}) %> - <%= qualifier_icon(resource) %> <%= link_to(h(resource.name), {:only_path => true, :overwrite_params => {:rids => (selected ? rids-[resource.id] : rids+[resource.id])}}) -%> <% end %> </td> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb index f1e4d260c2c..0cd94a80fba 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_tabs.html.erb @@ -7,11 +7,14 @@ selected_project_id = params[:project].to_i if @resource.project && selected_project_id != @resource.project.id %> <div class="subtitle"> + <!-- vertical alignment with title --> + <img src="<%= ApplicationController.root_context -%>/images/e16.gif"> + <% if logged_in? %><img src="<%= ApplicationController.root_context -%>/images/e16.gif"><% end %> + <%= @resource.ancestor_projects.select{|p| p.id != selected_project_id}.reverse.map{|p| p.name(true)}.join(' / ') -%> </div> <% end %> - <% if logged_in? %><%= link_to_favourite(@resource) -%> - <% end %> + <% if logged_in? %><%= link_to_favourite(@resource) -%><% end %> <span class="h3"><%= qualifier_icon(@resource) -%> <%= @resource.name(true) -%></span> </div> <% end %> 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 6e44e392bae..c232c7fc8dd 100644 --- a/sonar-server/src/main/webapp/WEB-INF/lib/resourceable.rb +++ b/sonar-server/src/main/webapp/WEB-INF/lib/resourceable.rb @@ -89,12 +89,18 @@ module Resourceable qualifier==QUALIFIER_FILE end - NO_DASHBOARD_QUALIFIERS=[QUALIFIER_FILE, QUALIFIER_CLASS, QUALIFIER_UNIT_TEST_CLASS] + def source_code? + java_definition.hasSourceCode() + end def display_dashboard? - @display_dashboard ||= + !source_code? + end + + def java_definition + @java_definition ||= begin - !NO_DASHBOARD_QUALIFIERS.include?(qualifier) + Java::OrgSonarServerUi::JRubyFacade.getInstance().getResourceDefinition(qualifier) end end diff --git a/sonar-server/src/main/webapp/WEB-INF/lib/treemap/node.rb b/sonar-server/src/main/webapp/WEB-INF/lib/treemap/node.rb index 223288212d5..3fdfe001a0a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/lib/treemap/node.rb +++ b/sonar-server/src/main/webapp/WEB-INF/lib/treemap/node.rb @@ -37,7 +37,7 @@ module Treemap # # class Treemap::Node - attr_accessor :id, :label, :color, :size, :bounds, :parent, :tooltip, :url, :title, :rid, :browsable + attr_accessor :id, :label, :color, :size, :bounds, :parent, :tooltip, :url, :title, :rid, :leaf attr_reader :children # @@ -65,7 +65,7 @@ module Treemap @tooltip = opts[:tooltip] @children = [] @rid = opts[:rid] - @browsable = opts[:browsable] + @leaf = opts[:leaf] if(@id.nil?) make_id end diff --git a/sonar-server/src/main/webapp/javascripts/application.js b/sonar-server/src/main/webapp/javascripts/application.js index 6cfcf872ab0..75a5024e407 100644 --- a/sonar-server/src/main/webapp/javascripts/application.js +++ b/sonar-server/src/main/webapp/javascripts/application.js @@ -233,8 +233,8 @@ Treemap.prototype.handleClick = function (event) { var elt = event.findElement('div'); var rid = elt.readAttribute('rid'); - var browsable = elt.hasAttribute('b'); - if (browsable) { + var leaf = elt.hasAttribute('l'); + if (!leaf) { var label = elt.innerText || elt.textContent; var context = new TreemapContext('resource', rid, label); this.breadcrumb.push(context); |