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);
}
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");
}
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;
}
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());
}
}
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();
}
Aggregations