action
.createParam(PARAM_DEFAULTS)
.setDescription(format("Return the quality profile marked as default for each language. " +
- "If provided, then the parameters '%s', '%s' and '%s' must not be set.",
- PARAM_LANGUAGE, PARAM_PROJECT_KEY, PARAM_PROFILE_NAME))
+ "If provided, then the parameters '%s', '%s' must not be set.",
+ PARAM_LANGUAGE, PARAM_PROJECT_KEY))
.setDefaultValue(false)
.setBooleanPossibleValues();
action.createParam(PARAM_PROFILE_NAME)
- .setDescription(format("Profile name. It should be always used with the '%s' parameter.", PARAM_PROJECT_KEY))
+ .setDescription(format("Profile name. It should be always used with the '%s' or '%s' parameter.", PARAM_PROJECT_KEY, PARAM_DEFAULTS))
.setExampleValue("SonarQube Way");
}
private final DbClient dbClient;
private final ComponentFinder componentFinder;
- public SearchDataLoader(Languages languages, QProfileLookup profileLookup, QProfileLoader profileLoader, QProfileFactory profileFactory, DbClient dbClient, ComponentFinder componentFinder) {
+ public SearchDataLoader(Languages languages, QProfileLookup profileLookup, QProfileLoader profileLoader, QProfileFactory profileFactory, DbClient dbClient,
+ ComponentFinder componentFinder) {
this.languages = languages;
this.profileLookup = profileLookup;
this.profileLoader = profileLoader;
private List<QProfile> findProfiles(Request request) {
List<QProfile> profiles;
if (askDefaultProfiles(request)) {
- profiles = findDefaultProfiles();
+ profiles = findDefaultProfiles(request);
} else if (hasComponentKey(request)) {
profiles = findProjectProfiles(request);
} else {
private List<QProfile> findAllProfiles(Request request) {
String language = request.param(PARAM_LANGUAGE);
- List<QProfile> profiles = language != null ?
- profileLookup.profiles(language)
+ List<QProfile> profiles = language != null ? profileLookup.profiles(language)
: profileLookup.allProfiles();
return from(profiles)
}
}
- private List<QProfile> findDefaultProfiles() {
+ private List<QProfile> findDefaultProfiles(Request request) {
+ String profileName = request.param(PARAM_PROFILE_NAME);
List<QProfile> profiles = new ArrayList<>();
DbSession dbSession = dbClient.openSession(false);
try {
for (Language language : languages.all()) {
- profiles.add(getDefaultProfile(dbSession, language.getKey()));
+ profiles.add(getDefaultProfile(dbSession, language.getKey(), profileName));
}
} finally {
dbClient.closeSession(dbSession);
return profileDtoToQProfile(profileDto);
}
- private QProfile getDefaultProfile(DbSession dbSession, String languageKey) {
- QualityProfileDto profile = profileFactory.getDefault(dbSession, languageKey);
+ private QProfile getDefaultProfile(DbSession dbSession, String languageKey, @Nullable String profileName) {
+ QualityProfileDto profile = profileName != null ? profileFactory.getByNameAndLanguage(dbSession, profileName, languageKey) : null;
+ if (profile == null) {
+ profile = profileFactory.getDefault(dbSession, languageKey);
+ }
checkState(profile != null, format("No quality profile can been found on language '%s'", languageKey));
return profileDtoToQProfile(profile);
checkRequest(!hasLanguage || (!hasComponentKey && !hasProfileName && !isDefault),
"The language parameter cannot be provided at the same time than the component key or profile name.");
- checkRequest(!isDefault || (!hasComponentKey && !hasProfileName), "The default parameter cannot be provided at the same time than the component key or profile name");
+ checkRequest(!isDefault || !hasComponentKey, "The default parameter cannot be provided at the same time than the component key");
}
private static boolean hasProfileName(Request request) {
}
@Test
- public void search_for_default_qp() {
+ public void search_for_default_qp_with_profile_name() {
QualityProfileDto qualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-12345")
.setLanguage(xoo1.getKey())
.setName("Sonar way")
- .setDefault(true);
+ .setDefault(false);
QualityProfileDto qualityProfileOnXoo2 = QualityProfileDto.createFor("sonar-way-xoo2-12345")
.setLanguage(xoo2.getKey())
.setName("Sonar way")
.setDefault(true);
QualityProfileDto anotherQualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-45678")
.setLanguage(xoo1.getKey())
- .setName("Sonar way")
- .setDefault(false);
+ .setName("Another way")
+ .setDefault(true);
qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
commit();
String result = ws.newRequest()
.setParam(PARAM_DEFAULTS, Boolean.TRUE.toString())
+ .setParam(PARAM_PROFILE_NAME, "Sonar way")
.execute().getInput();
assertThat(result)