Search in sources :

Example 6 with Language

use of org.sonar.api.resources.Language in project sonarqube by SonarSource.

the class RestoreAction method writeResponse.

private void writeResponse(JsonWriter json, BulkChangeResult result) {
    QualityProfileDto profile = result.profile();
    if (profile != null) {
        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", languageKey).prop("isDefault", false).prop("isInherited", false);
        if (language != null) {
            jsonProfile.prop("languageName", language.getName());
        }
        jsonProfile.endObject();
    }
    json.prop("ruleSuccesses", result.countSucceeded());
    json.prop("ruleFailures", result.countFailed());
    json.endObject().close();
}
Also used : Language(org.sonar.api.resources.Language) JsonWriter(org.sonar.api.utils.text.JsonWriter) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

Example 7 with Language

use of org.sonar.api.resources.Language in project sonarqube by SonarSource.

the class AppAction method addLanguages.

private void addLanguages(JsonWriter json) {
    json.name("languages").beginObject();
    for (Language language : languages.all()) {
        json.prop(language.getKey(), language.getName());
    }
    json.endObject();
}
Also used : Language(org.sonar.api.resources.Language)

Example 8 with Language

use of org.sonar.api.resources.Language in project sonarqube by SonarSource.

the class RuleMapper method setLanguageName.

private void setLanguageName(Rules.Rule.Builder ruleResponse, RuleDto ruleDto, Set<String> fieldsToReturn) {
    if (shouldReturnField(fieldsToReturn, FIELD_LANGUAGE_NAME) && ruleDto.getLanguage() != null) {
        String languageKey = ruleDto.getLanguage();
        Language language = languages.get(languageKey);
        ruleResponse.setLangName(language == null ? languageKey : language.getName());
    }
}
Also used : Language(org.sonar.api.resources.Language)

Example 9 with Language

use of org.sonar.api.resources.Language in project sonarqube by SonarSource.

the class WsResponseCommonFormat method formatRule.

public Common.Rule.Builder formatRule(RuleDto rule) {
    Common.Rule.Builder builder = Common.Rule.newBuilder().setKey(rule.getKey().toString()).setName(nullToEmpty(rule.getName())).setStatus(Common.RuleStatus.valueOf(rule.getStatus().name()));
    builder.setLang(nullToEmpty(rule.getLanguage()));
    Language lang = languages.get(rule.getLanguage());
    if (lang != null) {
        builder.setLangName(lang.getName());
    }
    return builder;
}
Also used : Language(org.sonar.api.resources.Language)

Example 10 with Language

use of org.sonar.api.resources.Language in project sonarqube by SonarSource.

the class QualityProfileEventsStepTest method mockLanguageInRepository.

private Language mockLanguageInRepository(String languageKey) {
    Language language = new AbstractLanguage(languageKey, languageKey + "_name") {

        @Override
        public String[] getFileSuffixes() {
            return new String[0];
        }
    };
    when(languageRepository.find(languageKey)).thenReturn(Optional.of(language));
    return language;
}
Also used : AbstractLanguage(org.sonar.api.resources.AbstractLanguage) Language(org.sonar.api.resources.Language) AbstractLanguage(org.sonar.api.resources.AbstractLanguage) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

Language (org.sonar.api.resources.Language)17 Test (org.junit.Test)4 AbstractLanguage (org.sonar.api.resources.AbstractLanguage)4 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)4 JsonWriter (org.sonar.api.utils.text.JsonWriter)3 QualityProfile (org.sonar.server.qualityprofile.QualityProfile)3 Locale (java.util.Locale)1 Pattern (java.util.regex.Pattern)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Languages (org.sonar.api.resources.Languages)1 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)1 RuleRepositoryDto (org.sonar.db.rule.RuleRepositoryDto)1 WsTester (org.sonar.server.ws.WsTester)1