]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4173 Add the possibility for a plugin to add a configuration page
authorJulien Lancelot <julien.lancelot@gmail.com>
Fri, 22 Mar 2013 14:19:43 +0000 (15:19 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Fri, 22 Mar 2013 14:19:43 +0000 (15:19 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/web/NavigationSection.java
sonar-server/src/main/webapp/WEB-INF/app/models/navigation.rb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_menu_resource_settings.html.erb
sonar-server/src/test/java/org/sonar/server/ui/ViewsTest.java

index 58dca1b105eff0b922848aa494d202e2efbc79ad..b065f7fd1b16e377b67fad643f7246feeb853175 100644 (file)
@@ -37,6 +37,8 @@ public @interface NavigationSection {
   String RESOURCE = "resource";
   String RESOURCE_TAB = "resource_tab";
   String CONFIGURATION = "configuration";
+  // @since 3.6
+  String PROJECT_CONFIGURATION = "project_configuration";
 
   String[] value() default { HOME };
 
index 94e8f3fe4f228313b0e0ac5d55e53b4637a31151..cea364c906cf0c242acdeaf3cf8e77ceca9c0691 100644 (file)
@@ -22,6 +22,7 @@ class Navigation
   SECTION_HOME = 'home'
   SECTION_RESOURCE = 'resource'
   SECTION_CONFIGURATION = 'configuration'
+  SECTION_PROJECT_CONFIGURATION = 'project_configuration'
   SECTION_SESSION = 'session'
 
 end
\ No newline at end of file
index abf7434fe1928e2158a913704465cd11098afe84..653596c0c319a36e1277758a097de9c331207fa5 100644 (file)
       <% if controller.java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'deletable') %>
         <li><a href="<%= ApplicationController.root_context -%>/project/deletion/<%= @project.id -%>"><%= message('resource_deletion.page', :params => message('qualifier.' + @project.qualifier)) -%></a></li>
       <% end %>
+      <% controller.java_facade.getPages(Navigation::SECTION_PROJECT_CONFIGURATION, @project.scope, @project.qualifier, @project.language, nil).each do |page|
+        page_url = (page.isController() ? "#{page.getId()}?id=#{@project.id}" : "/plugins/project_configuration/#{@project.id}?page=#{page.getId()}")
+      %>
+        <li><a href="<%= ApplicationController.root_context -%><%= page_url -%>"><%= message(page.getId() + '.page', :default => page.getTitle()) -%></a></li>
+      <% end %>
     </ul>
   </div>
   
index 2f509e1ffcaa7528f000974584df70b43a25e3cc..d682ea6dc1f654637983c4b56e4695652ac82372 100644 (file)
  */
 package org.sonar.server.ui;
 
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.List;
-
 import org.junit.Test;
 import org.sonar.api.resources.Java;
 import org.sonar.api.resources.Qualifiers;
@@ -36,6 +28,12 @@ import org.sonar.api.web.Page;
 import org.sonar.api.web.View;
 import org.sonar.api.web.Widget;
 
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 public class ViewsTest {
 
   private static FakeResourceViewer FAKE_TAB = new FakeResourceViewer();
@@ -44,127 +42,129 @@ public class ViewsTest {
   private static final View[] VIEWS = {FAKE_PAGE, FAKE_TAB, FAKE_WIDGET};
 
   @Test
-  public void getPageById() {
+  public void should_get_page_by_id() {
     final Views views = new Views(VIEWS);
-    assertThat(views.getPage("fake-page").getTarget(), is(FakePage.class));
-    assertThat(views.getPage("fake-widget"), nullValue());
-    assertThat(views.getPage("foo"), nullValue());
-    assertThat(views.getPage("fake-resourceviewer").getTarget(), is(FakeResourceViewer.class));
+    assertThat(views.getPage("fake-page").getTarget().getClass()).isEqualTo(FakePage.class);
+    assertThat(views.getPage("fake-widget")).isNull();
+    assertThat(views.getPage("foo")).isNull();
+    assertThat(views.getPage("fake-resourceviewer").getTarget().getClass()).isEqualTo(FakeResourceViewer.class);
   }
 
   @Test
-  public void getPagesBySection() {
+  public void should_get_pages_by_section() {
     final Views views = new Views(VIEWS);
 
     List<ViewProxy<Page>> pages = views.getPages(NavigationSection.RESOURCE);
-    assertThat(pages.size(), is(1));
-    assertThat(pages.get(0).getTarget(), is(FakePage.class));
+    assertThat(pages.size()).isEqualTo(1);
+    assertThat(pages.get(0).getTarget().getClass()).isEqualTo(FakePage.class);
 
     pages = views.getPages(NavigationSection.CONFIGURATION);
-    assertThat(pages.size(), is(0));
+    assertThat(pages.size()).isEqualTo(0);
   }
 
   @Test
-  public void getResourceViewers() {
+  public void should_get_resource_viewers() {
     final Views views = new Views(VIEWS);
     List resourceViewers = views.getPages(NavigationSection.RESOURCE_TAB);
-    assertThat(resourceViewers.size(), is(1 + 4 /* default */));
-    assertThat(resourceViewers.contains(new ViewProxy<FakeResourceViewer>(FAKE_TAB)), is(true));
+    assertThat(resourceViewers.size()).isEqualTo(1 + 4 /* default */);
+    assertThat(resourceViewers.contains(new ViewProxy<FakeResourceViewer>(FAKE_TAB))).isEqualTo(true);
   }
 
   @Test
-  public void getWidgets() {
+  public void should_get_widgets() {
     final Views views = new Views(VIEWS);
     List<ViewProxy<Widget>> widgets = views.getWidgets(null, null, null, null);
-    assertThat(widgets.size(), is(1));
-    assertThat(widgets.get(0).getTarget(), is(FakeWidget.class));
+    assertThat(widgets.size()).isEqualTo(1);
+    assertThat(widgets.get(0).getTarget().getClass()).isEqualTo(FakeWidget.class);
   }
 
   @Test
-  public void sortViewsByTitle() {
+  public void should_sort_views_by_title() {
     final Views views = new Views(new View[] {new FakeWidget("ccc", "ccc"), new FakeWidget("aaa", "aaa"), new FakeWidget("bbb", "bbb")});
     List<ViewProxy<Widget>> widgets = views.getWidgets(null, null, null, null);
-    assertThat(widgets.size(), is(3));
-    assertThat(widgets.get(0).getId(), is("aaa"));
-    assertThat(widgets.get(1).getId(), is("bbb"));
-    assertThat(widgets.get(2).getId(), is("ccc"));
+    assertThat(widgets.size()).isEqualTo(3);
+    assertThat(widgets.get(0).getId()).isEqualTo("aaa");
+    assertThat(widgets.get(1).getId()).isEqualTo("bbb");
+    assertThat(widgets.get(2).getId()).isEqualTo("ccc");
   }
 
   @Test
-  public void prefixTitleByNumberToDisplayFirst() {
+  public void should_prefix_title_by_number_to_display_first() {
     final Views views = new Views(new View[] {new FakeWidget("other", "Other"), new FakeWidget("1id", "1widget"), new FakeWidget("2id", "2widget")});
     List<ViewProxy<Widget>> widgets = views.getWidgets(null, null, null, null);
-    assertThat(widgets.size(), is(3));
-    assertThat(widgets.get(0).getId(), is("1id"));
-    assertThat(widgets.get(1).getId(), is("2id"));
-    assertThat(widgets.get(2).getId(), is("other"));
+    assertThat(widgets.size()).isEqualTo(3);
+    assertThat(widgets.get(0).getId()).isEqualTo("1id");
+    assertThat(widgets.get(1).getId()).isEqualTo("2id");
+    assertThat(widgets.get(2).getId()).isEqualTo("other");
   }
 
   @Test
-  public void acceptNavigationSection() {
+  public void should_accept_navigation_section() {
     ViewProxy proxy = mock(ViewProxy.class);
     when(proxy.getSections()).thenReturn(new String[] {NavigationSection.RESOURCE});
     when(proxy.isWidget()).thenReturn(false);
 
-    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE), is(true));
-    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME), is(false));
-    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION), is(false));
-    assertThat(Views.acceptNavigationSection(proxy, null), is(true));
+    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE)).isEqualTo(true);
+    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME)).isEqualTo(false);
+    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION)).isEqualTo(false);
+    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.PROJECT_CONFIGURATION)).isEqualTo(false);
+    assertThat(Views.acceptNavigationSection(proxy, null)).isEqualTo(true);
   }
 
   @Test
