use of org.sonar.api.resources.Language in project sonarqube by SonarSource.
the class QualityProfileEventsStepTest method added_event_if_qp_is_added.
@Test
public void added_event_if_qp_is_added() {
QualityProfile qp = qp(QP_NAME_1, LANGUAGE_KEY_1, new Date());
qProfileStatusRepository.register(qp.getQpKey(), ADDED);
Language language = mockLanguageInRepository(LANGUAGE_KEY_1);
mockMeasures(treeRootHolder.getRoot(), null, arrayOf(qp));
underTest.execute(new TestComputationStepContext());
verify(eventRepository).add(eq(treeRootHolder.getRoot()), eventArgumentCaptor.capture());
verifyNoMoreInteractions(eventRepository);
verifyEvent(eventArgumentCaptor.getValue(), "Use '" + qp.getQpName() + "' (" + language.getName() + ")", null);
}
use of org.sonar.api.resources.Language in project sonarqube by SonarSource.
the class CompareAction method writeRule.
private void writeRule(JsonWriter json, RuleDefinitionDto 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 ActiveRuleCompleter method writeProfile.
private void writeProfile(Map<String, Rules.QProfile> profilesResponse, QProfileDto profile) {
Rules.QProfile.Builder profileResponse = Rules.QProfile.newBuilder();
ofNullable(profile.getName()).ifPresent(profileResponse::setName);
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);
}
ofNullable(profile.getParentKee()).ifPresent(profileResponse::setParent);
profilesResponse.put(profile.getKee(), profileResponse.build());
}
use of org.sonar.api.resources.Language in project sonarqube by SonarSource.
the class LanguageValidationTest method fail_if_conflicting_languages.
@Test
public void fail_if_conflicting_languages() {
Language lang1 = mock(Language.class);
Language lang2 = mock(Language.class);
when(lang1.getKey()).thenReturn("key");
when(lang2.getKey()).thenReturn("key");
ServerPluginRepository repo = mock(ServerPluginRepository.class);
when(repo.getPluginKey(lang1)).thenReturn("plugin1");
when(repo.getPluginKey(lang2)).thenReturn("plugin2");
LanguageValidation languageValidation = new LanguageValidation(repo, lang1, lang2);
assertThatThrownBy(languageValidation::start).isInstanceOf(IllegalStateException.class).hasMessage("There are two languages declared with the same key 'key' declared by the plugins 'plugin1' and 'plugin2'. " + "Please uninstall one of the conflicting plugins.");
}
use of org.sonar.api.resources.Language in project sonarqube by SonarSource.
the class SearchActionTest method json_example.
@Test
public void json_example() {
// languages
Language cs = newLanguage("cs", "C#");
Language java = newLanguage("java", "Java");
Language python = newLanguage("py", "Python");
// profiles
QProfileDto sonarWayCs = db.qualityProfiles().insert(p -> p.setName("Sonar way").setKee("AU-TpxcA-iU5OvuD2FL3").setIsBuiltIn(true).setLanguage(cs.getKey()));
QProfileDto myCompanyProfile = db.qualityProfiles().insert(p -> p.setName("My Company Profile").setKee("iU5OvuD2FLz").setLanguage(java.getKey()));
QProfileDto myBuProfile = db.qualityProfiles().insert(p -> p.setName("My BU Profile").setKee("AU-TpxcA-iU5OvuD2FL1").setParentKee(myCompanyProfile.getKee()).setLanguage(java.getKey()));
QProfileDto sonarWayPython = db.qualityProfiles().insert(p -> p.setName("Sonar way").setKee("AU-TpxcB-iU5OvuD2FL7").setIsBuiltIn(true).setLanguage(python.getKey()));
db.qualityProfiles().setAsDefault(sonarWayCs, myCompanyProfile, sonarWayPython);
// rules
List<RuleDefinitionDto> javaRules = range(0, 10).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(java.getKey())).getDefinition()).collect(MoreCollectors.toList());
List<RuleDefinitionDto> deprecatedJavaRules = range(0, 5).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(java.getKey()).setStatus(DEPRECATED)).getDefinition()).collect(MoreCollectors.toList());
range(0, 7).forEach(i -> db.qualityProfiles().activateRule(myCompanyProfile, javaRules.get(i)));
range(0, 2).forEach(i -> db.qualityProfiles().activateRule(myCompanyProfile, deprecatedJavaRules.get(i)));
range(0, 10).forEach(i -> db.qualityProfiles().activateRule(myBuProfile, javaRules.get(i)));
range(0, 5).forEach(i -> db.qualityProfiles().activateRule(myBuProfile, deprecatedJavaRules.get(i)));
range(0, 2).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(python.getKey())).getDefinition()).forEach(rule -> db.qualityProfiles().activateRule(sonarWayPython, rule));
range(0, 3).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(cs.getKey())).getDefinition()).forEach(rule -> db.qualityProfiles().activateRule(sonarWayCs, rule));
// project
range(0, 7).mapToObj(i -> db.components().insertPrivateProjectDto()).forEach(project -> db.qualityProfiles().associateWithProject(project, myBuProfile));
// User
UserDto user = db.users().insertUser();
db.qualityProfiles().addUserPermission(myCompanyProfile, user);
db.qualityProfiles().addUserPermission(myBuProfile, user);
userSession.logIn(user);
underTest = new SearchAction(userSession, new Languages(cs, java, python), dbClient, new ComponentFinder(dbClient, null));
ws = new WsActionTester(underTest);
String result = ws.newRequest().execute().getInput();
assertJson(result).ignoreFields("ruleUpdatedAt", "lastUsed", "userUpdatedAt").isSimilarTo(ws.getDef().responseExampleAsString());
}
Aggregations