use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method statistics_on_active_rules.
@Test
public void statistics_on_active_rules() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
RuleDefinitionDto rule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
RuleDefinitionDto deprecatedRule1 = db.rules().insertRule(r -> r.setStatus(DEPRECATED)).getDefinition();
RuleDefinitionDto deprecatedRule2 = db.rules().insertRule(r -> r.setStatus(DEPRECATED)).getDefinition();
RuleDefinitionDto inactiveRule = db.rules().insertRule(r -> r.setLanguage(XOO1.getKey())).getDefinition();
db.qualityProfiles().activateRule(profile, rule);
db.qualityProfiles().activateRule(profile, deprecatedRule1);
db.qualityProfiles().activateRule(profile, deprecatedRule2);
SearchWsResponse result = call(ws.newRequest());
assertThat(result.getProfilesList()).extracting(QualityProfile::getActiveRuleCount, QualityProfile::getActiveDeprecatedRuleCount).containsExactlyInAnyOrder(tuple(3L, 2L));
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class DefaultQualityProfileLoader method call.
private Map<String, QualityProfile> call(String url) throws IOException {
GetRequest getRequest = new GetRequest(url);
try (InputStream is = wsClient.call(getRequest).contentStream()) {
SearchWsResponse profiles = SearchWsResponse.parseFrom(is);
List<QualityProfile> profilesList = profiles.getProfilesList();
return profilesList.stream().collect(toMap(QualityProfile::getLanguage, identity(), throwingMerger(), LinkedHashMap::new));
}
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method search_map_dates.
@Test
public void search_map_dates() {
long time = DateUtils.parseDateTime("2016-12-22T19:10:03+0100").getTime();
qualityProfileDb.insertQualityProfiles(newQualityProfileDto().setLanguage(xoo1.getKey()).setRulesUpdatedAt("2016-12-21T19:10:03+0100").setLastUsed(time).setUserUpdatedAt(time));
SearchWsResponse result = call(ws.newRequest());
assertThat(result.getProfilesCount()).isEqualTo(1);
assertThat(result.getProfiles(0).getRulesUpdatedAt()).isEqualTo("2016-12-21T19:10:03+0100");
assertThat(parseDateTime(result.getProfiles(0).getLastUsed()).getTime()).isEqualTo(time);
assertThat(parseDateTime(result.getProfiles(0).getUserUpdatedAt()).getTime()).isEqualTo(time);
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method search_for_project_qp.
@Test
public void search_for_project_qp() {
long time = DateUtils.parseDateTime("2016-12-22T19:10:03+0100").getTime();
OrganizationDto org = db.organizations().insert();
QualityProfileDto qualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-12345").setOrganizationUuid(org.getUuid()).setLanguage(xoo1.getKey()).setRulesUpdatedAt("2016-12-21T19:10:03+0100").setLastUsed(time).setName("Sonar way");
QualityProfileDto qualityProfileOnXoo2 = QualityProfileDto.createFor("sonar-way-xoo2-12345").setOrganizationUuid(org.getUuid()).setLanguage(xoo2.getKey()).setRulesUpdatedAt("2016-12-21T19:10:03+0100").setLastUsed(time).setName("Sonar way");
QualityProfileDto anotherQualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-45678").setOrganizationUuid(org.getUuid()).setLanguage(xoo1.getKey()).setRulesUpdatedAt("2016-12-21T19:10:03+0100").setLastUsed(time).setName("Another way");
ComponentDto project = newProjectDto(org, "project-uuid");
qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
qualityProfileDb.insertProjectWithQualityProfileAssociations(project, qualityProfileOnXoo1, qualityProfileOnXoo2);
SearchWsResponse result = call(ws.newRequest().setParam(PARAM_PROJECT_KEY, project.key()));
assertThat(result.getProfilesList()).hasSize(2).extracting(QualityProfile::getKey).contains("sonar-way-xoo1-12345", "sonar-way-xoo2-12345").doesNotContain("sonar-way-xoo1-45678");
assertThat(result.getProfilesList()).extracting(QualityProfile::getRulesUpdatedAt, QualityProfile::getLastUsed).contains(tuple("2016-12-21T19:10:03+0100", formatDateTime(time)));
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarlint-core by SonarSource.
the class ModuleQualityProfilesDownloader method fetchModuleQualityProfiles.
public List<QualityProfile> fetchModuleQualityProfiles(String moduleKey, String serverVersion) {
SearchWsResponse qpResponse;
String param;
if (Version.create(serverVersion).compareToIgnoreQualifier(Version.create("6.5")) >= 0) {
param = "project";
} else {
param = "projectKey";
}
String baseUrl = "/api/qualityprofiles/search.protobuf?" + param + "=" + StringUtils.urlEncode(moduleKey);
String organizationKey = wsClient.getOrganizationKey();
if (organizationKey != null) {
baseUrl += "&organization=" + StringUtils.urlEncode(organizationKey);
}
try (InputStream contentStream = wsClient.get(baseUrl).contentStream()) {
qpResponse = QualityProfiles.SearchWsResponse.parseFrom(contentStream);
} catch (NotFoundException e) {
throw new ProjectNotFoundException(moduleKey, organizationKey);
} catch (IOException e) {
throw new IllegalStateException("Failed to load module quality profiles", e);
}
return qpResponse.getProfilesList();
}
Aggregations