@@ -52,7 +52,7 @@ import static org.sonar.core.util.Protobuf.setNullable; | |||
import static org.sonar.core.util.stream.MoreCollectors.toHashSet; | |||
import static org.sonar.server.es.SearchOptions.MAX_LIMIT; | |||
import static org.sonar.server.util.LanguageParamUtils.getExampleValue; | |||
import static org.sonar.server.util.LanguageParamUtils.getLanguageKeys; | |||
import static org.sonar.server.util.LanguageParamUtils.getOrderedLanguageKeys; | |||
import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; | |||
import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
@@ -107,7 +107,7 @@ public class SearchAction implements ComponentsWsAction { | |||
.createParam(PARAM_LANGUAGE) | |||
.setDescription("Language key. If provided, only components for the given language are returned.") | |||
.setExampleValue(getExampleValue(languages)) | |||
.setPossibleValues(getLanguageKeys(languages)); | |||
.setPossibleValues(getOrderedLanguageKeys(languages)); | |||
createQualifiersParameter(action, newQualifierParameterContext(i18n, resourceTypes)) | |||
.setRequired(true); | |||
} |
@@ -43,7 +43,7 @@ import javax.annotation.Nullable; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES; | |||
import static org.sonar.server.qualityprofile.ws.QProfileWsSupport.createOrganizationParam; | |||
import static org.sonar.server.util.LanguageParamUtils.getLanguageKeys; | |||
import static org.sonar.server.util.LanguageParamUtils.getOrderedLanguageKeys; | |||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | |||
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.ACTION_CREATE; | |||
import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE; | |||
@@ -105,7 +105,7 @@ public class CreateAction implements QProfileWsAction { | |||
.setRequired(true) | |||
.setDescription("Quality profile language") | |||
.setExampleValue("js") | |||
.setPossibleValues(getLanguageKeys(languages)); | |||
.setPossibleValues(getOrderedLanguageKeys(languages)); | |||
for (ProfileImporter importer : importers) { | |||
create.createParam(getBackupParamName(importer.getKey())) |
@@ -94,7 +94,7 @@ public class ExportAction implements QProfileWsAction { | |||
action.createParam(PARAM_LANGUAGE) | |||
.setDescription("Quality profile language") | |||
.setExampleValue(LanguageParamUtils.getExampleValue(languages)) | |||
.setPossibleValues(LanguageParamUtils.getLanguageKeys(languages)); | |||
.setPossibleValues(LanguageParamUtils.getOrderedLanguageKeys(languages)); | |||
createOrganizationParam(action) | |||
.setSince("6.4"); |
@@ -120,7 +120,7 @@ public class SearchAction implements QProfileWsAction { | |||
action | |||
.createParam(PARAM_LANGUAGE) | |||
.setDescription("Language key. If provided, only profiles for the given language are returned.") | |||
.setPossibleValues(LanguageParamUtils.getLanguageKeys(languages)); | |||
.setPossibleValues(LanguageParamUtils.getOrderedLanguageKeys(languages)); | |||
action.createParam(PARAM_QUALITY_PROFILE) | |||
.setDescription("Quality profile name") |
@@ -19,13 +19,11 @@ | |||
*/ | |||
package org.sonar.server.util; | |||
import com.google.common.base.Function; | |||
import com.google.common.collect.Collections2; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
import javax.annotation.Nonnull; | |||
import java.util.List; | |||
import org.sonar.api.resources.Language; | |||
import org.sonar.api.resources.Languages; | |||
import org.sonar.core.util.stream.MoreCollectors; | |||
public class LanguageParamUtils { | |||
@@ -42,16 +40,11 @@ public class LanguageParamUtils { | |||
} | |||
} | |||
public static Collection<String> getLanguageKeys(Languages languages) { | |||
return Collections2.transform(Arrays.asList(languages.all()), LanguageToKeyFunction.INSTANCE); | |||
} | |||
private enum LanguageToKeyFunction implements Function<Language, java.lang.String> { | |||
INSTANCE; | |||
@Override | |||
public String apply(@Nonnull Language input) { | |||
return input.getKey(); | |||
} | |||
public static List<String> getOrderedLanguageKeys(Languages languages) { | |||
Language[] all = languages.all(); | |||
return Arrays.stream(all) | |||
.map(Language::getKey) | |||
.sorted() | |||
.collect(MoreCollectors.toList(all.length)); | |||
} | |||
} |
@@ -0,0 +1,52 @@ | |||
/* | |||
* 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.util; | |||
import org.junit.Test; | |||
import org.sonar.api.resources.AbstractLanguage; | |||
import org.sonar.api.resources.Languages; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class LanguageParamUtilsTest { | |||
@Test | |||
public void getOrderedLanguageKeys() { | |||
assertThat(LanguageParamUtils.getOrderedLanguageKeys(new Languages())).isEmpty(); | |||
Languages languages = new Languages( | |||
new TestLanguage("java"), | |||
new TestLanguage("abap"), | |||
new TestLanguage("js"), | |||
new TestLanguage("cobol")); | |||
assertThat(LanguageParamUtils.getOrderedLanguageKeys(languages)).containsExactly("abap", "cobol", "java", "js"); | |||
} | |||
private static class TestLanguage extends AbstractLanguage { | |||
TestLanguage(String key) { | |||
super(key); | |||
} | |||
@Override | |||
public String[] getFileSuffixes() { | |||
return new String[0]; | |||
} | |||
} | |||
} |