From df07474a15ceb5767167ec75fe1c3e538756417e Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 19 Jan 2017 09:17:44 +0100 Subject: [PATCH] SONAR-6309 Delete WS api/profiles/list --- .../server/qualityprofile/ws/ProfilesWs.java | 20 +-- .../qualityprofile/ws/ProfilesWsTest.java | 8 +- .../controllers/api/profiles_controller.rb | 158 ------------------ 3 files changed, 8 insertions(+), 178 deletions(-) delete mode 100644 server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java index cff23525c98..0ecb585ae05 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java @@ -20,12 +20,9 @@ package org.sonar.server.qualityprofile.ws; import com.google.common.io.Resources; -import org.sonar.api.server.ws.RailsHandler; import org.sonar.api.server.ws.WebService; import org.sonar.server.ws.RemovedWebServiceHandler; -import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; - /** * List of quality profiles WS implemented in Rails. * New WS on quality profiles MUST be declared in {@link org.sonar.server.qualityprofile.ws.QProfilesWs} @@ -43,7 +40,7 @@ public class ProfilesWs implements WebService { @Override public void define(Context context) { NewController controller = context.createController(API_ENDPOINT) - .setDescription("Manage quality profiles. Deprecated since 5.2.") + .setDescription("Removed since 6.3, please use api/qualityprofiles instead") .setSince("4.4"); restoreAction.define(controller); defineListAction(controller); @@ -62,19 +59,12 @@ public class ProfilesWs implements WebService { } private static void defineListAction(NewController controller) { - WebService.NewAction action = controller.createAction("list") - .setDescription("Get a list of profiles.") + controller.createAction("list") + .setDescription("Get a list of profiles.
" + + "The web service is removed and you're invited to use api/qualityprofiles/search instead") .setSince("3.3") .setDeprecatedSince("5.2") - .setHandler(RailsHandler.INSTANCE) + .setHandler(RemovedWebServiceHandler.INSTANCE) .setResponseExample(Resources.getResource(ProfilesWs.class, "example-list.json")); - - action.createParam("language") - .setDescription("Profile language") - .setExampleValue("java"); - action.createParam("project") - .setDescription("Project key or id") - .setExampleValue(KEY_PROJECT_EXAMPLE_001); - RailsHandler.addJsonOnlyFormatParam(action); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java index 024c26887af..47874b83e0e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java @@ -22,7 +22,6 @@ package org.sonar.server.qualityprofile.ws; import org.junit.Before; import org.junit.Test; import org.sonar.api.resources.Languages; -import org.sonar.api.server.ws.RailsHandler; import org.sonar.api.server.ws.WebService; import org.sonar.server.qualityprofile.QProfileBackuper; import org.sonar.server.user.UserSession; @@ -39,8 +38,7 @@ public class ProfilesWsTest { @Before public void setUp() { ws = new WsTester(new ProfilesWs( - new OldRestoreAction(mock(QProfileBackuper.class), mock(Languages.class), mock(UserSession.class)) - )); + new OldRestoreAction(mock(QProfileBackuper.class), mock(Languages.class), mock(UserSession.class)))); } @Test @@ -69,9 +67,9 @@ public class ProfilesWsTest { WebService.Action listProfiles = controller.action("list"); assertThat(listProfiles).isNotNull(); - assertThat(listProfiles.handler()).isInstanceOf(RailsHandler.class); + assertThat(listProfiles.handler()).isInstanceOf(RemovedWebServiceHandler.class); assertThat(listProfiles.responseExampleAsString()).isNotEmpty(); - assertThat(listProfiles.params()).hasSize(3); + assertThat(listProfiles.params()).isEmpty(); } private WebService.Controller controller() { diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb deleted file mode 100644 index d2d399038c0..00000000000 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/profiles_controller.rb +++ /dev/null @@ -1,158 +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::ProfilesController < Api::ApiController - - # GET /api/profiles/list?[language=] - # - # Since v.3.3 - # - # ==== Examples - # - get all the profiles : GET /api/profiles/list - # - get all the Java profiles : GET /api/profiles/list?language=java - # - get the profiles used by the project 'foo' : GET /api/profiles/list?project=foo - # - get the Java profile used by the project 'foo' : GET /api/profiles/list?project=foo&language=java - def list - language = params[:language] - project_key = params[:project] - - profiles = [] - default_profile_by_language = {} - if project_key.present? - project = Project.by_key(project_key) - not_found('Unknown project') unless project - if language.present? - default_profile_by_language[language] = Internal.qprofile_service.getDefault(language) - profile = Internal.quality_profiles.findProfileByProjectAndLanguage(project.id, language) - profiles << profile if profile - # Return default profile if the project is not associate to a profile - profiles << default_profile_by_language[language] unless profile - else - Api::Utils.languages.each do |language| - default_profile_by_language[language.getKey()] = Internal.qprofile_service.getDefault(language.getKey()) - profile = Internal.quality_profiles.findProfileByProjectAndLanguage(project.id, language.getKey()) - profiles << profile if profile - # Return default profile if the project is not associate to a profile - profiles << default_profile_by_language[language.getKey()] unless profile - end - end - elsif language.present? - profiles = Internal.quality_profiles.profilesByLanguage(language).to_a - else - profiles = Internal.quality_profiles.allProfiles().to_a - end - - # Populate the map of default profile by language by searching for all profiles languages - # We have to do that as the profiles list do not contain this information (maybe we should add it?) - profiles.each do |p| - lang = p.language - unless default_profile_by_language[lang] - default_profile_by_language[lang] = Internal.qprofile_service.getDefault(lang.to_s) - end - end - - json = profiles.compact.map { |profile| { - :key => profile.key, - :name => profile.name, - :language => profile.language, - :default => default_profile_by_language[profile.language].name == profile.name - } } - respond_to do |format| - format.json { render :json => jsonp(json) } - format.xml { render :xml => xml_not_supported } - format.text { render :text => text_not_supported } - end - end - - - private - - def filter_rules - conditions=['active_rules.profile_id=?'] - condition_values=[@profile.id] - - if params[:rule_repositories].present? - conditions<<'rules.plugin_name in (?)' - condition_values< [:rule, {:active_rule_parameters => :rules_parameter}], :conditions => [conditions.join(' AND ')].concat(condition_values)) - end - - def to_json - result={} - result[:name]=@profile.name - result[:language]=@profile.language - result[:parent]=@profile.parent_kee if @profile.parent_kee.present? - result[:default]=@profile.default_profile? - - rules=[] - @active_rules.each do |active_rule| - hash={} - hash[:key]=active_rule.rule.plugin_rule_key - hash[:repo]=active_rule.rule.plugin_name - hash[:severity]=active_rule.priority_text - hash[:inheritance]=active_rule.inheritance if active_rule.inheritance - params_hash=[] - active_rule.active_rule_parameters.each do |param| - params_hash<<{:key => param.name, :value => param.value} - end - hash[:params]=params_hash unless params_hash.empty? - rules< 0) - xml.instruct! - - xml.profile do - xml.name(@profile.name) - xml.language(@profile.language) - xml.parent(@profile.parent_kee) if @profile.parent_kee.present? - xml.default(@profile.default_profile?) - - @active_rules.each do |active_rule| - xml.rule do - xml.key(active_rule.rule.plugin_rule_key) - xml.repo(active_rule.rule.plugin_name) - xml.severity(active_rule.priority_text) - xml.inheritance(active_rule.inheritance) if active_rule.inheritance - active_rule.active_rule_parameters.each do |param| - xml.param do - xml.key(param.name) - xml.value(param.value) - end - end - end - end - end - end - -end -- 2.39.5