aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2012-03-19 07:19:49 +0100
committerFabrice Bellingard <bellingard@gmail.com>2012-03-19 07:19:49 +0100
commit4dd00c2e9cb29740b804f3f8b9b01a306ea976f3 (patch)
tree8bae70a46951cde7bfb39f37f7f83e77bc328b77 /sonar-server
parentd932b9251d8d0ce182e4199aa948cedff532ecb4 (diff)
downloadsonarqube-4dd00c2e9cb29740b804f3f8b9b01a306ea976f3.tar.gz
sonarqube-4dd00c2e9cb29740b804f3f8b9b01a306ea976f3.zip
Revert "SONAR-2977 Setting a profile to default via the API doesn't work"
This reverts commit 43012d7d54f1a0bdff26c4cc4f656ea8e4e1b93d.
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, 16 insertions, 23 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 bf6e1f06690..3d63834ca61 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 = RulesProfile.create("Default " + language.getName(), language.getKey());
- profileToActivate.setDefaultProfile(true);
- profileToActivate.setProvided(false);
+ profileToActivate = new RulesProfile("Default " + language.getName(), language.getKey(), true, false);
+
} else if (profiles.size() == 1) {
profileToActivate = profiles.get(0);
- } else if (noProfileAlreadyActivated(profiles)) {
+
+ } else {
Iterator<RulesProfile> iterator = profiles.iterator();
while (iterator.hasNext() && !oneProfileIsActivated) {
RulesProfile profile = iterator.next();
@@ -66,8 +66,10 @@ public final class ActivateDefaultProfiles {
profileToActivate = profile;
}
}
- if (!oneProfileIsActivated && profileToActivate == null) {
- profileToActivate = profiles.get(0);
+ if (!oneProfileIsActivated) {
+ if (profileToActivate == null) {
+ profileToActivate = profiles.get(0);
+ }
}
}
if (!oneProfileIsActivated && profileToActivate != null) {
@@ -75,13 +77,4 @@ 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 7ed797f2ead..89aeded16e8 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, session);
+ RulesProfile persistedProfile = findOrCreate(profile.getName(), profile.getLanguage(), session);
for (ActiveRule activeRule : profile.getActiveRules()) {
Rule rule = getPersistedRule(activeRule);
@@ -140,14 +140,14 @@ public final class RegisterProvidedProfiles {
return rule;
}
- 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);
+ 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);
}
- return persistedProfile;
+ return profile;
}
}