]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7027 add DevCockpitBridge and start/stop Dev Cockpit plugin 638/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 18 Nov 2015 10:28:19 +0000 (11:28 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 18 Nov 2015 13:37:33 +0000 (14:37 +0100)
add Maven module sonar-dev-cockpit-bridge

12 files changed:
pom.xml
server/pom.xml
server/sonar-dev-cockpit-bridge/pom.xml [new file with mode: 0644]
server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/DevCockpitBridge.java [new file with mode: 0644]
server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/package-info.java [new file with mode: 0644]
server/sonar-server/pom.xml
server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrap.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitStopper.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/package-info.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrapTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitStopperTest.java [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 4d56d660c9644967aea476f74d48bc74c2697219..27ed5824de50fe1d94e909a30d0c7f9edfb0e971 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <artifactId>sonar-views-bridge</artifactId>
         <version>${project.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.sonarsource.sonarqube</groupId>
+        <artifactId>sonar-dev-cockpit-bridge</artifactId>
+        <version>${project.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.sonarsource.java</groupId>
         <artifactId>sonar-java-plugin</artifactId>
index 356ea3b9d88998a2d70d1e87268f086ae298adb1..85822ac1d27d97b9c24e5f21aff38a4db37688b7 100644 (file)
@@ -14,8 +14,9 @@
     <module>sonar-process</module>
     <module>sonar-process-monitor</module>
     <module>sonar-search</module>
-    <module>sonar-views-bridge</module>
     <module>sonar-server</module>
+    <module>sonar-views-bridge</module>
+    <module>sonar-dev-cockpit-bridge</module>
     <module>sonar-web</module>
     <module>sonar-server-benchmarks</module>
   </modules>
diff --git a/server/sonar-dev-cockpit-bridge/pom.xml b/server/sonar-dev-cockpit-bridge/pom.xml
new file mode 100644 (file)
index 0000000..e63a98f
--- /dev/null
@@ -0,0 +1,58 @@
+<?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.sonarsource.sonarqube</groupId>
+    <artifactId>server</artifactId>
+    <version>5.3-SNAPSHOT</version>
+    <relativePath>..</relativePath>
+  </parent>
+  <artifactId>sonar-dev-cockpit-bridge</artifactId>
+  <name>SonarQube :: Developer Cockpit Bridge</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>sonar-plugin-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>sonar-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.code.findbugs</groupId>
+      <artifactId>jsr305</artifactId>
+      <scope>provided</scope>
+    </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-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/DevCockpitBridge.java b/server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/DevCockpitBridge.java
new file mode 100644 (file)
index 0000000..9b33069
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.devcockpit;
+
+import org.sonar.core.platform.ComponentContainer;
+
+/**
+ * Interface implemented by the Extension point exposed by the Developer Cockpit plugin that serves as the unique access
+ * point from the whole SQ instance into the Developer Cockpit plugin.
+ */
+public interface DevCockpitBridge {
+
+  /**
+   * Bootstraps the Developer Cockpit plugin.
+   *
+   * @param parent the parent ComponentContainer which provides Platform components for Developer Cockpit to use.
+   *
+   * @throws IllegalStateException if called more than once
+   */
+  void startDevCockpit(ComponentContainer parent);
+
+  /**
+   * This method is called when Platform is shutting down.
+   */
+  void stopDevCockpit();
+
+}
diff --git a/server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/package-info.java b/server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/package-info.java
new file mode 100644 (file)
index 0000000..1e92523
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.server.devcockpit;
+
+import javax.annotation.ParametersAreNonnullByDefault;
index 7fb49bddfb1ced038b1a3142ef4ce776fff6081a..b059b0ffe088e9fc356dbf9014cdbe14c8ae37da 100644 (file)
       <groupId>${project.groupId}</groupId>
       <artifactId>sonar-views-bridge</artifactId>
     </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>sonar-dev-cockpit-bridge</artifactId>
+    </dependency>
     <!-- unit tests -->
     <dependency>
       <groupId>${project.groupId}</groupId>
diff --git a/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrap.java b/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrap.java
new file mode 100644 (file)
index 0000000..0c87cd9
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.devcockpit.bridge;
+
+import org.sonar.api.platform.Server;
+import org.sonar.api.platform.ServerStartHandler;
+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.devcockpit.DevCockpitBridge;
+
+/**
+ * Startup task to responsible to bootstrap the Developer Cockpit plugin when it is installed.
+ */
+public class DevCockpitBootstrap implements ServerStartHandler {
+  private static final Logger LOGGER = Loggers.get(DevCockpitBootstrap.class);
+
+  private final ComponentContainer componentContainer;
+
+  public DevCockpitBootstrap(ComponentContainer componentContainer) {
+    this.componentContainer = componentContainer;
+  }
+
+  @Override
+  public void onServerStart(Server server) {
+    DevCockpitBridge bridge = componentContainer.getComponentByType(DevCockpitBridge.class);
+    if (bridge != null) {
+      Profiler profiler = Profiler.create(LOGGER).startInfo("Bootstrapping Developer Cockpit");
+      bridge.startDevCockpit(componentContainer);
+      profiler.stopInfo();
+    }
+  }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitStopper.java b/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitStopper.java
new file mode 100644 (file)
index 0000000..de97cad
--- /dev/null
@@ -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.devcockpit.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.devcockpit.DevCockpitBridge;
+
+/**
+ * As an component of PlatformLevel4, this class is responsible for notifying shutdown to the Developer Cockpit plugin when its
+ * installed.
+ */
+public class DevCockpitStopper implements Startable {
+  private static final Logger LOGGER = Loggers.get(DevCockpitStopper.class);
+
+  private final ComponentContainer platformContainer;
+
+  public DevCockpitStopper(ComponentContainer platformContainer) {
+    this.platformContainer = platformContainer;
+  }
+
+  @Override
+  public void start() {
+    // nothing to do, Views plugins is started by DevCockpitBootstrap
+  }
+
+  @Override
+  public void stop() {
+    DevCockpitBridge devCockpitBridge = platformContainer.getComponentByType(DevCockpitBridge.class);
+    if (devCockpitBridge != null) {
+      Profiler profiler = Profiler.create(LOGGER).startInfo("Stopping Developer Cockpit");
+      devCockpitBridge.stopDevCockpit();
+      profiler.stopInfo();
+    }
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/package-info.java
new file mode 100644 (file)
index 0000000..d5c1532
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.server.devcockpit.bridge;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
index 1d2349b3991039bc10ef6f34921258d0cb2a8d0f..9b6869750ee2b49a1808d92600410ed01692b2fb 100644 (file)
@@ -108,6 +108,8 @@ import org.sonar.server.debt.DebtModelPluginRepository;
 import org.sonar.server.debt.DebtModelService;
 import org.sonar.server.debt.DebtModelXMLExporter;
 import org.sonar.server.debt.DebtRulesXMLImporter;
+import org.sonar.server.devcockpit.bridge.DevCockpitBootstrap;
+import org.sonar.server.devcockpit.bridge.DevCockpitStopper;
 import org.sonar.server.duplication.ws.DuplicationsJsonWriter;
 import org.sonar.server.duplication.ws.DuplicationsParser;
 import org.sonar.server.duplication.ws.DuplicationsWs;
@@ -308,8 +310,8 @@ 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;
-import org.sonar.server.ws.WebServicesWs;
 import org.sonar.server.ws.WebServiceEngine;
+import org.sonar.server.ws.WebServicesWs;
 import org.sonar.server.ws.WsResponseCommonFormat;
 
 public class PlatformLevel4 extends PlatformLevel {
@@ -712,6 +714,10 @@ public class PlatformLevel4 extends PlatformLevel {
       ViewsBootstrap.class,
       ViewsStopper.class,
 
+      // Developer Cockpit plugin
+      DevCockpitBootstrap.class,
+      DevCockpitStopper.class,
+
       // UI
       GlobalNavigationAction.class,
       SettingsNavigationAction.class,
diff --git a/server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrapTest.java b/server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrapTest.java
new file mode 100644 (file)
index 0000000..91eb613
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.devcockpit.bridge;
+
+import org.junit.Test;
+import org.sonar.api.platform.Server;
+import org.sonar.core.platform.ComponentContainer;
+import org.sonar.server.devcockpit.DevCockpitBridge;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+public class DevCockpitBootstrapTest {
+  private ComponentContainer componentContainer = new ComponentContainer();
+  private DevCockpitBridge devCockpitBridge = mock(DevCockpitBridge.class);
+
+  private DevCockpitBootstrap underTest = new DevCockpitBootstrap(componentContainer);
+
+  @Test
+  public void onServerStart_calls_startDevCockpit_if_DevCockpitBridge_exists_in_container() {
+    componentContainer.add(devCockpitBridge);
+    componentContainer.startComponents();
+
+    underTest.onServerStart(mock(Server.class));
+
+    verify(devCockpitBridge).startDevCockpit(componentContainer);
+    verifyNoMoreInteractions(devCockpitBridge);
+  }
+
+  @Test
+  public void onServerStart_does_not_call_startDevCockpit_if_DevCockpitBridge_does_not_exist_in_container() {
+    underTest.onServerStart(mock(Server.class));
+
+    verifyNoMoreInteractions(devCockpitBridge);
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitStopperTest.java b/server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitStopperTest.java
new file mode 100644 (file)
index 0000000..90b2ccc
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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.devcockpit.bridge;
+
+import org.junit.Test;
+import org.sonar.core.platform.ComponentContainer;
+import org.sonar.server.devcockpit.DevCockpitBridge;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+public class DevCockpitStopperTest {
+  private ComponentContainer componentContainer = new ComponentContainer();
+  private DevCockpitBridge devCockpitBridge = mock(DevCockpitBridge.class);
+
+  private DevCockpitStopper underTest = new DevCockpitStopper(componentContainer);
+
+  @Test
+  public void stop_calls_stopDevCockpit_if_DevCockpitBridge_exists_in_container() {
+    componentContainer.add(devCockpitBridge);
+    componentContainer.startComponents();
+
+    underTest.stop();
+
+
+    verify(devCockpitBridge).stopDevCockpit();
+    verifyNoMoreInteractions(devCockpitBridge);
+  }
+
+  @Test
+  public void stop_does_not_call_stopDevCockpit_if_DevCockpitBridge_does_not_exist_in_container() {
+    underTest.stop();
+
+    verifyNoMoreInteractions(devCockpitBridge);
+  }
+}