Search in sources :

Example 1 with Language

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

the class ActiveRuleCompleter method writeProfile.

private void writeProfile(Map<String, Rules.QProfile> profilesResponse, QualityProfileDto profile) {
    Rules.QProfile.Builder profileResponse = Rules.QProfile.newBuilder();
    if (profile.getName() != null) {
        profileResponse.setName(profile.getName());
    }
    if (profile.getLanguage() != null) {
        profileResponse.setLang(profile.getLanguage());
        Language language = languages.get(profile.getLanguage());
        String langName = language == null ? profile.getLanguage() : language.getName();
        profileResponse.setLangName(langName);
    }
    if (profile.getParentKee() != null) {
        profileResponse.setParent(profile.getParentKee());
    }
    profilesResponse.put(profile.getKey(), profileResponse.build());
}
Also used : Language(org.sonar.api.resources.Language)

Example 2 with Language

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

the class OldRestoreAction 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 3 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 4 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 5 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)

Aggregations

Language (org.sonar.api.resources.Language)33 Test (org.junit.Test)12 AbstractLanguage (org.sonar.api.resources.AbstractLanguage)8 QualityProfile (org.sonar.server.qualityprofile.QualityProfile)6 Languages (org.sonar.api.resources.Languages)4 JsonWriter (org.sonar.api.utils.text.JsonWriter)4 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)3 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)3 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)3 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)3 LanguageTesting.newLanguage (org.sonar.server.language.LanguageTesting.newLanguage)3 Date (java.util.Date)2 IntStream.range (java.util.stream.IntStream.range)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Rule (org.junit.Rule)2 DEPRECATED (org.sonar.api.rule.RuleStatus.DEPRECATED)2 WebService (org.sonar.api.server.ws.WebService)2 DateUtils (org.sonar.api.utils.DateUtils)2 DateUtils.parseDateTime (org.sonar.api.utils.DateUtils.parseDateTime)2