]> source.dussan.org Git - sonarqube.git/commitdiff
Fix bug in ActiveRule.clone()
authorGodin <mandrikov@gmail.com>
Fri, 17 Dec 2010 09:04:09 +0000 (09:04 +0000)
committerGodin <mandrikov@gmail.com>
Fri, 17 Dec 2010 09:04:09 +0000 (09:04 +0000)
sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRule.java
sonar-server/src/main/java/org/sonar/server/configuration/ProfilesBackup.java
sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java
sonar-server/src/test/java/org/sonar/server/configuration/InheritedProfilesTest.java
sonar-server/src/test/java/org/sonar/server/configuration/ProfilesManagerTest.java

index a53c3f01c79a569febffbe1cab30a821fa6d3a22..9b0cd9565512c86fced0cfa7a22edae0e41c7884 100644 (file)
@@ -260,12 +260,14 @@ public class ActiveRule implements Cloneable {
 
   @Override
   public Object clone() {
-    ActiveRule clone = new ActiveRule(getRulesProfile(), getRule(), getSeverity());
+    final ActiveRule clone = new ActiveRule(getRulesProfile(), getRule(), getSeverity());
     clone.setInherited(isInherited());
     if (CollectionUtils.isNotEmpty(getActiveRuleParams())) {
       clone.setActiveRuleParams(new ArrayList<ActiveRuleParam>(CollectionUtils.collect(getActiveRuleParams(), new Transformer() {
         public Object transform(Object input) {
-          return ((ActiveRuleParam) input).clone();
+          ActiveRuleParam activeRuleParamClone = (ActiveRuleParam) ((ActiveRuleParam) input).clone();
+          activeRuleParamClone.setActiveRule(clone);
+          return activeRuleParamClone;
         }
       })));
     }
index c1259bb32b42a954a102fc05e484e35b2b1c2a45..67ef7de918541c3a5d7169b8fa58fc9c4ab1d289 100644 (file)
@@ -75,7 +75,7 @@ public class ProfilesBackup implements Backupable {
 
   public void importXml(SonarConfig sonarConfig) {
     if (CollectionUtils.isNotEmpty(sonarConfig.getProfiles())) {
-      ProfilesManager profilesManager = new ProfilesManager(session, null, null, null);
+      ProfilesManager profilesManager = new ProfilesManager(session, null);
       profilesManager.deleteAllProfiles();
 
       RulesDao rulesDao = new RulesDao(session);
index e92496bfd6fcb97a68d09636c7b7a7b885de9710..2cf094e8ac036ae8e1b74911d03b41b5e9edab3a 100644 (file)
  */
 package org.sonar.server.configuration;
 
-import org.sonar.api.Plugins;
 import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.database.model.ResourceModel;
 import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.ActiveRuleParam;
-import org.sonar.api.rules.DefaultRulesManager;
 import org.sonar.api.rules.Rule;
 import org.sonar.jpa.dao.BaseDao;
 import org.sonar.jpa.dao.RulesDao;
@@ -34,15 +31,11 @@ import java.util.List;
 
 public class ProfilesManager extends BaseDao {
 
-  private DefaultRulesManager rulesManager;
   private RulesDao rulesDao;
-  private Plugins plugins;
 
-  public ProfilesManager(DatabaseSession session, RulesDao rulesDao, Plugins plugins, DefaultRulesManager rulesManager) {
+  public ProfilesManager(DatabaseSession session, RulesDao rulesDao) {
     super(session);
-    this.rulesManager = rulesManager;
     this.rulesDao = rulesDao;
-    this.plugins = plugins;
   }
 
   public void copyProfile(int profileId, String newProfileName) {
@@ -133,10 +126,6 @@ public class ProfilesManager extends BaseDao {
       removeActiveRule(profile, activeRule);
     }
     activeRule = (ActiveRule) parentActiveRule.clone();
-    // TODO Godin: it means that we have bug in ActiveRule.clone()
-    for (ActiveRuleParam param : activeRule.getActiveRuleParams()) {
-      param.setActiveRule(activeRule);
-    }
     activeRule.setRulesProfile(profile);
     activeRule.setInherited(true);
     profile.getActiveRules().add(activeRule);
index 075ec844ffddfacd6b6d0579dcb7013e85311611..cd91617045bd64592c56e391c5b39abaf5b075c3 100644 (file)
@@ -9,7 +9,7 @@ public class InheritedProfilesTest extends AbstractDbUnitTestCase {
 
   @Before
   public void setUp() {
-    profilesManager = new ProfilesManager(getSession(), null, null, null);
+    profilesManager = new ProfilesManager(getSession(), null);
   }
 
   @Test
index 997ba67bb8a1c6a42f1e8975a0e2379727093dd1..2820933f37a4bbe661707c1d7357beeadfb267c4 100644 (file)
@@ -35,7 +35,7 @@ public class ProfilesManagerTest extends AbstractDbUnitTestCase {
 
   @Before
   public void setup() {
-    manager = new ProfilesManager(getSession(), null, null, null);
+    manager = new ProfilesManager(getSession(), null);
   }
 
   @Test