aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-09-24 14:47:58 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-09-24 14:49:23 +0200
commit186c158abed49d4413673332cd1892e296eabe2e (patch)
treed1fe4aaa011d95d55043cc443c3c26ba39ddd504
parente07a31b513b2585981f041cd46149353ed024ba5 (diff)
downloadsonarqube-186c158abed49d4413673332cd1892e296eabe2e.tar.gz
sonarqube-186c158abed49d4413673332cd1892e296eabe2e.zip
SONAR-2376 Add an extension point to define a HTML banner
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/web/PageDecoration.java29
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java6
-rw-r--r--sonar-server/src/main/java/org/sonar/server/ui/PageDecorations.java46
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb3
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/layouts/application.html.erb11
-rw-r--r--sonar-server/src/test/java/org/sonar/server/ui/PageDecorationsTest.java46
6 files changed, 137 insertions, 4 deletions
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
index 00000000000..3c89d1aa238
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/PageDecoration.java
@@ -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 {
+
+}
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 5f369ba3454..3c39a3d7a89 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
@@ -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
index 00000000000..2c0dde37be2
--- /dev/null
+++ b/sonar-server/src/main/java/org/sonar/server/ui/PageDecorations.java
@@ -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;
+ }
+}
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
index 01afcdae95e..0bf5418a25b 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
@@ -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>
@@ -180,6 +181,7 @@
<% 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>
@@ -211,6 +213,7 @@
</div>
<% unless params[:hd]=='false' %>
+ <%= yield :footer %>
<div id="footer">
<% controller.java_facade.getWebFooters().each do |footer| %>
<% if footer.getHtml() %>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/application.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/application.html.erb
index 8e653187f5d..3c67adf30b2 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/application.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/application.html.erb
@@ -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
index 00000000000..48e602c2eaa
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/ui/PageDecorationsTest.java
@@ -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);
+ }
+}