From be56575b34b2d16d3486a754145a2478908765fe Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Tue, 22 Sep 2015 13:18:30 +0200 Subject: [PATCH] Fix WS suffix management --- .../org/sonar/server/scanner/Messages.java | 6 +- .../org/sonar/server/util/ObjectUtils.java | 62 ------------------- .../org/sonar/server/ws/ServletRequest.java | 7 ++- .../app/controllers/api/java_ws_controller.rb | 2 +- .../webapp/WEB-INF/lib/java_ws_routing.rb | 1 + 5 files changed, 10 insertions(+), 68 deletions(-) delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/util/ObjectUtils.java diff --git a/server/sonar-server/src/main/java/org/sonar/server/scanner/Messages.java b/server/sonar-server/src/main/java/org/sonar/server/scanner/Messages.java index 5d7f085d242..dc49b0d7b48 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/scanner/Messages.java +++ b/server/sonar-server/src/main/java/org/sonar/server/scanner/Messages.java @@ -19,8 +19,10 @@ */ package org.sonar.server.scanner; -public interface Messages { +public class Messages { + private Messages() { + // constants + } String NO_PERMISSION = "You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator."; - } diff --git a/server/sonar-server/src/main/java/org/sonar/server/util/ObjectUtils.java b/server/sonar-server/src/main/java/org/sonar/server/util/ObjectUtils.java deleted file mode 100644 index f5f7542b314..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/util/ObjectUtils.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.server.util; - -public class ObjectUtils { - private ObjectUtils() { - // static utility methods only - } - - /** - * Taken from http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/src-html/org/apache/commons/lang3/ObjectUtils.html#line.119 - * - *

Returns the first value in the array which is not {@code null}. - * If all the values are {@code null} or the array is {@code null} - * or empty then {@code null} is returned.

- * - *
-    * ObjectUtils.firstNonNull(null, null)      = null
-    * ObjectUtils.firstNonNull(null, "")        = ""
-    * ObjectUtils.firstNonNull(null, null, "")  = ""
-    * ObjectUtils.firstNonNull(null, "zz")      = "zz"
-    * ObjectUtils.firstNonNull("abc", *)        = "abc"
-    * ObjectUtils.firstNonNull(null, "xyz", *)  = "xyz"
-    * ObjectUtils.firstNonNull(Boolean.TRUE, *) = Boolean.TRUE
-    * ObjectUtils.firstNonNull()                = null
-    * 
- * - * @param the component type of the array - * @param values the values to test, may be {@code null} or empty - * @return the first value from {@code values} which is not {@code null}, - * or {@code null} if there are no non-null values - * @since 3.0 - */ - public static T firstNonNull(T... values) { - if (values != null) { - for (T val : values) { - if (val != null) { - return val; - } - } - } - return null; - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/ServletRequest.java b/server/sonar-server/src/main/java/org/sonar/server/ws/ServletRequest.java index 931de1d6beb..4ae04e47905 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/ServletRequest.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/ServletRequest.java @@ -29,7 +29,7 @@ import org.jruby.RubyFile; import org.sonar.api.server.ws.internal.ValidatingRequest; import org.sonar.server.plugins.MimeTypes; -import static org.sonar.server.util.ObjectUtils.firstNonNull; +import static com.google.common.base.Objects.firstNonNull; public class ServletRequest extends ValidatingRequest { @@ -54,8 +54,9 @@ public class ServletRequest extends ValidatingRequest { public String getMediaType() { return firstNonNull( mediaTypeFromUrl(source.getRequestURI()), - acceptedContentTypeInResponse(), - MimeTypes.DEFAULT); + firstNonNull( + acceptedContentTypeInResponse(), + MimeTypes.DEFAULT)); } @Override diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/java_ws_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/java_ws_controller.rb index 7ee7e580709..1855d30d915 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/java_ws_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/java_ws_controller.rb @@ -49,7 +49,7 @@ class Api::JavaWsController < Api::ApiController def skip_authentication_check_for_batch - (params[:wspath]=='batch' && params[:wsaction]=='index') || (params[:wspath]=='batch' && params[:wsaction]=='file') + (params[:wspath]=='scanner' && params[:wsaction]=='index') || (params[:wspath]=='scanner' && params[:wsaction]=='file') end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/lib/java_ws_routing.rb b/server/sonar-web/src/main/webapp/WEB-INF/lib/java_ws_routing.rb index 741cce8bf45..258de4f5b4a 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/lib/java_ws_routing.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/lib/java_ws_routing.rb @@ -34,6 +34,7 @@ module ActionController ws_engine.controllers().each do |controller| controller.actions.each do |action| if (!action.handler().java_kind_of?(Java::OrgSonarApiServerWs::RailsHandler)) + prepend_route("#{controller.path()}/#{action.key()}.:format/:id", {:controller => 'api/java_ws', :action => 'index', :wsaction => action.key(), :wspath => controller.path()}) prepend_route("#{controller.path()}/#{action.key()}/:id", {:controller => 'api/java_ws', :action => 'index', :wsaction => action.key(), :wspath => controller.path()}) if action.key()=='index' prepend_route("#{controller.path()}", {:controller => 'api/java_ws', :action => 'index', :wsaction => action.key(), :wspath => controller.path()}) -- 2.39.5