From: Sébastien Lesaint Date: Wed, 30 May 2018 11:41:01 +0000 (+0200) Subject: SONAR-10690 remove support for privileged plugins X-Git-Tag: 7.5~1001 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c11d8d1a2540dd15d02c002197dd5b389670d050;p=sonarqube.git SONAR-10690 remove support for privileged plugins --- 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 2a9888cfe2e..1c45927fa2b 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 @@ -95,6 +95,8 @@ import org.sonar.server.debt.DebtRulesXMLImporter; import org.sonar.server.es.EsModule; import org.sonar.server.es.ProjectIndexersImpl; import org.sonar.server.event.NewAlerts; +import org.sonar.server.extension.CoreExtensionBootstraper; +import org.sonar.server.extension.CoreExtensionStopper; import org.sonar.server.favorite.FavoriteUpdater; import org.sonar.server.issue.IssueFieldsSetter; import org.sonar.server.issue.index.IssueIndex; @@ -146,8 +148,6 @@ import org.sonar.server.platform.monitoring.OfficialDistribution; import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider; 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.property.InternalPropertiesImpl; import org.sonar.server.qualitygate.QualityGateModule; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; @@ -443,8 +443,8 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { // privileged plugins CECoreExtensionsInstaller.class, - PrivilegedPluginsBootstraper.class, - PrivilegedPluginsStopper.class, + CoreExtensionBootstraper.class, + CoreExtensionStopper.class, // Compute engine (must be after Views and Developer Cockpit) CeConfigurationModule.class, 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 deleted file mode 100644 index 308acec9d5d..00000000000 --- a/server/sonar-plugin-bridge/src/main/java/org/sonar/plugin/PrivilegedPluginBridge.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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-server-common/src/main/java/org/sonar/server/extension/CoreExtensionBootstraper.java b/server/sonar-server-common/src/main/java/org/sonar/server/extension/CoreExtensionBootstraper.java new file mode 100644 index 00000000000..cef03abaa1e --- /dev/null +++ b/server/sonar-server-common/src/main/java/org/sonar/server/extension/CoreExtensionBootstraper.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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.extension; + +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 static java.lang.String.format; + +/** + * Startup task responsible to bootstrap installed Core Extensions (if any). + */ +public class CoreExtensionBootstraper implements ServerStartHandler { + private static final Logger LOGGER = Loggers.get(CoreExtensionBootstraper.class); + + private final ComponentContainer componentContainer; + + public CoreExtensionBootstraper(ComponentContainer componentContainer) { + this.componentContainer = componentContainer; + } + + @Override + public void onServerStart(Server server) { + List bridges = componentContainer.getComponentsByType(CoreExtensionBridge.class); + for (CoreExtensionBridge bridge : bridges) { + Profiler profiler = Profiler.create(LOGGER).startInfo(format("Bootstrapping %s", bridge.getPluginName())); + bridge.startPlugin(componentContainer); + profiler.stopInfo(); + } + } + +} diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/extension/CoreExtensionBridge.java b/server/sonar-server-common/src/main/java/org/sonar/server/extension/CoreExtensionBridge.java new file mode 100644 index 00000000000..008f0f9308e --- /dev/null +++ b/server/sonar-server-common/src/main/java/org/sonar/server/extension/CoreExtensionBridge.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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.extension; + +import org.sonar.core.platform.ComponentContainer; + +/** + * Interface implemented by the Extension point exposed by the Core Extensions that serves as the unique access + * point from the whole SQ instance into the Core Extension. + */ +public interface CoreExtensionBridge { + + 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-server-common/src/main/java/org/sonar/server/extension/CoreExtensionStopper.java b/server/sonar-server-common/src/main/java/org/sonar/server/extension/CoreExtensionStopper.java new file mode 100644 index 00000000000..17e61da6ce5 --- /dev/null +++ b/server/sonar-server-common/src/main/java/org/sonar/server/extension/CoreExtensionStopper.java @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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.extension; + +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 static java.lang.String.format; + +/** + * As an component of PlatformLevel4, this class is responsible for notifying shutdown to the installed Core Extensions + * (if any). + */ +public class CoreExtensionStopper implements Startable { + private static final Logger LOGGER = Loggers.get(CoreExtensionStopper.class); + + private final ComponentContainer platformContainer; + + public CoreExtensionStopper(ComponentContainer platformContainer) { + this.platformContainer = platformContainer; + } + + @Override + public void start() { + // nothing to do, privileged plugins are started by CoreExtensionBootstraper + } + + @Override + public void stop() { + List bridges = platformContainer.getComponentsByType(CoreExtensionBridge.class); + for (CoreExtensionBridge bridge : bridges) { + Profiler profiler = Profiler.create(LOGGER).startInfo(format("Stopping %s", bridge.getPluginName())); + bridge.stopPlugin(); + profiler.stopInfo(); + } + } +} diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/extension/package-info.java b/server/sonar-server-common/src/main/java/org/sonar/server/extension/package-info.java new file mode 100644 index 00000000000..92fa11fca90 --- /dev/null +++ b/server/sonar-server-common/src/main/java/org/sonar/server/extension/package-info.java @@ -0,0 +1,24 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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.extension; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/extension/CoreExtensionBootstraperTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/extension/CoreExtensionBootstraperTest.java new file mode 100644 index 00000000000..3b6029ed0ed --- /dev/null +++ b/server/sonar-server-common/src/test/java/org/sonar/server/extension/CoreExtensionBootstraperTest.java @@ -0,0 +1,54 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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.extension; + +import org.junit.Test; +import org.sonar.api.platform.Server; +import org.sonar.core.platform.ComponentContainer; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +public class CoreExtensionBootstraperTest { + private ComponentContainer componentContainer = new ComponentContainer(); + private CoreExtensionBridge bridge = mock(CoreExtensionBridge.class); + + private CoreExtensionBootstraper underTest = new CoreExtensionBootstraper(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-common/src/test/java/org/sonar/server/extension/CoreExtensionStopperTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/extension/CoreExtensionStopperTest.java new file mode 100644 index 00000000000..4f6b7911f6d --- /dev/null +++ b/server/sonar-server-common/src/test/java/org/sonar/server/extension/CoreExtensionStopperTest.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info 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.extension; + +import org.junit.Test; +import org.sonar.core.platform.ComponentContainer; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +public class CoreExtensionStopperTest { + private ComponentContainer componentContainer = new ComponentContainer(); + private CoreExtensionBridge bridge = mock(CoreExtensionBridge.class); + + private CoreExtensionStopper underTest = new CoreExtensionStopper(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/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 2794fc763c2..fa23da44099 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 @@ -67,6 +67,8 @@ import org.sonar.server.es.metadata.EsDbCompatibilityImpl; import org.sonar.server.es.metadata.MetadataIndex; import org.sonar.server.es.metadata.MetadataIndexDefinition; import org.sonar.server.event.NewAlerts; +import org.sonar.server.extension.CoreExtensionBootstraper; +import org.sonar.server.extension.CoreExtensionStopper; import org.sonar.server.favorite.FavoriteModule; import org.sonar.server.health.NodeHealthModule; import org.sonar.server.issue.AddTagsAction; @@ -137,8 +139,6 @@ import org.sonar.server.platform.ws.UpgradesAction; import org.sonar.server.plugins.PluginDownloader; import org.sonar.server.plugins.PluginUninstaller; import org.sonar.server.plugins.ServerExtensionInstaller; -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.DownloadAction; @@ -535,10 +535,10 @@ public class PlatformLevel4 extends PlatformLevel { // Project badges ProjectBadgesWsModule.class, - // privileged plugins + // Core Extensions WebCoreExtensionsInstaller.class, - PrivilegedPluginsBootstraper.class, - PrivilegedPluginsStopper.class, + CoreExtensionBootstraper.class, + CoreExtensionStopper.class, // Compute engine (must be after Views and Developer Cockpit) ReportAnalysisFailureNotificationModule.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 deleted file mode 100644 index 8a15ce091bb..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraper.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 deleted file mode 100644 index 3ca8e6db872..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/PrivilegedPluginsStopper.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 deleted file mode 100644 index 3f2755b47fc..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/privileged/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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/plugins/privileged/PrivilegedPluginsBootstraperTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraperTest.java deleted file mode 100644 index a68faa9391a..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsBootstraperTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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 deleted file mode 100644 index c54505e32ad..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/plugins/privileged/PrivilegedPluginsStopperTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info 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/PluginClassLoaderDef.java b/sonar-core/src/main/java/org/sonar/core/platform/PluginClassLoaderDef.java index f89683ce43a..c1c3584b58a 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/PluginClassLoaderDef.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/PluginClassLoaderDef.java @@ -46,8 +46,6 @@ class PluginClassLoaderDef { */ private boolean compatibilityMode = false; - private boolean privileged = false; - PluginClassLoaderDef(String basePluginKey) { Preconditions.checkArgument(!Strings.isNullOrEmpty(basePluginKey)); this.basePluginKey = basePluginKey; @@ -95,14 +93,6 @@ class PluginClassLoaderDef { this.compatibilityMode = b; } - boolean isPrivileged() { - return privileged; - } - - void setPrivileged(boolean privileged) { - this.privileged = privileged; - } - @Override public boolean equals(@Nullable Object o) { if (this == o) { diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PluginClassloaderFactory.java b/sonar-core/src/main/java/org/sonar/core/platform/PluginClassloaderFactory.java index 0706050fead..0c69f978a09 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/PluginClassloaderFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/PluginClassloaderFactory.java @@ -73,11 +73,7 @@ public class PluginClassloaderFactory { for (PluginClassLoaderDef def : defs) { builder.newClassloader(def.getBasePluginKey()); - if (def.isPrivileged()) { - builder.setParent(def.getBasePluginKey(), baseClassLoader, new Mask()); - } else { - builder.setParent(def.getBasePluginKey(), API_CLASSLOADER_KEY, new Mask()); - } + builder.setParent(def.getBasePluginKey(), API_CLASSLOADER_KEY, new Mask()); builder.setLoadingOrder(def.getBasePluginKey(), def.isSelfFirstStrategy() ? SELF_FIRST : PARENT_FIRST); for (File jar : def.getFiles()) { builder.addURL(def.getBasePluginKey(), fileToUrl(jar)); diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java b/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java index 593adca7a73..f44a346336e 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java @@ -24,16 +24,13 @@ import com.google.common.base.Strings; import java.io.Closeable; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import org.apache.commons.lang.SystemUtils; import org.sonar.api.Plugin; import org.sonar.api.utils.log.Loggers; import org.sonar.updatecenter.common.Version; import static java.util.Arrays.asList; -import static java.util.Collections.unmodifiableSet; /** * Loads the plugin JAR files by creating the appropriate classloaders and by instantiating @@ -52,11 +49,6 @@ import static java.util.Collections.unmodifiableSet; public class PluginLoader { private static final String[] DEFAULT_SHARED_RESOURCES = {"org/sonar/plugins", "com/sonar/plugins", "com/sonarsource/plugins"}; - /** - * Defines the base keys (defined by {@link #basePluginKey(PluginInfo, Map)}) of the plugins which are allowed to - * run a full server extensions. - */ - private static final Set PRIVILEGED_PLUGINS_BASE_KEYS = unmodifiableSet(new HashSet<>(asList("billing", "branch", "developer", "governance", "ha", "license"))); public static final Version COMPATIBILITY_MODE_MAX_VERSION = Version.create("5.2"); @@ -105,7 +97,6 @@ public class PluginLoader { Version minSqVersion = info.getMinimalSqVersion(); boolean compatibilityMode = minSqVersion != null && minSqVersion.compareToIgnoreQualifier(COMPATIBILITY_MODE_MAX_VERSION) < 0; def.setCompatibilityMode(compatibilityMode); - def.setPrivileged(isPrivileged(baseKey)); if (compatibilityMode) { Loggers.get(getClass()).debug("API compatibility mode is enabled on plugin {} [{}] " + "(built with API lower than {})", @@ -116,10 +107,6 @@ public class PluginLoader { return classloadersByBasePlugin.values(); } - private static boolean isPrivileged(String basePluginKey) { - return PRIVILEGED_PLUGINS_BASE_KEYS.contains(basePluginKey); - } - /** * Instantiates collection of {@link org.sonar.api.Plugin} according to given metadata and classloaders * diff --git a/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java b/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java index 58e3d6fd5d5..432296e40fc 100644 --- a/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/platform/PluginLoaderTest.java @@ -147,15 +147,6 @@ public class PluginLoaderTest { // TODO test mask - require change in sonar-classloader } - @Test - public void plugin_is_recognised_as_privileged_if_key_is_views_and_extends_no_other_plugins() throws IOException { - PluginInfo governance = createPluginInfo("governance"); - - Collection defs = loader.defineClassloaders(ImmutableMap.of("governance", governance)); - - assertThat(defs.iterator().next().isPrivileged()).isTrue(); - } - @Test public void plugin_is_not_recognised_as_system_extension_if_key_is_governance_and_extends_another_plugin() throws IOException { PluginInfo foo = createPluginInfo("foo"); diff --git a/tests/plugins/fake-billing-plugin/src/main/java/FakeBillingPlugin.java b/tests/plugins/fake-billing-plugin/src/main/java/FakeBillingPlugin.java index 6aab3e55223..97a4e8053d6 100644 --- a/tests/plugins/fake-billing-plugin/src/main/java/FakeBillingPlugin.java +++ b/tests/plugins/fake-billing-plugin/src/main/java/FakeBillingPlugin.java @@ -52,7 +52,7 @@ public class FakeBillingPlugin implements Plugin { private static boolean isRunningInSQ() { try { - Class.forName("org.sonar.plugin.PrivilegedPluginBridge"); + Class.forName("org.sonar.server.plugins.privileged.CoreExtensionBridge"); return true; } catch (ClassNotFoundException e) { return false; diff --git a/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java b/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java index b656d46f524..df27964476e 100644 --- a/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java +++ b/tests/plugins/fake-governance-plugin/src/main/java/FakeGovernancePlugin.java @@ -62,7 +62,7 @@ public class FakeGovernancePlugin implements Plugin { private static boolean isRunningInSQ() { try { - Class.forName("org.sonar.plugin.PrivilegedPluginBridge"); + Class.forName("org.sonar.server.plugins.privileged.CoreExtensionBridge"); return true; } catch (ClassNotFoundException e) { return false;