aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-07-28 18:47:31 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-08-06 14:20:48 +0200
commite8ef04be6f224cd6f16757e07bb2778bbb165671 (patch)
tree135a1695f47b4cd73188d82d46f75ab4bd15ec21 /server
parent5500b11848b73bfdfa4163aab4e3ed4d3aa68396 (diff)
downloadsonarqube-e8ef04be6f224cd6f16757e07bb2778bbb165671.tar.gz
sonarqube-e8ef04be6f224cd6f16757e07bb2778bbb165671.zip
SONAR-6749 add sonar-views-bridge module and start/stop Views from SQ
Diffstat (limited to 'server')
-rw-r--r--server/pom.xml1
-rw-r--r--server/sonar-server/pom.xml4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/view/bridge/ViewsBootstrap.java56
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/view/bridge/ViewsStopper.java56
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/ViewsIntegrationTest.java106
-rw-r--r--server/sonar-views-bridge/pom.xml54
-rw-r--r--server/sonar-views-bridge/src/main/java/org/sonar/server/views/ViewsBridge.java51
9 files changed, 335 insertions, 1 deletions
diff --git a/server/pom.xml b/server/pom.xml
index e7b1d8c88f0..e1fafe5fa9c 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -14,6 +14,7 @@
<module>sonar-process</module>
<module>sonar-process-monitor</module>
<module>sonar-search</module>
+ <module>sonar-views-bridge</module>
<module>sonar-server</module>
<module>sonar-web</module>
<module>sonar-server-benchmarks</module>
diff --git a/server/sonar-server/pom.xml b/server/sonar-server/pom.xml
index 5caf02b187b..b83c1d783da 100644
--- a/server/sonar-server/pom.xml
+++ b/server/sonar-server/pom.xml
@@ -183,6 +183,10 @@
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-views-bridge</artifactId>
+ </dependency>
<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
index efed066e65e..534edeffa91 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
@@ -311,6 +311,7 @@ import org.sonar.server.user.ws.UserPropertiesWs;
import org.sonar.server.user.ws.UsersWs;
import org.sonar.server.usergroups.ws.UserGroupsModule;
import org.sonar.server.util.TypeValidationModule;
+import org.sonar.server.view.bridge.ViewsStopper;
import org.sonar.server.view.index.ViewIndex;
import org.sonar.server.view.index.ViewIndexDefinition;
import org.sonar.server.view.index.ViewIndexer;
@@ -724,6 +725,9 @@ public class PlatformLevel4 extends PlatformLevel {
ProjectSettingsFactory.class,
IndexPurgeListener.class,
+ // Views plugin
+ ViewsStopper.class,
+
// UI
GlobalNavigationAction.class,
SettingsNavigationAction.class,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
index 80141a36266..f76e269d59e 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelStartup.java
@@ -39,6 +39,7 @@ import org.sonar.server.startup.RenameDeprecatedPropertyKeys;
import org.sonar.server.startup.RenameIssueWidgets;
import org.sonar.server.user.DoPrivileged;
import org.sonar.server.user.ThreadLocalUserSession;
+import org.sonar.server.view.bridge.ViewsBootstrap;
public class PlatformLevelStartup extends PlatformLevel {
public PlatformLevelStartup(PlatformLevel parent) {
@@ -65,7 +66,8 @@ public class PlatformLevelStartup extends PlatformLevel {
ReportQueueCleaner.class,
RegisterIssueFilters.class,
RenameIssueWidgets.class,
- ServerLifecycleNotifier.class);
+ ServerLifecycleNotifier.class,
+ ViewsBootstrap.class);
}
@Override
diff --git a/server/sonar-server/src/main/java/org/sonar/server/view/bridge/ViewsBootstrap.java b/server/sonar-server/src/main/java/org/sonar/server/view/bridge/ViewsBootstrap.java
new file mode 100644
index 00000000000..691515905fd
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/view/bridge/ViewsBootstrap.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.view.bridge;
+
+import org.picocontainer.Startable;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.api.utils.log.Profiler;
+import org.sonar.core.platform.ComponentContainer;
+import org.sonar.server.views.ViewsBridge;
+
+/**
+ * Startup task to responsible to bootstrap the Views plugin when it is installed.
+ */
+public class ViewsBootstrap implements Startable {
+ private static final Logger LOGGER = Loggers.get(ViewsBootstrap.class);
+
+ private final ComponentContainer componentContainer;
+
+ public ViewsBootstrap(ComponentContainer componentContainer) {
+ this.componentContainer = componentContainer;
+ }
+
+ @Override
+ public void start() {
+ ViewsBridge viewsBridge = componentContainer.getComponentByType(ViewsBridge.class);
+ if (viewsBridge != null) {
+ Profiler profiler = Profiler.create(LOGGER).startInfo("Bootstrapping views");
+ viewsBridge.startViews(componentContainer);
+ profiler.stopInfo();
+ }
+ }
+
+ @Override
+ public void stop() {
+ // this class is stopped right after it has been started as an element of PlatformLevelStartup
+ // stopping Views is handled by ViewsStopper
+ }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/view/bridge/ViewsStopper.java b/server/sonar-server/src/main/java/org/sonar/server/view/bridge/ViewsStopper.java
new file mode 100644
index 00000000000..f82d78d0d34
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/view/bridge/ViewsStopper.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.view.bridge;
+
+import org.picocontainer.Startable;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.api.utils.log.Profiler;
+import org.sonar.core.platform.ComponentContainer;
+import org.sonar.server.views.ViewsBridge;
+
+/**
+ * As an component of PlatformLevel4, this class is responsible for notifying shutdown to the Views plugin when its
+ * installed.
+ */
+public class ViewsStopper implements Startable {
+ private static final Logger LOGGER = Loggers.get(ViewsStopper.class);
+
+ private final ComponentContainer platformContainer;
+
+ public ViewsStopper(ComponentContainer platformContainer) {
+ this.platformContainer = platformContainer;
+ }
+
+ @Override
+ public void start() {
+ // nothing to do, Views plugins is started by ViewsBootstrap
+ }
+
+ @Override
+ public void stop() {
+ ViewsBridge viewsBridge = platformContainer.getComponentByType(ViewsBridge.class);
+ if (viewsBridge != null) {
+ Profiler profiler = Profiler.create(LOGGER).startInfo("Stopping views");
+ viewsBridge.stopViews();
+ profiler.stopInfo();
+ }
+ }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ViewsIntegrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ViewsIntegrationTest.java
new file mode 100644
index 00000000000..f1eb44a33ff
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ViewsIntegrationTest.java
@@ -0,0 +1,106 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform;
+
+import org.junit.After;
+import org.junit.Test;
+import org.sonar.core.platform.ComponentContainer;
+import org.sonar.server.tester.ServerTester;
+import org.sonar.server.views.ViewsBridge;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ViewsIntegrationTest {
+ private final ViewsBridgeSimulator viewsBridgeSimulator = new ViewsBridgeSimulator();
+
+ private ServerTester serverTester = new ServerTester();
+
+ @After
+ public void tearDown() throws Exception {
+ serverTester.stop();
+ }
+
+ @Test
+ public void verify_no_interaction_when_not_added_to_the_server() {
+ serverTester.start();
+
+ assertThat(viewsBridgeSimulator.isBootstrapCalled()).isFalse();
+ assertThat(viewsBridgeSimulator.getStopCalls()).isEqualTo(0);
+ assertThat(viewsBridgeSimulator.getUpdateViewsCalls()).isEqualTo(0);
+ }
+
+ @Test
+ public void verify_no_interaction_when_startup_tasks_are_disabled() {
+ serverTester.addComponents(viewsBridgeSimulator).start();
+
+ assertThat(viewsBridgeSimulator.isBootstrapCalled()).isFalse();
+ assertThat(viewsBridgeSimulator.getStopCalls()).isEqualTo(0);
+ assertThat(viewsBridgeSimulator.getUpdateViewsCalls()).isEqualTo(0);
+ }
+
+ @Test
+ public void verify_bootstrapped_only_with_startup_tasks_and_stopped_with_the_server() {
+ serverTester.addComponents(viewsBridgeSimulator).withStartupTasks().start();
+
+ assertThat(viewsBridgeSimulator.isBootstrapCalled()).isTrue();
+ assertThat(viewsBridgeSimulator.getStopCalls()).isEqualTo(0);
+ assertThat(viewsBridgeSimulator.getUpdateViewsCalls()).isEqualTo(0);
+
+ serverTester.stop();
+
+ assertThat(viewsBridgeSimulator.getStopCalls()).isEqualTo(1);
+ assertThat(viewsBridgeSimulator.getUpdateViewsCalls()).isEqualTo(0);
+ }
+
+ private static class ViewsBridgeSimulator implements ViewsBridge {
+ private boolean bootstrapCalled = false;
+ private int stopCalls = 0;
+ private int updateViewsCalls = 0;
+
+ @Override
+ public void startViews(ComponentContainer parent) {
+ checkArgument(!bootstrapCalled, "Bootstrap already called");
+ this.bootstrapCalled = true;
+ }
+
+ @Override
+ public void stopViews() {
+ this.stopCalls += 1;
+ }
+
+ @Override
+ public void updateViews() {
+ this.updateViewsCalls += 1;
+ }
+
+ public boolean isBootstrapCalled() {
+ return bootstrapCalled;
+ }
+
+ public int getStopCalls() {
+ return stopCalls;
+ }
+
+ public int getUpdateViewsCalls() {
+ return updateViewsCalls;
+ }
+ }
+}
diff --git a/server/sonar-views-bridge/pom.xml b/server/sonar-views-bridge/pom.xml
new file mode 100644
index 00000000000..e434b99fedd
--- /dev/null
+++ b/server/sonar-views-bridge/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>server</artifactId>
+ <version>5.2-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>sonar-views-bridge</artifactId>
+ <name>SonarQube :: Views Bridge</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-core</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipServerTests}</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>release</id>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+
+</project>
diff --git a/server/sonar-views-bridge/src/main/java/org/sonar/server/views/ViewsBridge.java b/server/sonar-views-bridge/src/main/java/org/sonar/server/views/ViewsBridge.java
new file mode 100644
index 00000000000..759468e2b98
--- /dev/null
+++ b/server/sonar-views-bridge/src/main/java/org/sonar/server/views/ViewsBridge.java
@@ -0,0 +1,51 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.views;
+
+import org.sonar.core.platform.ComponentContainer;
+
+/**
+ * Interface implemented by the Extension point exposed by the Views plugin that serves as the unique access point from
+ * the whole SQ instance into the Views plugin.
+ */
+public interface ViewsBridge {
+
+ /**
+ * Bootstraps the Views plugin.
+ *
+ * @param parent the parent ComponentContainer which provides Platform components for Views to use.
+ *
+ * @throws IllegalStateException if called more than once
+ */
+ void startViews(ComponentContainer parent);
+
+ /**
+ * This method is called when Platform is shutting down.
+ */
+ void stopViews();
+
+ /**
+ * Triggers an update of Views tree and measures.
+ *
+ * @throws IllegalStateException if {@link #startViews(ComponentContainer)} has not been called
+ */
+ void updateViews();
+
+}