]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2376 Add an extension point to define a HTML banner
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 24 Sep 2012 12:47:58 +0000 (14:47 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 24 Sep 2012 12:49:23 +0000 (14:49 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/web/PageDecoration.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/java/org/sonar/server/ui/PageDecorations.java [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/application.html.erb
sonar-server/src/test/java/org/sonar/server/ui/PageDecorationsTest.java [new file with mode: 0644]

diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/PageDecoration.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/PageDecoration.java
new file mode 100644 (file)
index 0000000..3c89d1a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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.api.web;
+
+import org.sonar.api.ServerExtension;
+
+/**
+ * @since 3.3
+ */
+public abstract class PageDecoration extends AbstractRubyTemplate implements ServerExtension {
+
+}
index 5f369ba3454ee3798687406d673c6e52316d58ee..3c39a3d7a8947d142c5ede724e529f317fd9f088 100644 (file)
@@ -69,10 +69,7 @@ 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.CodeColorizers;
-import org.sonar.server.ui.JRubyI18n;
-import org.sonar.server.ui.SecurityRealmFactory;
-import org.sonar.server.ui.Views;
+import org.sonar.server.ui.*;
 
 import javax.servlet.ServletContext;
 
@@ -221,6 +218,7 @@ public final class Platform {
     servicesContainer.addSingleton(ResourceTypes.class);
     servicesContainer.addSingleton(NewUserNotifier.class);
     servicesContainer.addSingleton(SettingsChangeNotifier.class);
+    servicesContainer.addSingleton(PageDecorations.class);
 
     // Notifications
     servicesContainer.addSingleton(EmailSettings.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/ui/PageDecorations.java b/sonar-server/src/main/java/org/sonar/server/ui/PageDecorations.java
new file mode 100644 (file)
index 0000000..2c0dde3
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.sonar.api.ServerComponent;
+import org.sonar.api.web.PageDecoration;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @since 3.3
+ */
+public final class PageDecorations implements ServerComponent {
+
+  private final PageDecoration[] decorations;
+
+  public PageDecorations(List<PageDecoration> decorations) {
+    this.decorations = decorations.toArray(new PageDecoration[decorations.size()]);
+  }
+
+  public PageDecorations() {
+    this(Collections.<PageDecoration>emptyList());
+  }
+
+  public PageDecoration[] get() {
+    return decorations;
+  }
+}
index 01afcdae95eab904cd74f96ac8bd9dfec66ae7e7..0bf5418a25bfc1326c1b20a5d2a7b155a0610f8f 100644 (file)
@@ -7,6 +7,7 @@
    period_param = "period=#{params[:period]}" if params[:period]
 %>
 <div id="container">
+<%= yield :header -%>
 <div id="hd">
   <div id="nav-left">
     <ul>
 
         <% end %>
       </ul>
+      <%= yield :sidebar %>
       <div id="logo">
         <center><a href="http://www.sonarsource.org/" target="SonarSource"><%= image_tag('sonar.png', :alt => message('layout.sonar.slogan'), :class => 'png') -%></a></center>
       </div>
 </div>
 
 <% unless params[:hd]=='false' %>
+  <%= yield :footer %>
   <div id="footer">
     <% controller.java_facade.getWebFooters().each do |footer| %>
       <% if footer.getHtml() %>
index 8e653187f5d4d9c7537a18f37d228a5723240640..3c67adf30b2e4bb81e79369821c8cf723f34524a 100644 (file)
@@ -1,3 +1,14 @@
+<%
+   controller.java_facade.getCoreComponentByClassname('org.sonar.server.ui.PageDecorations').get().each do |decoration|
+     begin
+%>
+    <%= render :inline => decoration.getTemplate() -%>
+  <%
+     rescue => error
+       logger.error(error)
+     end
+   end
+  %>
 <%= render :partial => 'layouts/head' unless params[:hd]=='false' %>
 <% if params[:layout]=='false' %>
   <%= render :partial => 'layouts/nolayout' %>
diff --git a/sonar-server/src/test/java/org/sonar/server/ui/PageDecorationsTest.java b/sonar-server/src/test/java/org/sonar/server/ui/PageDecorationsTest.java
new file mode 100644 (file)
index 0000000..48e602c
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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.web.PageDecoration;
+
+import java.util.Arrays;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class PageDecorationsTest {
+
+  @Test
+  public void should_not_fail_if_no_decorations() {
+    assertThat(new PageDecorations().get()).isEmpty();
+  }
+
+  @Test
+  public void should_register_decorations() {
+    PageDecoration deco1 = mock(PageDecoration.class);
+    PageDecoration deco2 = mock(PageDecoration.class);
+
+    PageDecorations decorations = new PageDecorations(Arrays.asList(deco1, deco2));
+
+    assertThat(decorations.get()).hasSize(2);
+  }
+}