Search in sources :

Example 11 with Language

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

the class QualityProfileEventsStepTest method no_more_used_event_if_qp_no_more_listed.

@Test
public void no_more_used_event_if_qp_no_more_listed() {
    QualityProfile qp = qp(QP_NAME_1, LANGUAGE_KEY_1);
    mockMeasures(treeRootHolder.getRoot(), arrayOf(qp), null);
    Language language = mockLanguageInRepository(LANGUAGE_KEY_1);
    underTest.execute();
    verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture());
    verifyNoMoreInteractions(eventRepository);
    verifyEvent(eventArgumentCaptor.getValue(), "Stop using '" + 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 12 with Language

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

the class AppActionTest method should_generate_app_init_info.

@Test
public void should_generate_app_init_info() throws Exception {
    AppAction app = new AppAction(languages, db.getDbClient(), i18n, userSessionRule, defaultOrganizationProvider);
    WsTester tester = new WsTester(new RulesWs(app));
    userSessionRule.addPermission(ADMINISTER_QUALITY_PROFILES, defaultOrganizationProvider.get().getUuid());
    QualityProfileDto profile1 = QProfileTesting.newXooP1("org-123");
    QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123").setParentKee(QProfileTesting.XOO_P1_KEY);
    db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1);
    db.getDbClient().qualityProfileDao().insert(db.getSession(), profile2);
    db.commit();
    Language xoo = mock(Language.class);
    when(xoo.getKey()).thenReturn("xoo");
    when(xoo.getName()).thenReturn("Xoo");
    Language whitespace = mock(Language.class);
    when(whitespace.getKey()).thenReturn("ws");
    when(whitespace.getName()).thenReturn("Whitespace");
    when(languages.get("xoo")).thenReturn(xoo);
    when(languages.all()).thenReturn(new Language[] { xoo, whitespace });
    RuleRepositoryDto repo1 = new RuleRepositoryDto("xoo", "xoo", "SonarQube");
    RuleRepositoryDto repo2 = new RuleRepositoryDto("squid", "ws", "SonarQube");
    db.getDbClient().ruleRepositoryDao().insert(db.getSession(), asList(repo1, repo2));
    db.getSession().commit();
    when(i18n.message(isA(Locale.class), anyString(), anyString())).thenAnswer(invocation -> invocation.getArguments()[1]);
    tester.newGetRequest("api/rules", "app").execute().assertJson(this.getClass(), "app.json");
}
Also used : Locale(java.util.Locale) WsTester(org.sonar.server.ws.WsTester) Language(org.sonar.api.resources.Language) RuleRepositoryDto(org.sonar.db.rule.RuleRepositoryDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 13 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)

Example 14 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 15 with Language

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

the class CopyAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    qProfileWsSupport.checkQProfileAdminPermission();
    String newName = request.mandatoryParam(PARAM_PROFILE_NAME);
    String profileKey = request.mandatoryParam(PARAM_PROFILE_KEY);
    QualityProfileDto copiedProfile = profileCopier.copyToName(profileKey, newName);
    String languageKey = copiedProfile.getLanguage();
    Language language = languages.get(copiedProfile.getLanguage());
    String parentKey = copiedProfile.getParentKee();
    response.newJsonWriter().beginObject().prop("key", copiedProfile.getKey()).prop("name", copiedProfile.getName()).prop("language", languageKey).prop("languageName", language == null ? null : language.getName()).prop("isDefault", copiedProfile.isDefault()).prop("isInherited", parentKey != null).prop("parentKey", parentKey).endObject().close();
}
Also used : Language(org.sonar.api.resources.Language) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto)

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