-  public void acceptAvailableMeasures() {
+  public void should_accept_available_measures() {
     ViewProxy proxy = mock(ViewProxy.class);
     when(proxy.acceptsAvailableMeasures(new String[] {"lines"})).thenReturn(true);
     when(proxy.acceptsAvailableMeasures(new String[] {"ncloc"})).thenReturn(false);
 
-    assertThat(Views.acceptAvailableMeasures(proxy, null), is(true));
-    assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"lines"}), is(true));
-    assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"ncloc"}), is(false));
+    assertThat(Views.acceptAvailableMeasures(proxy, null)).isEqualTo(true);
+    assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"lines"})).isEqualTo(true);
+    assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"ncloc"})).isEqualTo(false);
 
-    assertThat(Views.accept(proxy, null, null, null, null, null), is(true));
-    assertThat(Views.accept(proxy, null, null, null, null, new String[] {"lines"}), is(true));
-    assertThat(Views.accept(proxy, null, null, null, null, new String[] {"ncloc"}), is(false));
+    assertThat(Views.accept(proxy, null, null, null, null, null)).isEqualTo(true);
+    assertThat(Views.accept(proxy, null, null, null, null, new String[] {"lines"})).isEqualTo(true);
+    assertThat(Views.accept(proxy, null, null, null, null, new String[] {"ncloc"})).isEqualTo(false);
   }
 
   @Test
