use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarlint-core by SonarSource.
the class QualityProfilesDownloader method fetchQualityProfiles.
public QProfiles fetchQualityProfiles() {
QProfiles.Builder qProfileBuilder = QProfiles.newBuilder();
String searchUrl = DEFAULT_QP_SEARCH_URL;
if (wsClient.getOrganizationKey() != null) {
searchUrl += "?organization=" + StringUtils.urlEncode(wsClient.getOrganizationKey());
}
try (InputStream contentStream = wsClient.get(searchUrl).contentStream()) {
SearchWsResponse qpResponse = QualityProfiles.SearchWsResponse.parseFrom(contentStream);
for (QualityProfile qp : qpResponse.getProfilesList()) {
QProfile.Builder qpBuilder = QProfile.newBuilder();
qpBuilder.setKey(qp.getKey());
qpBuilder.setName(qp.getName());
qpBuilder.setLanguage(qp.getLanguage());
qpBuilder.setLanguageName(qp.getLanguageName());
qpBuilder.setActiveRuleCount(qp.getActiveRuleCount());
qpBuilder.setRulesUpdatedAt(qp.getRulesUpdatedAt());
qpBuilder.setUserUpdatedAt(qp.getUserUpdatedAt());
qProfileBuilder.putQprofilesByKey(qp.getKey(), qpBuilder.build());
if (qp.getIsDefault()) {
qProfileBuilder.putDefaultQProfilesByLanguage(qp.getLanguage(), qp.getKey());
}
}
} catch (IOException e) {
throw new IllegalStateException("Failed to load default quality profiles", e);
}
return qProfileBuilder.build();
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method actions_when_user_can_edit_profile.
@Test
public void actions_when_user_can_edit_profile() {
QProfileDto profile1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
QProfileDto profile2 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
QProfileDto profile3 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
QProfileDto builtInProfile = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()).setIsBuiltIn(true));
UserDto user = db.users().insertUser();
GroupDto group = db.users().insertGroup();
db.qualityProfiles().addUserPermission(profile1, user);
db.qualityProfiles().addGroupPermission(profile3, group);
userSession.logIn(user).setGroups(group);
SearchWsResponse result = call(ws.newRequest());
assertThat(result.getProfilesList()).extracting(QualityProfile::getKey, qp -> qp.getActions().getEdit(), qp -> qp.getActions().getCopy(), qp -> qp.getActions().getSetAsDefault(), qp -> qp.getActions().getDelete(), qp -> qp.getActions().getAssociateProjects()).containsExactlyInAnyOrder(tuple(profile1.getKee(), true, false, false, true, true), tuple(profile2.getKee(), false, false, false, false, false), tuple(profile3.getKee(), true, false, false, true, true), tuple(builtInProfile.getKee(), false, false, false, false, false));
assertThat(result.getActions().getCreate()).isFalse();
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method filter_on_deprecated_project_key_and_default.
@Test
public void filter_on_deprecated_project_key_and_default() {
ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profileOnXoo1 = db.qualityProfiles().insert(q -> q.setLanguage(XOO1.getKey()));
QProfileDto defaultProfileOnXoo1 = db.qualityProfiles().insert(q -> q.setLanguage(XOO1.getKey()));
QProfileDto defaultProfileOnXoo2 = db.qualityProfiles().insert(q -> q.setLanguage(XOO2.getKey()));
db.qualityProfiles().associateWithProject(project, profileOnXoo1);
db.qualityProfiles().setAsDefault(defaultProfileOnXoo1, defaultProfileOnXoo2);
SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT_KEY, project.getKey()).setParam(PARAM_DEFAULTS, "true"));
assertThat(result.getProfilesList()).extracting(QualityProfile::getKey).containsExactlyInAnyOrder(defaultProfileOnXoo2.getKee()).doesNotContain(defaultProfileOnXoo1.getKee(), profileOnXoo1.getKee());
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method empty_when_filtering_on_project_and_no_language_installed.
@Test
public void empty_when_filtering_on_project_and_no_language_installed() {
WsActionTester ws = new WsActionTester(new SearchAction(userSession, new Languages(), dbClient, new ComponentFinder(dbClient, null)));
db.qualityProfiles().insert();
ProjectDto project = db.components().insertPrivateProjectDto();
QProfileDto profileOnXoo1 = db.qualityProfiles().insert(q -> q.setLanguage(XOO1.getKey()));
db.qualityProfiles().associateWithProject(project, profileOnXoo1);
SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT, project.getKey()).setParam(PARAM_DEFAULTS, "true"));
assertThat(result.getProfilesList()).isEmpty();
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method no_profile.
@Test
public void no_profile() {
SearchWsResponse result = call(ws.newRequest());
assertThat(result.getProfilesList()).isEmpty();
}
Aggregations