diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-10-05 14:01:24 +0200 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-10-05 14:02:48 +0200 |
commit | 1dd375690cf8f15bdb5795539676be7f4373a17f (patch) | |
tree | 2ecdd4c03628e5d45c904be6cd71633eb6a53af4 /server/sonar-server | |
parent | c3419c08d143160a17ecfd60af90033f5c7c43a6 (diff) | |
download | sonarqube-1dd375690cf8f15bdb5795539676be7f4373a17f.tar.gz sonarqube-1dd375690cf8f15bdb5795539676be7f4373a17f.zip |
Fix WS qualityprofiles/restore when a language is not found by language key
Diffstat (limited to 'server/sonar-server')
2 files changed, 24 insertions, 12 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java index efd1ac9fde2..fcf810a63c3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java @@ -25,6 +25,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; +import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; @@ -90,15 +91,20 @@ public class OldRestoreAction implements WsAction { private void writeResponse(JsonWriter json, BulkChangeResult result) { QualityProfileDto profile = result.profile(); if (profile != null) { - String language = profile.getLanguage(); - json.beginObject().name("profile").beginObject() + String languageKey = profile.getLanguage(); + Language language = languages.get(languageKey); + + JsonWriter jsonProfile = json.beginObject().name("profile").beginObject(); + jsonProfile .prop("key", profile.getKey()) .prop("name", profile.getName()) - .prop("language", language) - .prop("languageName", languages.get(profile.getLanguage()).getName()) + .prop("language", languageKey) .prop("isDefault", false) - .prop("isInherited", false) - .endObject(); + .prop("isInherited", false); + if (language != null) { + jsonProfile.prop("languageName", language.getName()); + } + jsonProfile.endObject(); } json.prop("ruleSuccesses", result.countSucceeded()); json.prop("ruleFailures", result.countFailed()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java index 175031e6dfa..a05dba18c67 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java @@ -21,6 +21,7 @@ package org.sonar.server.qualityprofile.ws; import com.google.common.base.Preconditions; import org.apache.commons.io.IOUtils; +import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; @@ -83,15 +84,20 @@ public class RestoreAction implements QProfileWsAction { private void writeResponse(JsonWriter json, BulkChangeResult result) { QualityProfileDto profile = result.profile(); if (profile != null) { - String language = profile.getLanguage(); - json.beginObject().name("profile").beginObject() + String languageKey = profile.getLanguage(); + Language language = languages.get(languageKey); + + JsonWriter jsonProfile = json.beginObject().name("profile").beginObject(); + jsonProfile .prop("key", profile.getKey()) .prop("name", profile.getName()) - .prop("language", language) - .prop("languageName", languages.get(profile.getLanguage()).getName()) + .prop("language", languageKey) .prop("isDefault", false) - .prop("isInherited", false) - .endObject(); + .prop("isInherited", false); + if (language != null) { + jsonProfile.prop("languageName", language.getName()); + } + jsonProfile.endObject(); } json.prop("ruleSuccesses", result.countSucceeded()); json.prop("ruleFailures", result.countFailed()); |