diff options
author | Godin <mandrikov@gmail.com> | 2010-12-21 17:59:22 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-21 17:59:22 +0000 |
commit | 8c305fd210becd5f62c643eeadc0ae2f6c91b8a4 (patch) | |
tree | aa5a2e9970cf91a5e7cabf03dbdd25945dbf0697 /sonar-server | |
parent | 13d356806a18cbcf080aa784765a07fa310b29d8 (diff) | |
download | sonarqube-8c305fd210becd5f62c643eeadc0ae2f6c91b8a4.tar.gz sonarqube-8c305fd210becd5f62c643eeadc0ae2f6c91b8a4.zip |
SONAR-1722: Take inheritance into account during rename of profiles
Diffstat (limited to 'sonar-server')
5 files changed, 38 insertions, 2 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java index 1c6114ba386..bae9f3bff68 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java @@ -38,6 +38,20 @@ public class ProfilesManager extends BaseDao { this.rulesDao = rulesDao; } + public void renameProfile(int profileId, String newProfileName) { + RulesProfile profile = getSession().getSingleResult(RulesProfile.class, "id", profileId); + if (profile != null && !profile.getProvided()) { + String hql = "UPDATE " + RulesProfile.class.getSimpleName() + " o SET o.parentName=:newName WHERE o.parentName=:oldName"; + getSession().getEntityManager().createQuery(hql) + .setParameter("oldName", profile.getName()) + .setParameter("newName", newProfileName) + .executeUpdate(); + profile.setName(newProfileName); + getSession().save(profile); + getSession().commit(); + } + } + public void copyProfile(int profileId, String newProfileName) { RulesProfile profile = getSession().getSingleResult(RulesProfile.class, "id", profileId); RulesProfile toImport = (RulesProfile) profile.clone(); diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index d4e89669dbd..5aec6c8f921 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -189,6 +189,10 @@ public final class JRubyFacade implements ServerComponent { return getContainer().getComponent(ProfilesConsole.class).getProfileExporter(exporterKey).getMimeType(); } + public void renameProfile(int profileId, String newProfileName) { + getProfilesManager().renameProfile(profileId, newProfileName); + } + public void copyProfile(long profileId, String newProfileName) { getProfilesManager().copyProfile((int) profileId, newProfileName); } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb index eb0235793aa..4fdd7bd2380 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/profiles_controller.rb @@ -244,8 +244,7 @@ class ProfilesController < ApplicationController if existing flash[:warning]='This profile name already exists.' elsif !profile.provided? - profile.name=name - profile.save + java_facade.renameProfile(profile.id, name) end end redirect_to :action => 'index' diff --git a/sonar-server/src/test/java/org/sonar/server/configuration/InheritedProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/configuration/InheritedProfilesTest.java index d3ea548b69e..500846033fe 100644 --- a/sonar-server/src/test/java/org/sonar/server/configuration/InheritedProfilesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/configuration/InheritedProfilesTest.java @@ -42,6 +42,13 @@ public class InheritedProfilesTest extends AbstractDbUnitTestCase { } @Test + public void shouldRenameInheritedProfile() { + setupData("shouldCheckCycles"); + profilesManager.renameProfile(1, "newName"); + checkTables("shouldRenameInheritedProfile", "rules_profiles"); + } + + @Test public void shouldSetParent() { setupData("shouldSetParent"); profilesManager.changeParentProfile(2, "parent"); diff --git a/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRenameInheritedProfile-result.xml b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRenameInheritedProfile-result.xml new file mode 100644 index 00000000000..d42f80577cb --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/configuration/InheritedProfilesTest/shouldRenameInheritedProfile-result.xml @@ -0,0 +1,12 @@ +<dataset> + + <rules id="1" name="foo" description="test" plugin_config_key="checker/foo" + plugin_rule_key="checkstyle.rule1" plugin_name="plugin" enabled="true" cardinality="SINGLE" parent_id="[null]"/> + + <rules_profiles id="1" provided="false" name="newName" default_profile="0" language="java" parent_name="[null]"/> + + <rules_profiles id="2" provided="false" name="level2" default_profile="0" language="java" parent_name="newName"/> + + <rules_profiles id="3" provided="false" name="level3" default_profile="0" language="java" parent_name="level2"/> + +</dataset> |