aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2012-03-16 19:02:48 +0100
committerFabrice Bellingard <bellingard@gmail.com>2012-03-16 19:04:52 +0100
commit43012d7d54f1a0bdff26c4cc4f656ea8e4e1b93d (patch)
tree774244cddbc258415dea7da6bc3eefd07c15ded4 /sonar-server
parentfdc46b92d29e2da8dcea5e8c2dd25dcf4dd92e5a (diff)
downloadsonarqube-43012d7d54f1a0bdff26c4cc4f656ea8e4e1b93d.tar.gz
sonarqube-43012d7d54f1a0bdff26c4cc4f656ea8e4e1b93d.zip
SONAR-2977 Setting a profile to default via the API doesn't work
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/ActivateDefaultProfiles.java23
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java16
2 files changed, 23 insertions, 16 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/ActivateDefaultProfiles.java b/sonar-server/src/main/java/org/sonar/server/startup/ActivateDefaultProfiles.java
index 3d63834ca61..bf6e1f06690 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/ActivateDefaultProfiles.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/ActivateDefaultProfiles.java
@@ -52,12 +52,12 @@ public final class ActivateDefaultProfiles {
RulesProfile profileToActivate = null;
boolean oneProfileIsActivated = false;
if (profiles.isEmpty()) {
- profileToActivate = new RulesProfile("Default " + language.getName(), language.getKey(), true, false);
-
+ profileToActivate = RulesProfile.create("Default " + language.getName(), language.getKey());
+ profileToActivate.setDefaultProfile(true);
+ profileToActivate.setProvided(false);
} else if (profiles.size() == 1) {
profileToActivate = profiles.get(0);
-
- } else {
+ } else if (noProfileAlreadyActivated(profiles)) {
Iterator<RulesProfile> iterator = profiles.iterator();
while (iterator.hasNext() && !oneProfileIsActivated) {
RulesProfile profile = iterator.next();
@@ -66,10 +66,8 @@ public final class ActivateDefaultProfiles {
profileToActivate = profile;
}
}
- if (!oneProfileIsActivated) {
- if (profileToActivate == null) {
- profileToActivate = profiles.get(0);
- }
+ if (!oneProfileIsActivated && profileToActivate == null) {
+ profileToActivate = profiles.get(0);
}
}
if (!oneProfileIsActivated && profileToActivate != null) {
@@ -77,4 +75,13 @@ public final class ActivateDefaultProfiles {
session.saveWithoutFlush(profileToActivate);
}
}
+
+ private boolean noProfileAlreadyActivated(List<RulesProfile> profiles) {
+ for (RulesProfile rulesProfile : profiles) {
+ if (rulesProfile.getDefaultProfile()) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
index 89aeded16e8..7ed797f2ead 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
@@ -108,7 +108,7 @@ public final class RegisterProvidedProfiles {
void saveProvidedProfiles(List<RulesProfile> profiles, DatabaseSession session) {
for (RulesProfile profile : profiles) {
TimeProfiler profiler = new TimeProfiler().start("Save profile " + profile);
- RulesProfile persistedProfile = findOrCreate(profile.getName(), profile.getLanguage(), session);
+ RulesProfile persistedProfile = findOrCreate(profile, session);
for (ActiveRule activeRule : profile.getActiveRules()) {
Rule rule = getPersistedRule(activeRule);
@@ -140,14 +140,14 @@ public final class RegisterProvidedProfiles {
return rule;
}
- private RulesProfile findOrCreate(String name, String language, DatabaseSession session) {
- RulesProfile profile = session.getSingleResult(RulesProfile.class, "name", name, "language", language);
- if (profile == null) {
- profile = RulesProfile.create(name, language);
- profile.setProvided(true);
- profile.setDefaultProfile(false);
+ private RulesProfile findOrCreate(RulesProfile profile, DatabaseSession session) {
+ RulesProfile persistedProfile = session.getSingleResult(RulesProfile.class, "name", profile.getName(), "language", profile.getLanguage());
+ if (persistedProfile == null) {
+ persistedProfile = RulesProfile.create(profile.getName(), profile.getLanguage());
+ persistedProfile.setDefaultProfile(profile.getDefaultProfile());
+ persistedProfile.setProvided(true);
}
- return profile;
+ return persistedProfile;
}
}