From 9b88ac1448e5f8dc359a928602ed2883515611c5 Mon Sep 17 00:00:00 2001 From: Sébastien Lesaint Date: Tue, 29 Mar 2016 18:10:21 +0200 Subject: SONAR-7510 add sonar-plugin-bridge and ReportAnalysisComponentProvider new sonar-plugin-bridge maven module replaces modules sonar-dev-cockpit-bridge and sonar-governance-bridge ReportAnalysisComponentProvider generalizes loading component in the Compute Engine task processing analysis report which was specifically in Dev Cockpit before, as a method of DevCockpitBridge --- pom.xml | 7 +-- server/pom.xml | 3 +- .../ce/container/ComputeEngineContainerImpl.java | 16 ++---- .../container/ComputeEngineContainerImplTest.java | 2 +- server/sonar-dev-cockpit-bridge/pom.xml | 41 --------------- .../sonar/server/devcockpit/DevCockpitBridge.java | 50 ------------------ .../devcockpit/PersistDevelopersDelegate.java | 29 ----------- .../org/sonar/server/devcockpit/package-info.java | 23 --------- server/sonar-governance-bridge/pom.xml | 41 --------------- .../sonar/server/governance/GovernanceBridge.java | 44 ---------------- .../org/sonar/server/governance/package-info.java | 23 --------- server/sonar-plugin-bridge/pom.xml | 41 +++++++++++++++ .../org/sonar/plugin/PrivilegedPluginBridge.java | 46 +++++++++++++++++ .../plugin/ce/ReportAnalysisComponentProvider.java | 33 ++++++++++++ .../java/org/sonar/plugin/ce/package-info.java | 23 +++++++++ .../main/java/org/sonar/plugin/package-info.java | 23 +++++++++ server/sonar-server/pom.xml | 6 +-- .../computation/container/ContainerFactory.java | 6 +-- .../container/ContainerFactoryImpl.java | 8 +-- .../ReportComputeEngineContainerPopulator.java | 15 +++--- .../developer/PersistDevelopersDelegate.java | 29 +++++++++++ .../server/computation/developer/package-info.java | 23 +++++++++ .../computation/step/PersistDevelopersStep.java | 2 +- .../computation/step/ReportComputationSteps.java | 6 ++- .../taskprocessor/report/ReportTaskProcessor.java | 16 +++--- .../devcockpit/bridge/DevCockpitBootstrap.java | 52 ------------------- .../devcockpit/bridge/DevCockpitStopper.java | 56 -------------------- .../server/devcockpit/bridge/package-info.java | 24 --------- .../governance/bridge/GovernanceBootstrap.java | 52 ------------------- .../governance/bridge/GovernanceStopper.java | 56 -------------------- .../server/governance/bridge/package-info.java | 24 --------- .../platform/platformlevel/PlatformLevel4.java | 16 ++---- .../privileged/PrivilegedPluginsBootstraper.java | 55 ++++++++++++++++++++ .../privileged/PrivilegedPluginsStopper.java | 59 +++++++++++++++++++++ .../server/plugins/privileged/package-info.java | 24 +++++++++ .../ReportComputeEngineContainerPopulatorTest.java | 51 +++++++++--------- .../step/PersistDevelopersStepTest.java | 2 +- .../devcockpit/bridge/DevCockpitBootstrapTest.java | 54 ------------------- .../devcockpit/bridge/DevCockpitStopperTest.java | 54 ------------------- .../governance/bridge/GovernanceBootstrapTest.java | 54 ------------------- .../governance/bridge/GovernanceStopperTest.java | 60 ---------------------- .../PrivilegedPluginsBootstraperTest.java | 55 ++++++++++++++++++++ .../privileged/PrivilegedPluginsStopperTest.java | 54 +++++++++++++++++++ .../sonar/core/platform/ContainerPopulator.java | 4 ++ 44 files changed, 539 insertions(+), 823 deletions(-) delete mode 100644 server/sonar-dev-cockpit-bridge/pom.xml delete mode 100644 server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/DevCockpitBridge.java delete mode 100644 server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/PersistDevelopersDelegate.java delete mode 100644 server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/package-info.java delete mode 100644 server/sonar-governance-bridge/pom.xml delete mode 100644 server/sonar-governance-bridge/src/main/java/org/sonar/server/governance/GovernanceBridge.java delete mode 100644 server/sonar-governance-bridge/src/main/java/org/sonar/server/governance/package-info.java create mode 100644 server/sonar-plugin-bridge/pom.xml create mode 100644 server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/PrivilegedPluginBridge.java create mode 100644 server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/ce/ReportAnalysisComponentProvider.java create mode 100644 server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/ce/package-info.java create mode 100644 server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/package-info.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/developer/PersistDevelopersDelegate.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/developer/package-info.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrap.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitStopper.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/package-info.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/governance/bridge/GovernanceBootstrap.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/governance/bridge/GovernanceStopper.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/governance/bridge/package-info.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraper.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/PrivilegedPluginsStopper.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/package-info.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrapTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitStopperTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceBootstrapTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceStopperTest.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraperTest.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsStopperTest.java diff --git a/pom.xml b/pom.xml index ded0eaa437e..1733d94735f 100644 --- a/pom.xml +++ b/pom.xml @@ -520,12 +520,7 @@ org.sonarsource.sonarqube - sonar-dev-cockpit-bridge - ${project.version} - - - org.sonarsource.sonarqube - sonar-governance-bridge + sonar-plugin-bridge ${project.version} diff --git a/server/pom.xml b/server/pom.xml index 5f7aab7d92b..0802fb2eb61 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -16,8 +16,7 @@ sonar-search sonar-server sonar-ce - sonar-dev-cockpit-bridge - sonar-governance-bridge + sonar-plugin-bridge sonar-web sonar-server-benchmarks diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java index 168b1b2dae1..bd2d9e11eb0 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java @@ -75,11 +75,7 @@ import org.sonar.server.computation.queue.PurgeCeActivities; import org.sonar.server.computation.taskprocessor.CeTaskProcessorModule; import org.sonar.server.debt.DebtModelPluginRepository; import org.sonar.server.debt.DebtRulesXMLImporter; -import org.sonar.server.devcockpit.bridge.DevCockpitBootstrap; -import org.sonar.server.devcockpit.bridge.DevCockpitStopper; import org.sonar.server.event.NewAlerts; -import org.sonar.server.governance.bridge.GovernanceBootstrap; -import org.sonar.server.governance.bridge.GovernanceStopper; import org.sonar.server.issue.IssueUpdater; import org.sonar.server.issue.index.IssueAuthorizationIndexer; import org.sonar.server.issue.index.IssueIndex; @@ -112,6 +108,8 @@ import org.sonar.server.platform.TempFolderProvider; import org.sonar.server.platform.monitoring.JmxConnectionFactoryProvider; import org.sonar.server.plugins.InstalledPluginReferentialFactory; import org.sonar.server.plugins.ServerExtensionInstaller; +import org.sonar.server.plugins.privileged.PrivilegedPluginsBootstraper; +import org.sonar.server.plugins.privileged.PrivilegedPluginsStopper; import org.sonar.server.properties.ProjectSettingsFactory; import org.sonar.server.qualityprofile.BuiltInProfiles; import org.sonar.server.qualityprofile.QProfileComparison; @@ -548,13 +546,9 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { // ViewsBootstrap.class, Views not supported in 5.5 // ViewsStopper.class, Views not supported in 5.5 - // Developer Cockpit plugin - DevCockpitBootstrap.class, - DevCockpitStopper.class, - - // Governance plugin - GovernanceBootstrap.class, - GovernanceStopper.class, + // privileged plugins + PrivilegedPluginsBootstraper.class, + PrivilegedPluginsStopper.class, // Compute engine (must be after Views and Developer Cockpit) CeModule.class, diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index d767f42a1bb..15abf853225 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -79,7 +79,7 @@ public class ComputeEngineContainerImplTest { assertThat(picoContainer.getComponentAdapters()) .hasSize( CONTAINER_ITSELF - + 78 // level 4 + + 76 // level 4 + 5 // content of CeModule + 7 // content of CeQueueModule + 4 // content of ReportProcessingModule diff --git a/server/sonar-dev-cockpit-bridge/pom.xml b/server/sonar-dev-cockpit-bridge/pom.xml deleted file mode 100644 index 87f2e8276e8..00000000000 --- a/server/sonar-dev-cockpit-bridge/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - 4.0.0 - - org.sonarsource.sonarqube - server - 5.5-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} - - - - - - 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 deleted file mode 100644 index 55bbdf85d92..00000000000 --- a/server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/DevCockpitBridge.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 java.util.List; -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(); - - /** - * Return the list of components to add to the state-full container of a Compute Engine report analysis task - */ - List getCeComponents(); - -} diff --git a/server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/PersistDevelopersDelegate.java b/server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/PersistDevelopersDelegate.java deleted file mode 100644 index 927bb9a3d4d..00000000000 --- a/server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/PersistDevelopersDelegate.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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; - -/** - * This interface is used to delegate the persistence of developers to the Developer Cockpit plugin - */ -public interface PersistDevelopersDelegate { - - void execute(); - -} 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 deleted file mode 100644 index fbf52f1b14e..00000000000 --- a/server/sonar-dev-cockpit-bridge/src/main/java/org/sonar/server/devcockpit/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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-governance-bridge/pom.xml b/server/sonar-governance-bridge/pom.xml deleted file mode 100644 index 3c49da1690e..00000000000 --- a/server/sonar-governance-bridge/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - 4.0.0 - - org.sonarsource.sonarqube - server - 5.5-SNAPSHOT - .. - - sonar-governance-bridge - SonarQube :: Governance Bridge - - - - ${project.groupId} - sonar-plugin-api - - - ${project.groupId} - sonar-core - - - com.google.code.findbugs - jsr305 - provided - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - ${skipServerTests} - - - - - - diff --git a/server/sonar-governance-bridge/src/main/java/org/sonar/server/governance/GovernanceBridge.java b/server/sonar-governance-bridge/src/main/java/org/sonar/server/governance/GovernanceBridge.java deleted file mode 100644 index 03c3e633383..00000000000 --- a/server/sonar-governance-bridge/src/main/java/org/sonar/server/governance/GovernanceBridge.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.governance; - -import org.sonar.core.platform.ComponentContainer; - -/** - * Interface implemented by the Extension point exposed by the Governance plugin that serves as the unique access point from - * the whole SQ instance into the Governance plugin. - */ -public interface GovernanceBridge { - - /** - * Bootstraps the Governance plugin. - * - * @param parent the parent ComponentContainer which provides Platform components for Governance to use. - * - * @throws IllegalStateException if called more than once - */ - void startGovernance(ComponentContainer parent); - - /** - * This method is called when Platform is shutting down. - */ - void stopGovernance(); - -} diff --git a/server/sonar-governance-bridge/src/main/java/org/sonar/server/governance/package-info.java b/server/sonar-governance-bridge/src/main/java/org/sonar/server/governance/package-info.java deleted file mode 100644 index 17c8c94552d..00000000000 --- a/server/sonar-governance-bridge/src/main/java/org/sonar/server/governance/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.governance; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-plugin-bridge/pom.xml b/server/sonar-plugin-bridge/pom.xml new file mode 100644 index 00000000000..5c23d7a334e --- /dev/null +++ b/server/sonar-plugin-bridge/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + org.sonarsource.sonarqube + server + 5.5-SNAPSHOT + .. + + sonar-plugin-bridge + SonarQube :: Priviledged Plugin Bridge + + + + ${project.groupId} + sonar-plugin-api + + + ${project.groupId} + sonar-core + + + com.google.code.findbugs + jsr305 + provided + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + ${skipServerTests} + + + + + + diff --git a/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/PrivilegedPluginBridge.java b/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/PrivilegedPluginBridge.java new file mode 100644 index 00000000000..b8cb97babac --- /dev/null +++ b/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/PrivilegedPluginBridge.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.plugin; + +import org.sonar.core.platform.ComponentContainer; + +/** + * Interface implemented by the Extension point exposed by the Privileged plugin that serves as the unique access + * point from the whole SQ instance into the Privileged plugin. + */ +public interface PrivilegedPluginBridge { + + String getPluginName(); + + /** + * Bootstraps the plugin. + * + * @param parent the parent ComponentContainer which provides Platform components for the Privileged plugin to use. + * + * @throws IllegalStateException if called more than once + */ + void startPlugin(ComponentContainer parent); + + /** + * This method is called when Platform is shutting down. + */ + void stopPlugin(); + +} diff --git a/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/ce/ReportAnalysisComponentProvider.java b/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/ce/ReportAnalysisComponentProvider.java new file mode 100644 index 00000000000..e47723602d3 --- /dev/null +++ b/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/ce/ReportAnalysisComponentProvider.java @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.plugin.ce; + +import java.util.List; +import org.sonar.api.ce.ComputeEngineSide; + +@ComputeEngineSide +public interface ReportAnalysisComponentProvider { + + /** + * Return the list of components to add to the state-full container of a Compute Engine report analysis task + */ + List getComponents(); + +} diff --git a/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/ce/package-info.java b/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/ce/package-info.java new file mode 100644 index 00000000000..0eda9134660 --- /dev/null +++ b/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/ce/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.plugin.ce; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/package-info.java b/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/package-info.java new file mode 100644 index 00000000000..66b29c54962 --- /dev/null +++ b/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.plugin; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/pom.xml b/server/sonar-server/pom.xml index 36880dd10cd..2b1a4860dbb 100644 --- a/server/sonar-server/pom.xml +++ b/server/sonar-server/pom.xml @@ -171,11 +171,7 @@ ${project.groupId} - sonar-dev-cockpit-bridge - - - ${project.groupId} - sonar-governance-bridge + sonar-plugin-bridge diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/container/ContainerFactory.java b/server/sonar-server/src/main/java/org/sonar/server/computation/container/ContainerFactory.java index 8893ab2c885..fe1b292278a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/container/ContainerFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/container/ContainerFactory.java @@ -20,11 +20,11 @@ package org.sonar.server.computation.container; import javax.annotation.Nullable; -import org.sonar.core.platform.ComponentContainer; import org.sonar.ce.queue.CeTask; -import org.sonar.server.devcockpit.DevCockpitBridge; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.plugin.ce.ReportAnalysisComponentProvider; public interface ContainerFactory { - ComputeEngineContainer create(ComponentContainer parent, CeTask task, @Nullable DevCockpitBridge devCockpitBridge); + ComputeEngineContainer create(ComponentContainer parent, CeTask task, @Nullable ReportAnalysisComponentProvider[] componentProviders); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/container/ContainerFactoryImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/container/ContainerFactoryImpl.java index 78d2f863f01..eaba445cf16 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/container/ContainerFactoryImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/container/ContainerFactoryImpl.java @@ -20,13 +20,13 @@ package org.sonar.server.computation.container; import javax.annotation.Nullable; -import org.sonar.core.platform.ComponentContainer; import org.sonar.ce.queue.CeTask; -import org.sonar.server.devcockpit.DevCockpitBridge; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.plugin.ce.ReportAnalysisComponentProvider; public class ContainerFactoryImpl implements ContainerFactory { @Override - public ComputeEngineContainer create(ComponentContainer parent, CeTask task, @Nullable DevCockpitBridge devCockpitBridge) { - return new ComputeEngineContainerImpl(parent, new ReportComputeEngineContainerPopulator(task, devCockpitBridge)); + public ComputeEngineContainer create(ComponentContainer parent, CeTask task, @Nullable ReportAnalysisComponentProvider[] componentProviders) { + return new ComputeEngineContainerImpl(parent, new ReportComputeEngineContainerPopulator(task, componentProviders)); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java b/server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java index 1c79df7d1cb..c0c9797d736 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulator.java @@ -25,6 +25,7 @@ import javax.annotation.Nullable; import org.sonar.ce.queue.CeTask; import org.sonar.core.issue.tracking.Tracker; import org.sonar.core.platform.ContainerPopulator; +import org.sonar.plugin.ce.ReportAnalysisComponentProvider; import org.sonar.server.computation.analysis.AnalysisMetadataHolderImpl; import org.sonar.server.computation.batch.BatchReportDirectoryHolderImpl; import org.sonar.server.computation.batch.BatchReportReaderImpl; @@ -90,16 +91,15 @@ import org.sonar.server.computation.step.ComputationStepExecutor; import org.sonar.server.computation.step.ComputationSteps; import org.sonar.server.computation.step.ReportComputationSteps; import org.sonar.server.computation.taskprocessor.MutableTaskResultHolderImpl; -import org.sonar.server.devcockpit.DevCockpitBridge; import org.sonar.server.view.index.ViewIndex; public final class ReportComputeEngineContainerPopulator implements ContainerPopulator { private final CeTask task; - private final DevCockpitBridge devCockpitBridge; + private final ReportAnalysisComponentProvider[] componentProviders; - public ReportComputeEngineContainerPopulator(CeTask task, @Nullable DevCockpitBridge devCockpitBridge) { + public ReportComputeEngineContainerPopulator(CeTask task, @Nullable ReportAnalysisComponentProvider[] componentProviders) { this.task = task; - this.devCockpitBridge = devCockpitBridge; + this.componentProviders = componentProviders == null ? new ReportAnalysisComponentProvider[0] : componentProviders; } @Override @@ -108,8 +108,8 @@ public final class ReportComputeEngineContainerPopulator implements ContainerPop container.add(task); container.add(steps); container.addSingletons(componentClasses()); - if (devCockpitBridge != null) { - container.addSingletons(devCockpitBridge.getCeComponents()); + for (ReportAnalysisComponentProvider componentProvider : componentProviders) { + container.addSingletons(componentProvider.getComponents()); } container.addSingletons(steps.orderedStepClasses()); } @@ -207,8 +207,7 @@ public final class ReportComputeEngineContainerPopulator implements ContainerPop // views ViewIndex.class, - MeasureToMeasureDto.class - ); + MeasureToMeasureDto.class); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/developer/PersistDevelopersDelegate.java b/server/sonar-server/src/main/java/org/sonar/server/computation/developer/PersistDevelopersDelegate.java new file mode 100644 index 00000000000..f8f60553365 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/developer/PersistDevelopersDelegate.java @@ -0,0 +1,29 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.computation.developer; + +/** + * This interface is used to delegate the persistence of developers to the Developer Cockpit plugin + */ +public interface PersistDevelopersDelegate { + + void execute(); + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/developer/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/developer/package-info.java new file mode 100644 index 00000000000..3ddfcdfcb98 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/developer/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.computation.developer; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDevelopersStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDevelopersStep.java index eb2da0e9158..24ee34ab3a9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDevelopersStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDevelopersStep.java @@ -19,7 +19,7 @@ */ package org.sonar.server.computation.step; -import org.sonar.server.devcockpit.PersistDevelopersDelegate; +import org.sonar.server.computation.developer.PersistDevelopersDelegate; /** * Persist developers, should only be execute when the Dev Cockpit plugin is installed. diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java index 8343cc318ca..5300cf398b5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ReportComputationSteps.java @@ -24,7 +24,7 @@ import java.util.Arrays; import java.util.List; import javax.annotation.Nonnull; import org.sonar.server.computation.container.ComputeEngineContainer; -import org.sonar.server.devcockpit.DevCockpitBridge; +import org.sonar.server.computation.developer.PersistDevelopersDelegate; import static com.google.common.collect.FluentIterable.from; @@ -33,6 +33,8 @@ import static com.google.common.collect.FluentIterable.from; */ public class ReportComputationSteps extends AbstractComputationSteps { + private static final String DEVELOPER_COCKPIT_PLUGIN_NAME = "Developer Cockpit"; + private static final List> STEPS = Arrays.asList( ExtractReportStep.class, LogScannerContextStep.class, @@ -127,7 +129,7 @@ public class ReportComputationSteps extends AbstractComputationSteps { private class AllowPersistDevelopersStepIfDevCockpitPluginInstalled implements Predicate> { - private final boolean devCockpitIsInstalled = computeEngineContainer.getComponentByType(DevCockpitBridge.class) != null; + private final boolean devCockpitIsInstalled = computeEngineContainer.getComponentByType(PersistDevelopersDelegate.class) != null; @Override public boolean apply(@Nonnull Class input) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/report/ReportTaskProcessor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/report/ReportTaskProcessor.java index 912177763db..0a24deab12a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/report/ReportTaskProcessor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/taskprocessor/report/ReportTaskProcessor.java @@ -28,11 +28,11 @@ import org.sonar.ce.settings.ThreadLocalSettings; import org.sonar.ce.taskprocessor.CeTaskProcessor; import org.sonar.core.platform.ComponentContainer; import org.sonar.db.ce.CeTaskTypes; +import org.sonar.plugin.ce.ReportAnalysisComponentProvider; import org.sonar.server.computation.container.ComputeEngineContainer; import org.sonar.server.computation.container.ContainerFactory; import org.sonar.server.computation.step.ComputationStepExecutor; import org.sonar.server.computation.taskprocessor.TaskResultHolder; -import org.sonar.server.devcockpit.DevCockpitBridge; public class ReportTaskProcessor implements CeTaskProcessor { @@ -41,24 +41,24 @@ public class ReportTaskProcessor implements CeTaskProcessor { private final ContainerFactory containerFactory; private final ComponentContainer serverContainer; @CheckForNull - private final DevCockpitBridge devCockpitBridge; + private final ReportAnalysisComponentProvider[] componentProviders; /** - * Used when Developer Cockpit plugin is installed + * Used when at least one Privileged plugin is installed */ - public ReportTaskProcessor(ContainerFactory containerFactory, ComponentContainer serverContainer, DevCockpitBridge devCockpitBridge) { + public ReportTaskProcessor(ContainerFactory containerFactory, ComponentContainer serverContainer, ReportAnalysisComponentProvider[] componentProviders) { this.containerFactory = containerFactory; this.serverContainer = serverContainer; - this.devCockpitBridge = devCockpitBridge; + this.componentProviders = componentProviders; } /** - * Used when Developer Cockpit plugin is not installed + * Used when no privileged plugin is installed */ public ReportTaskProcessor(ContainerFactory containerFactory, ComponentContainer serverContainer) { this.containerFactory = containerFactory; this.serverContainer = serverContainer; - this.devCockpitBridge = null; + this.componentProviders = null; } @Override @@ -68,7 +68,7 @@ public class ReportTaskProcessor implements CeTaskProcessor { @Override public CeTaskResult process(CeTask task) { - ComputeEngineContainer ceContainer = containerFactory.create(serverContainer, task, devCockpitBridge); + ComputeEngineContainer ceContainer = containerFactory.create(serverContainer, task, componentProviders); ThreadLocalSettings ceSettings = null; try { ceSettings = ceContainer.getComponentByType(ThreadLocalSettings.class); 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 deleted file mode 100644 index 5924c430225..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrap.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 deleted file mode 100644 index dc5ffb8d98c..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/DevCockpitStopper.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 deleted file mode 100644 index 1401c9986e5..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/devcockpit/bridge/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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/governance/bridge/GovernanceBootstrap.java b/server/sonar-server/src/main/java/org/sonar/server/governance/bridge/GovernanceBootstrap.java deleted file mode 100644 index 273f40e6e51..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/governance/bridge/GovernanceBootstrap.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.governance.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.governance.GovernanceBridge; - -/** - * Startup task to responsible to bootstrap the Governance plugin when it is installed. - */ -public class GovernanceBootstrap implements ServerStartHandler { - private static final Logger LOGGER = Loggers.get(GovernanceBootstrap.class); - - private final ComponentContainer componentContainer; - - public GovernanceBootstrap(ComponentContainer componentContainer) { - this.componentContainer = componentContainer; - } - - @Override - public void onServerStart(Server server) { - GovernanceBridge governanceBridge = componentContainer.getComponentByType(GovernanceBridge.class); - if (governanceBridge != null) { - Profiler profiler = Profiler.create(LOGGER).startInfo("Bootstrapping Governance plugin"); - governanceBridge.startGovernance(componentContainer); - profiler.stopInfo(); - } - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/governance/bridge/GovernanceStopper.java b/server/sonar-server/src/main/java/org/sonar/server/governance/bridge/GovernanceStopper.java deleted file mode 100644 index 6ecb566af6d..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/governance/bridge/GovernanceStopper.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.governance.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.governance.GovernanceBridge; - -/** - * As an component of PlatformLevel4, this class is responsible for notifying shutdown to the Governance plugin when its - * installed. - */ -public class GovernanceStopper implements Startable { - private static final Logger LOGGER = Loggers.get(GovernanceStopper.class); - - private final ComponentContainer platformContainer; - - public GovernanceStopper(ComponentContainer platformContainer) { - this.platformContainer = platformContainer; - } - - @Override - public void start() { - // nothing to do, Governance plugins is started by GovernanceBootstrap - } - - @Override - public void stop() { - GovernanceBridge viewsBridge = platformContainer.getComponentByType(GovernanceBridge.class); - if (viewsBridge != null) { - Profiler profiler = Profiler.create(LOGGER).startInfo("Stopping Governance plugin"); - viewsBridge.stopGovernance(); - profiler.stopInfo(); - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/governance/bridge/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/governance/bridge/package-info.java deleted file mode 100644 index 5ad47aac89a..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/governance/bridge/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.governance.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 e832c4b4d8a..10913fa94ca 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 @@ -89,16 +89,12 @@ 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; import org.sonar.server.es.IndexCreator; import org.sonar.server.es.IndexDefinitions; import org.sonar.server.event.NewAlerts; -import org.sonar.server.governance.bridge.GovernanceBootstrap; -import org.sonar.server.governance.bridge.GovernanceStopper; import org.sonar.server.issue.ActionService; import org.sonar.server.issue.AddTagsAction; import org.sonar.server.issue.AssignAction; @@ -180,6 +176,8 @@ import org.sonar.server.plugins.PluginDownloader; import org.sonar.server.plugins.ServerExtensionInstaller; import org.sonar.server.plugins.UpdateCenterClient; import org.sonar.server.plugins.UpdateCenterMatrixFactory; +import org.sonar.server.plugins.privileged.PrivilegedPluginsBootstraper; +import org.sonar.server.plugins.privileged.PrivilegedPluginsStopper; import org.sonar.server.plugins.ws.AvailableAction; import org.sonar.server.plugins.ws.CancelAllAction; import org.sonar.server.plugins.ws.InstallAction; @@ -674,13 +672,9 @@ public class PlatformLevel4 extends PlatformLevel { CancelAllAction.class, PluginsWs.class, - // Developer Cockpit plugin - DevCockpitBootstrap.class, - DevCockpitStopper.class, - - // Governance plugin - GovernanceBootstrap.class, - GovernanceStopper.class, + // privileged plugins + PrivilegedPluginsBootstraper.class, + PrivilegedPluginsStopper.class, // Compute engine (must be after Views and Developer Cockpit) CeModule.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraper.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraper.java new file mode 100644 index 00000000000..e433e9d6a5a --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraper.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.plugins.privileged; + +import java.util.List; +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.plugin.PrivilegedPluginBridge; + +import static java.lang.String.format; + +/** + * Startup task to responsible to bootstrap installed Privileged plugins (if any). + */ +public class PrivilegedPluginsBootstraper implements ServerStartHandler { + private static final Logger LOGGER = Loggers.get(PrivilegedPluginsBootstraper.class); + + private final ComponentContainer componentContainer; + + public PrivilegedPluginsBootstraper(ComponentContainer componentContainer) { + this.componentContainer = componentContainer; + } + + @Override + public void onServerStart(Server server) { + List bridges = componentContainer.getComponentsByType(PrivilegedPluginBridge.class); + for (PrivilegedPluginBridge bridge : bridges) { + Profiler profiler = Profiler.create(LOGGER).startInfo(format("Bootstrapping %s", bridge.getPluginName())); + bridge.startPlugin(componentContainer); + profiler.stopInfo(); + } + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/PrivilegedPluginsStopper.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/PrivilegedPluginsStopper.java new file mode 100644 index 00000000000..c9c71773657 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/PrivilegedPluginsStopper.java @@ -0,0 +1,59 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.plugins.privileged; + +import java.util.List; +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.plugin.PrivilegedPluginBridge; + +import static java.lang.String.format; + +/** + * As an component of PlatformLevel4, this class is responsible for notifying shutdown to the installed Privileged plugins + * (if any) when its installed. + */ +public class PrivilegedPluginsStopper implements Startable { + private static final Logger LOGGER = Loggers.get(PrivilegedPluginsStopper.class); + + private final ComponentContainer platformContainer; + + public PrivilegedPluginsStopper(ComponentContainer platformContainer) { + this.platformContainer = platformContainer; + } + + @Override + public void start() { + // nothing to do, privileged plugins are started by PrivilegedPluginsBootstraper + } + + @Override + public void stop() { + List bridges = platformContainer.getComponentsByType(PrivilegedPluginBridge.class); + for (PrivilegedPluginBridge bridge : bridges) { + Profiler profiler = Profiler.create(LOGGER).startInfo(format("Stopping %s", bridge.getPluginName())); + bridge.stopPlugin(); + profiler.stopInfo(); + } + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/package-info.java new file mode 100644 index 00000000000..992ccb1c06e --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.plugins.privileged; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulatorTest.java index 0674fd77fee..7254400aff3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/container/ReportComputeEngineContainerPopulatorTest.java @@ -21,19 +21,20 @@ package org.sonar.server.computation.container; import com.google.common.base.Function; import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.junit.Test; -import org.sonar.core.platform.ComponentContainer; import org.sonar.ce.queue.CeTask; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.plugin.ce.ReportAnalysisComponentProvider; import org.sonar.server.computation.step.ComputationStep; import org.sonar.server.computation.step.PersistComponentsStep; import org.sonar.server.computation.step.PersistDevelopersStep; -import org.sonar.server.devcockpit.DevCockpitBridge; -import org.sonar.server.devcockpit.PersistDevelopersDelegate; import static com.google.common.base.Predicates.notNull; import static com.google.common.collect.FluentIterable.from; @@ -100,29 +101,22 @@ public class ReportComputeEngineContainerPopulatorTest { } @Test - public void PersistDevelopersStep_is_added_to_the_container_when_DevCockpitBridge_exist() { - DevCockpitBridge devCockpitBridge = mock(DevCockpitBridge.class); - when(devCockpitBridge.getCeComponents()).thenReturn(Arrays.asList(PersistDevelopersDelegateImpl.class)); + public void Components_of_ReportAnalysisComponentProvider_are_added_to_the_container() { + Object object = new Object(); + Class clazz = MyClass.class; + ReportAnalysisComponentProvider componentProvider = mock(ReportAnalysisComponentProvider.class); + when(componentProvider.getComponents()).thenReturn(ImmutableList.of(object, clazz)); - underTest = new ReportComputeEngineContainerPopulator(task, devCockpitBridge); + underTest = new ReportComputeEngineContainerPopulator(task, new ReportAnalysisComponentProvider[]{componentProvider}); AddedObjectsRecorderComputeEngineContainer container = new AddedObjectsRecorderComputeEngineContainer(); - container.add(devCockpitBridge); + container.add(componentProvider); underTest.populateContainer(container); - assertThat(container.added).contains(PersistDevelopersStep.class); + assertThat(container.added).contains(object, clazz); } - @Test - public void components_from_DevCockpitBridge_are_added_to_the_container_when_DevCockpitBridge_exist() { - DevCockpitBridge devCockpitBridge = mock(DevCockpitBridge.class); - when(devCockpitBridge.getCeComponents()).thenReturn(Arrays.asList(PersistDevelopersDelegateImpl.class)); - - underTest = new ReportComputeEngineContainerPopulator(task, devCockpitBridge); - AddedObjectsRecorderComputeEngineContainer container = new AddedObjectsRecorderComputeEngineContainer(); - container.add(devCockpitBridge); - underTest.populateContainer(container); + private static final class MyClass { - assertThat(container.added).contains(PersistDevelopersDelegateImpl.class); } private enum IsComputationStep implements Predicate> { @@ -170,12 +164,23 @@ public class ReportComputeEngineContainerPopulatorTest { } return null; } - } - private static class PersistDevelopersDelegateImpl implements PersistDevelopersDelegate { @Override - public void execute() { - // nothing to do + public List getComponentsByType(final Class type) { + return from(added) + .filter(new Predicate() { + @Override + public boolean apply(@Nonnull Object input) { + return input.getClass().getSimpleName().contains(type.getSimpleName()); + } + }).transform(new Function() { + @Override + @Nonnull + public T apply(@Nonnull Object input) { + return (T) input; + } + }).toList(); } } + } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDevelopersStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDevelopersStepTest.java index 33bdf73b639..9ef1e5b8d54 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDevelopersStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDevelopersStepTest.java @@ -20,7 +20,7 @@ package org.sonar.server.computation.step; import org.junit.Test; -import org.sonar.server.devcockpit.PersistDevelopersDelegate; +import org.sonar.server.computation.developer.PersistDevelopersDelegate; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; 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 deleted file mode 100644 index 3a9f9b9c3ac..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitBootstrapTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 deleted file mode 100644 index 7e8c5a86306..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/devcockpit/bridge/DevCockpitStopperTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceBootstrapTest.java b/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceBootstrapTest.java deleted file mode 100644 index b34bc9b913d..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceBootstrapTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.governance.bridge; - -import org.junit.Test; -import org.sonar.api.platform.Server; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.server.governance.GovernanceBridge; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; - -public class GovernanceBootstrapTest { - private Server server = mock(Server.class); - private ComponentContainer componentContainer = spy(new ComponentContainer()); - private GovernanceBootstrap underTest = new GovernanceBootstrap(componentContainer); - - @Test - public void onServerStart_has_no_effect_when_ComponentContainer_contains_no_GovernanceBridge() { - underTest.onServerStart(server); - - verify(componentContainer).getComponentByType(GovernanceBridge.class); - verifyNoMoreInteractions(componentContainer); - } - - @Test - public void onServerStart_calls_GovernanceBridge_startGovernance_when_present_in_ComponentContainer() { - GovernanceBridge governanceBridge = mock(GovernanceBridge.class); - componentContainer.add(governanceBridge); - - underTest.onServerStart(server); - - verify(governanceBridge).startGovernance(componentContainer); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceStopperTest.java b/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceStopperTest.java deleted file mode 100644 index 46cf92e4158..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/governance/bridge/GovernanceStopperTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.governance.bridge; - -import org.junit.Test; -import org.sonar.core.platform.ComponentContainer; -import org.sonar.server.governance.GovernanceBridge; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; - -public class GovernanceStopperTest { - private ComponentContainer componentContainer = spy(new ComponentContainer()); - private GovernanceStopper underTest = new GovernanceStopper(componentContainer); - - @Test - public void start_has_no_effect() { - underTest.start(); - - verifyNoMoreInteractions(componentContainer); - } - - @Test - public void stop_has_no_effect_when_no_GovernanceBridge() { - underTest.stop(); - - verify(componentContainer).getComponentByType(GovernanceBridge.class); - verifyNoMoreInteractions(componentContainer); - } - - @Test - public void stop_calls_GovernanceBridge_stopGovernance_when_in_ComponentContainer() { - GovernanceBridge governanceBridge = mock(GovernanceBridge.class); - - componentContainer.add(governanceBridge); - - underTest.stop(); - - verify(governanceBridge).stopGovernance(); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraperTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraperTest.java new file mode 100644 index 00000000000..722189d4fb4 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraperTest.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.plugins.privileged; + +import org.junit.Test; +import org.sonar.api.platform.Server; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.plugin.PrivilegedPluginBridge; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +public class PrivilegedPluginsBootstraperTest { + private ComponentContainer componentContainer = new ComponentContainer(); + private PrivilegedPluginBridge bridge = mock(PrivilegedPluginBridge.class); + + private PrivilegedPluginsBootstraper underTest = new PrivilegedPluginsBootstraper(componentContainer); + + @Test + public void onServerStart_calls_startPlugin_if_Bridge_exists_in_container() { + componentContainer.add(bridge); + componentContainer.startComponents(); + + underTest.onServerStart(mock(Server.class)); + + verify(bridge).getPluginName(); + verify(bridge).startPlugin(componentContainer); + verifyNoMoreInteractions(bridge); + } + + @Test + public void onServerStart_does_not_call_startPlugin_if_Bridge_does_not_exist_in_container() { + underTest.onServerStart(mock(Server.class)); + + verifyNoMoreInteractions(bridge); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsStopperTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsStopperTest.java new file mode 100644 index 00000000000..88a130edcc7 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsStopperTest.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program 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. + * + * This program 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.plugins.privileged; + +import org.junit.Test; +import org.sonar.core.platform.ComponentContainer; +import org.sonar.plugin.PrivilegedPluginBridge; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +public class PrivilegedPluginsStopperTest { + private ComponentContainer componentContainer = new ComponentContainer(); + private PrivilegedPluginBridge bridge = mock(PrivilegedPluginBridge.class); + + private PrivilegedPluginsStopper underTest = new PrivilegedPluginsStopper(componentContainer); + + @Test + public void stop_calls_stopPlugin_if_Bridge_exists_in_container() { + componentContainer.add(bridge); + componentContainer.startComponents(); + + underTest.stop(); + + verify(bridge).getPluginName(); + verify(bridge).stopPlugin(); + verifyNoMoreInteractions(bridge); + } + + @Test + public void stop_does_not_call_stopPlugin_if_Bridge_does_not_exist_in_container() { + underTest.stop(); + + verifyNoMoreInteractions(bridge); + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/platform/ContainerPopulator.java b/sonar-core/src/main/java/org/sonar/core/platform/ContainerPopulator.java index c7b12d46971..b63adfaace2 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/ContainerPopulator.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/ContainerPopulator.java @@ -19,6 +19,8 @@ */ package org.sonar.core.platform; +import java.util.List; + public interface ContainerPopulator { void populateContainer(T container); @@ -28,5 +30,7 @@ public interface ContainerPopulator { Container addSingletons(Iterable components); T getComponentByType(Class type); + + List getComponentsByType(Class type); } } -- cgit v1.2.3