use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class DefaultQualityProfileLoader method loadResource.
private List<QualityProfile> loadResource(String url) {
GetRequest getRequest = new GetRequest(url);
InputStream is = wsClient.call(getRequest).contentStream();
SearchWsResponse profiles = null;
try {
profiles = SearchWsResponse.parseFrom(is);
} catch (IOException e) {
throw new IllegalStateException("Failed to load quality profiles", e);
} finally {
IOUtils.closeQuietly(is);
}
List<QualityProfile> profilesList = profiles.getProfilesList();
if (profilesList == null || profilesList.isEmpty()) {
throw MessageException.of("No quality profiles have been found, you probably don't have any language plugin installed.");
}
return profilesList;
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarlint-core by SonarSource.
the class ConnectedModeTest method checkForUpdate.
@Test
public void checkForUpdate() throws Exception {
updateGlobal();
updateModule(PROJECT_KEY_JAVA);
ServerConfiguration serverConfig = getServerConfig(true);
StorageUpdateCheckResult result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isFalse();
// restarting server should not lead to notify an update
ORCHESTRATOR.restartServer();
result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isFalse();
// Change a global setting that is not in the whitelist
setSettings(null, "sonar.foo", "bar");
result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isFalse();
// Change a global setting that *is* in the whitelist
setSettingsMultiValue(null, "sonar.inclusions", "**/*");
// Activate a new rule
SearchWsResponse response = newAdminWsClient(ORCHESTRATOR).qualityProfiles().search(new SearchWsRequest().setLanguage("java"));
String profileKey = response.getProfilesList().stream().filter(p -> p.getName().equals("SonarLint IT Java")).findFirst().get().getKey();
ORCHESTRATOR.getServer().adminWsClient().post("api/qualityprofiles/activate_rule", "profile_key", profileKey, "rule_key", "squid:S1228");
result = engine.checkIfGlobalStorageNeedUpdate(serverConfig, null);
assertThat(result.needUpdate()).isTrue();
assertThat(result.changelog()).containsOnly("Global settings updated", "Quality profile 'SonarLint IT Java' for language 'Java' updated");
result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
assertThat(result.needUpdate()).isFalse();
// Change a project setting that is not in the whitelist
setSettings(PROJECT_KEY_JAVA, "sonar.foo", "biz");
result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
assertThat(result.needUpdate()).isFalse();
// Change a project setting that *is* in the whitelist
setSettingsMultiValue(PROJECT_KEY_JAVA, "sonar.exclusions", "**/*.foo");
result = engine.checkIfModuleStorageNeedUpdate(serverConfig, PROJECT_KEY_JAVA, null);
assertThat(result.needUpdate()).isTrue();
assertThat(result.changelog()).containsOnly("Project settings updated");
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class SearchAction method buildResponse.
private SearchWsResponse buildResponse(SearchData data) {
List<QProfileDto> profiles = data.getProfiles();
Map<String, QProfileDto> profilesByKey = profiles.stream().collect(Collectors.toMap(QProfileDto::getKee, identity()));
boolean isGlobalQProfileAdmin = userSession.hasPermission(ADMINISTER_QUALITY_PROFILES);
SearchWsResponse.Builder response = SearchWsResponse.newBuilder();
response.setActions(SearchWsResponse.Actions.newBuilder().setCreate(isGlobalQProfileAdmin));
for (QProfileDto profile : profiles) {
QualityProfile.Builder profileBuilder = response.addProfilesBuilder();
String profileKey = profile.getKee();
profileBuilder.setKey(profileKey);
ofNullable(profile.getName()).ifPresent(profileBuilder::setName);
ofNullable(profile.getRulesUpdatedAt()).ifPresent(profileBuilder::setRulesUpdatedAt);
ofNullable(profile.getLastUsed()).ifPresent(last -> profileBuilder.setLastUsed(formatDateTime(last)));
ofNullable(profile.getUserUpdatedAt()).ifPresent(userUpdatedAt -> profileBuilder.setUserUpdatedAt(formatDateTime(userUpdatedAt)));
profileBuilder.setActiveRuleCount(data.getActiveRuleCount(profileKey));
profileBuilder.setActiveDeprecatedRuleCount(data.getActiveDeprecatedRuleCount(profileKey));
boolean isDefault = data.isDefault(profile);
profileBuilder.setIsDefault(isDefault);
if (!isDefault) {
profileBuilder.setProjectCount(data.getProjectCount(profileKey));
}
writeLanguageFields(profileBuilder, profile);
writeParentFields(profileBuilder, profile, profilesByKey);
profileBuilder.setIsInherited(profile.getParentKee() != null);
profileBuilder.setIsBuiltIn(profile.isBuiltIn());
profileBuilder.setActions(SearchWsResponse.QualityProfile.Actions.newBuilder().setEdit(!profile.isBuiltIn() && (isGlobalQProfileAdmin || data.isEditable(profile))).setSetAsDefault(!isDefault && isGlobalQProfileAdmin).setCopy(isGlobalQProfileAdmin).setDelete(!isDefault && !profile.isBuiltIn() && (isGlobalQProfileAdmin || data.isEditable(profile))).setAssociateProjects(!isDefault && (isGlobalQProfileAdmin || data.isEditable(profile))));
}
return response.build();
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method ignore_profiles_on_unknown_language.
@Test
public void ignore_profiles_on_unknown_language() {
QProfileDto profile1OnXoo1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
QProfileDto profile2OnXoo1 = db.qualityProfiles().insert(p -> p.setLanguage(XOO2.getKey()));
QProfileDto profileOnUnknownLanguage = db.qualityProfiles().insert(p -> p.setLanguage("unknown"));
SearchWsResponse result = call(ws.newRequest());
assertThat(result.getProfilesList()).extracting(QualityProfile::getKey).containsExactlyInAnyOrder(profile1OnXoo1.getKee(), profile2OnXoo1.getKee()).doesNotContain(profileOnUnknownLanguage.getKee());
}
use of org.sonarqube.ws.QualityProfiles.SearchWsResponse in project sonarqube by SonarSource.
the class SearchActionTest method actions_when_not_logged_in.
@Test
public void actions_when_not_logged_in() {
QProfileDto profile = db.qualityProfiles().insert(p -> p.setLanguage(XOO1.getKey()));
userSession.anonymous();
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(profile.getKee(), false, false, false, false, false));
assertThat(result.getActions().getCreate()).isFalse();
}
Aggregations