From 919955b34e8c92cd2572a42d276db4445e982c6c Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 19 Jan 2017 09:29:40 +0100 Subject: [PATCH] SONAR-6506 Delete internal WS api/updatecenter/installed_plugins --- .../it/updateCenter/UpdateCenterTest.java | 34 --------- .../updatecenter/ws/UpdateCenterWs.java | 21 +----- .../updatecenter/ws/UpdateCenterWsTest.java | 17 +---- .../api/updatecenter_controller.rb | 70 ------------------- 4 files changed, 4 insertions(+), 138 deletions(-) delete mode 100644 server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/updatecenter_controller.rb diff --git a/it/it-tests/src/test/java/it/updateCenter/UpdateCenterTest.java b/it/it-tests/src/test/java/it/updateCenter/UpdateCenterTest.java index a2f1c80cf5a..849ff01fcb6 100644 --- a/it/it-tests/src/test/java/it/updateCenter/UpdateCenterTest.java +++ b/it/it-tests/src/test/java/it/updateCenter/UpdateCenterTest.java @@ -20,20 +20,12 @@ package it.updateCenter; import com.sonar.orchestrator.Orchestrator; -import java.util.List; -import org.apache.commons.lang.StringUtils; import org.junit.After; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.sonar.wsclient.Host; -import org.sonar.wsclient.Sonar; -import org.sonar.wsclient.connectors.HttpClient4Connector; -import org.sonar.wsclient.services.Plugin; -import org.sonar.wsclient.services.UpdateCenterQuery; import util.user.UserRule; -import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.pluginArtifact; import static util.selenium.Selenese.runSelenese; @@ -42,7 +34,6 @@ import static util.selenium.Selenese.runSelenese; */ public class UpdateCenterTest { - @ClassRule public static final Orchestrator orchestrator = Orchestrator.builderEnv() .setServerProperty("sonar.updatecenter.url", UpdateCenterTest.class.getResource("/updateCenter/UpdateCenterTest/update-center.properties").toString()) @@ -56,34 +47,9 @@ public class UpdateCenterTest { userRule.resetUsers(); } - @Test - public void web_service_installed_plugins_requires_root_and_returns_installed_plugins() { - userRule.createUser("new_root", "bar"); - userRule.setRoot("new_root"); - - Sonar newRootSonarWsClient = new Sonar(new HttpClient4Connector(new Host(orchestrator.getServer().getUrl(), "new_root", "bar"))); - List < Plugin > plugins = newRootSonarWsClient.findAll(UpdateCenterQuery.createForInstalledPlugins()); - assertThat(plugins.size()).isGreaterThan(0); - - Plugin installedPlugin = findPlugin(plugins, "fake"); - - assertThat(installedPlugin).isNotNull(); - assertThat(installedPlugin.getName()).isEqualTo("Plugins :: Fake"); - assertThat(installedPlugin.getVersion()).isEqualTo("1.0-SNAPSHOT"); - } - @Test public void test_console() { runSelenese(orchestrator, "/updateCenter/installed-plugins.html"); } - private Plugin findPlugin(List plugins, String pluginKey) { - for (Plugin plugin : plugins) { - if (StringUtils.equals(pluginKey, plugin.getKey())) { - return plugin; - } - } - return null; - } - } diff --git a/server/sonar-server/src/main/java/org/sonar/server/updatecenter/ws/UpdateCenterWs.java b/server/sonar-server/src/main/java/org/sonar/server/updatecenter/ws/UpdateCenterWs.java index b311da9ac4e..63abf653419 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/updatecenter/ws/UpdateCenterWs.java +++ b/server/sonar-server/src/main/java/org/sonar/server/updatecenter/ws/UpdateCenterWs.java @@ -19,8 +19,7 @@ */ package org.sonar.server.updatecenter.ws; -import com.google.common.io.Resources; -import org.sonar.api.server.ws.RailsHandler; +import java.util.Arrays; import org.sonar.api.server.ws.WebService; public class UpdateCenterWs implements WebService { @@ -36,23 +35,7 @@ public class UpdateCenterWs implements WebService { NewController controller = context.createController("api/updatecenter") .setDescription("Get list of installed plugins") .setSince("2.10"); - - defineInstalledPluginsAction(controller); - for (UpdateCenterWsAction action : actions) { - action.define(controller); - } - + Arrays.stream(actions).forEach(action -> action.define(controller)); controller.done(); } - - private void defineInstalledPluginsAction(NewController controller) { - NewAction action = controller.createAction("installed_plugins") - .setDescription("Get the list of all the plugins installed on the SonarQube instance") - .setSince("2.10") - .setHandler(RailsHandler.INSTANCE) - .setInternal(true) - .setResponseExample(Resources.getResource(this.getClass(), "example-installed_plugins.json")); - RailsHandler.addFormatParam(action); - } - } diff --git a/server/sonar-server/src/test/java/org/sonar/server/updatecenter/ws/UpdateCenterWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/updatecenter/ws/UpdateCenterWsTest.java index 0d25e12ba8d..6bd21995134 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/updatecenter/ws/UpdateCenterWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/updatecenter/ws/UpdateCenterWsTest.java @@ -21,7 +21,6 @@ package org.sonar.server.updatecenter.ws; import org.junit.Before; import org.junit.Test; -import org.sonar.api.server.ws.RailsHandler; import org.sonar.api.server.ws.WebService; import org.sonar.server.platform.ServerFileSystem; import org.sonar.server.ws.WsTester; @@ -35,8 +34,7 @@ public class UpdateCenterWsTest { @Before public void setUp() { - tester = new WsTester(new UpdateCenterWs( - new UploadAction(null, mock(ServerFileSystem.class)))); + tester = new WsTester(new UpdateCenterWs(new UploadAction(null, mock(ServerFileSystem.class)))); } @Test @@ -45,18 +43,7 @@ public class UpdateCenterWsTest { assertThat(controller).isNotNull(); assertThat(controller.since()).isEqualTo("2.10"); assertThat(controller.description()).isNotEmpty(); - assertThat(controller.actions()).hasSize(2); - } - - @Test - public void define_installed_plugins_action() { - WebService.Controller controller = tester.controller("api/updatecenter"); - - WebService.Action action = controller.action("installed_plugins"); - assertThat(action).isNotNull(); - assertThat(action.handler()).isInstanceOf(RailsHandler.class); - assertThat(action.responseExampleAsString()).isNotEmpty(); - assertThat(action.params()).hasSize(1); + assertThat(controller.actions()).hasSize(1); } @Test diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/updatecenter_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/updatecenter_controller.rb deleted file mode 100644 index 4819403d2e8..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/updatecenter_controller.rb +++ /dev/null @@ -1,70 +0,0 @@ -# -# SonarQube, open source software quality management tool. -# Copyright (C) 2008-2016 SonarSource -# mailto:contact AT sonarsource DOT com -# -# SonarQube is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# SonarQube is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -require 'json' - -class Api::UpdatecenterController < Api::ApiController - - # - # GET /api/updatecenter/installed_plugins - # curl http://localhost:9000/api/updatecenter/installed_plugins -v - # - def installed_plugins - respond_to do |format| - format.json { render :json => jsonp(plugins_to_json(user_plugins())) } - format.xml { render :xml => plugins_to_xml(user_plugins()) } - format.text { render :text => text_not_supported } - end - end - - private - - def plugins_to_json(plugins=[]) - json=[] - plugins.each do |p| - json< 0)) - xml.plugins do - plugins.each do |plugin| - xml.plugin do - xml.key(plugin.getKey()) - xml.name(plugin.getName()) - xml.version(plugin.getVersion().getName()) - end - end - end - end - - def user_plugins - java_facade.getPluginInfos().to_a.sort - end -end -- 2.39.5