-  public void doNotCheckNavigationSectionOnWidgets() {
+  public void should_not_check_navigation_section_on_widgets() {
     ViewProxy proxy = mock(ViewProxy.class);
     when(proxy.isWidget()).thenReturn(true);
 
-    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE), is(true));
-    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME), is(true));
-    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION), is(true));
-    assertThat(Views.acceptNavigationSection(proxy, null), is(true));
+    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE)).isEqualTo(true);
+    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME)).isEqualTo(true);
+    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION)).isEqualTo(true);
+    assertThat(Views.acceptNavigationSection(proxy, NavigationSection.PROJECT_CONFIGURATION)).isEqualTo(true);
+    assertThat(Views.acceptNavigationSection(proxy, null)).isEqualTo(true);
   }
 
   @Test
-  public void checkResourceLanguage() {
+  public void should_check_resource_language() {
     ViewProxy proxy = mock(ViewProxy.class);
-    assertThat(Views.acceptResourceLanguage(proxy, Java.KEY), is(true));
+    assertThat(Views.acceptResourceLanguage(proxy, Java.KEY)).isEqualTo(true);
 
     when(proxy.getResourceLanguages()).thenReturn(new String[] {"foo"});
-    assertThat(Views.acceptResourceLanguage(proxy, Java.KEY), is(false));
-    assertThat(Views.acceptResourceLanguage(proxy, "foo"), is(true));
+    assertThat(Views.acceptResourceLanguage(proxy, Java.KEY)).isEqualTo(false);
+    assertThat(Views.acceptResourceLanguage(proxy, "foo")).isEqualTo(true);
   }
 
   @Test
-  public void checkResourceScope() {
+  public void should_check_resource_scope() {
     ViewProxy proxy = mock(ViewProxy.class);
-    assertThat(Views.acceptResourceScope(proxy, Scopes.FILE), is(true));
+    assertThat(Views.acceptResourceScope(proxy, Scopes.FILE)).isEqualTo(true);
 
     when(proxy.getResourceScopes()).thenReturn(new String[] {Scopes.PROJECT, Scopes.FILE});
-    assertThat(Views.acceptResourceScope(proxy, Scopes.FILE), is(true));
-    assertThat(Views.acceptResourceScope(proxy, Scopes.DIRECTORY), is(false));
+    assertThat(Views.acceptResourceScope(proxy, Scopes.FILE)).isEqualTo(true);
+    assertThat(Views.acceptResourceScope(proxy, Scopes.DIRECTORY)).isEqualTo(false);
   }
 
   @Test
-  public void checkResourceQualifier() {
+  public void should_check_resource_qualifier() {
     ViewProxy proxy = mock(ViewProxy.class);
-    assertThat(Views.acceptResourceQualifier(proxy, Scopes.FILE), is(true));
+    assertThat(Views.acceptResourceQualifier(proxy, Scopes.FILE)).isEqualTo(true);
 
     when(proxy.getResourceQualifiers()).thenReturn(new String[] {Qualifiers.CLASS, Qualifiers.FILE});
-    assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.FILE), is(true));
-    assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.PACKAGE), is(false));
+    assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.FILE)).isEqualTo(true);
+    assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.PACKAGE)).isEqualTo(false);
   }
 }