From 5934fd7d5566968f395b6dcf4658bad241d28825 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Wed, 18 Nov 2015 11:28:19 +0100 Subject: [PATCH] SONAR-7027 add DevCockpitBridge and start/stop Dev Cockpit plugin add Maven module sonar-dev-cockpit-bridge --- pom.xml | 5 ++ server/pom.xml | 3 +- server/sonar-dev-cockpit-bridge/pom.xml | 58 +++++++++++++++++++ .../server/devcockpit/DevCockpitBridge.java | 44 ++++++++++++++ .../sonar/server/devcockpit/package-info.java | 24 ++++++++ server/sonar-server/pom.xml | 4 ++ .../bridge/DevCockpitBootstrap.java | 52 +++++++++++++++++ .../devcockpit/bridge/DevCockpitStopper.java | 56 ++++++++++++++++++ .../devcockpit/bridge/package-info.java | 25 ++++++++ .../platformlevel/PlatformLevel4.java | 8 ++- .../bridge/DevCockpitBootstrapTest.java | 54 +++++++++++++++++ .../bridge/DevCockpitStopperTest.java | 54 +++++++++++++++++ 12 files changed, 385 insertions(+), 2 deletions(-) create mode 100644 server/sonar-dev-cockpit-bridge/pom.xml create mode 100644 server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/DevCockpitBridge.java create mode 100644 server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/package-info.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrap.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitStopper.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/package-info.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrapTest.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitStopperTest.java diff --git a/pom.xml b/pom.xml index 4d56d660c96..27ed5824de5 100644 --- a/pom.xml +++ b/pom.xml @@ -715,6 +715,11 @@ sonar-views-bridge ${project.version} + + org.sonarsource.sonarqube + sonar-dev-cockpit-bridge + ${project.version} + org.sonarsource.java sonar-java-plugin diff --git a/server/pom.xml b/server/pom.xml index 356ea3b9d88..85822ac1d27 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -14,8 +14,9 @@ sonar-process sonar-process-monitor sonar-search - sonar-views-bridge sonar-server + sonar-views-bridge + sonar-dev-cockpit-bridge sonar-web sonar-server-benchmarks diff --git a/server/sonar-dev-cockpit-bridge/pom.xml b/server/sonar-dev-cockpit-bridge/pom.xml new file mode 100644 index 00000000000..e63a98facb5 --- /dev/null +++ b/server/sonar-dev-cockpit-bridge/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + org.sonarsource.sonarqube + server + 5.3-SNAPSHOT + .. + + sonar-dev-cockpit-bridge + SonarQube :: Developer Cockpit Bridge + + + + ${project.groupId} + sonar-plugin-api + + + ${project.groupId} + sonar-core + + + com.google.code.findbugs + jsr305 + provided + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + ${skipServerTests} + + + + + + + + release + + + + maven-deploy-plugin + + true + + + + + + + + + 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 index 00000000000..9b330693a2c --- /dev/null +++ b/server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/DevCockpitBridge.java @@ -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 index 00000000000..1e92523aa8f --- /dev/null +++ b/server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/package-info.java @@ -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; diff --git a/server/sonar-server/pom.xml b/server/sonar-server/pom.xml index 7fb49bddfb1..b059b0ffe08 100644 --- a/server/sonar-server/pom.xml +++ b/server/sonar-server/pom.xml @@ -185,6 +185,10 @@ ${project.groupId} sonar-views-bridge + + ${project.groupId} + sonar-dev-cockpit-bridge + ${project.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 index 00000000000..0c87cd974ca --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrap.java @@ -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 index 00000000000..de97cad9102 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitStopper.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.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 index 00000000000..d5c15329392 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/package-info.java @@ -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; + 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 1d2349b3991..9b6869750ee 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 @@ -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 index 00000000000..91eb613dff5 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrapTest.java @@ -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 index 00000000000..90b2ccc4285 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitStopperTest.java @@ -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); + } +} -- 2.39.5