Search in sources :

Example 21 with Language

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

the class CompareAction method writeRule.

private void writeRule(JsonWriter json, RuleDto rule, @Nullable RuleRepositoryDto repository) {
    String repositoryKey = rule.getRepositoryKey();
    json.prop(ATTRIBUTE_KEY, rule.getKey().toString()).prop(ATTRIBUTE_NAME, rule.getName()).prop(ATTRIBUTE_PLUGIN_KEY, repositoryKey);
    if (repository != null) {
        String languageKey = repository.getLanguage();
        Language language = languages.get(languageKey);
        json.prop(ATTRIBUTE_PLUGIN_NAME, repository.getName());
        json.prop(ATTRIBUTE_LANGUAGE_KEY, languageKey);
        json.prop(ATTRIBUTE_LANGUAGE_NAME, language == null ? null : language.getName());
    }
}
Also used : Language(org.sonar.api.resources.Language)

Example 22 with Language

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

the class QualityProfileEventsStepTest method added_event_if_one_new_qp.

@Test
public void added_event_if_one_new_qp() {
    QualityProfile qp = qp(QP_NAME_1, LANGUAGE_KEY_1);
    Language language = mockLanguageInRepository(LANGUAGE_KEY_1);
    mockMeasures(treeRootHolder.getRoot(), null, arrayOf(qp));
    underTest.execute();
    verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture());
    verifyNoMoreInteractions(eventRepository);
    verifyEvent(eventArgumentCaptor.getValue(), "Use '" + qp.getQpName() + "' (" + language.getName() + ")", null);
}
Also used : AbstractLanguage(org.sonar.api.resources.AbstractLanguage) Language(org.sonar.api.resources.Language) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Test(org.junit.Test)

Example 23 with Language

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

the class QualityProfileEventsStepTest method changed_event_if_same_qp_but_no_same_date.

@Test
public void changed_event_if_same_qp_but_no_same_date() {
    QualityProfile qp1 = qp(QP_NAME_1, LANGUAGE_KEY_1, parseDateTime("2011-04-25T01:05:13+0100"));
    QualityProfile qp2 = qp(QP_NAME_1, LANGUAGE_KEY_1, parseDateTime("2011-04-25T01:05:17+0100"));
    mockMeasures(treeRootHolder.getRoot(), arrayOf(qp1), arrayOf(qp2));
    Language language = mockLanguageInRepository(LANGUAGE_KEY_1);
    underTest.execute();
    verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture());
    verifyNoMoreInteractions(eventRepository);
    verifyEvent(eventArgumentCaptor.getValue(), "Changes in '" + qp2.getQpName() + "' (" + language.getName() + ")", "from=" + UtcDateUtils.formatDateTime(parseDateTime("2011-04-25T01:05:14+0100")) + ";key=" + qp1.getQpKey() + ";to=" + UtcDateUtils.formatDateTime(parseDateTime("2011-04-25T01:05:18+0100")));
}
Also used : AbstractLanguage(org.sonar.api.resources.AbstractLanguage) Language(org.sonar.api.resources.Language) QualityProfile(org.sonar.server.qualityprofile.QualityProfile) Test(org.junit.Test)

Example 24 with Language

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

the class SearchResponseFormat method formatRule.

private Common.Rule.Builder formatRule(RuleDefinitionDto 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 25 with Language

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

the class SearchResponseFormat method formatLanguages.

private Issues.Languages.Builder formatLanguages() {
    Issues.Languages.Builder wsLangs = Issues.Languages.newBuilder();
    Issues.Language.Builder wsLang = Issues.Language.newBuilder();
    for (Language lang : languages.all()) {
        wsLang.clear().setKey(lang.getKey()).setName(lang.getName());
        wsLangs.addLanguages(wsLang);
    }
    return wsLangs;
}
Also used : Language(org.sonar.api.resources.Language) Languages(org.sonar.api.resources.Languages)

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