]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 - Fixed ActiveRule Inheritance ENUMs to match org.sonar.core ones
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 30 May 2014 15:14:45 +0000 (17:14 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Fri, 30 May 2014 15:14:45 +0000 (17:14 +0200)
sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/ActiveRule.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivationContextFactory.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java

index e7a059a9da8aae582ff27ec1bd5e2fdb3c8b198b..9c36eed507752d84d000433569508c7394625b05 100644 (file)
@@ -25,6 +25,7 @@ import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.api.rules.ActiveRule;
 import org.sonar.core.persistence.Dto;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.core.rule.SeverityUtil;
@@ -35,8 +36,8 @@ import javax.persistence.Transient;
 
 public class ActiveRuleDto extends Dto<ActiveRuleKey> {
 
-  public static final String INHERITED = "INHERITED";
-  public static final String OVERRIDES = "OVERRIDES";
+  public static final String INHERITED = ActiveRule.INHERITED;
+  public static final String OVERRIDES = ActiveRule.OVERRIDES;
 
   private String repository;
   private String ruleField;
@@ -120,6 +121,9 @@ public class ActiveRuleDto extends Dto<ActiveRuleKey> {
   }
 
   public ActiveRuleDto setInheritance(@Nullable String inheritance) {
+    if(inheritance != null && !inheritance.equals(INHERITED) && !inheritance.equals(OVERRIDES)){
+      throw new IllegalStateException("Inheritance value '"+inheritance+"' is invalid");
+    }
     this.inheritance = inheritance;
     return this;
   }
index ef0c306589cf1e840468f8d844c61de432578525..5258c43bc15bec99b4527c71e3581aafd2d988ef 100644 (file)
  */
 package org.sonar.server.qualityprofile;
 
+import com.google.common.collect.ImmutableList;
 import org.sonar.core.qualityprofile.db.ActiveRuleKey;
 
 import javax.annotation.CheckForNull;
+import java.util.List;
 import java.util.Map;
 
 public interface ActiveRule {
 
   public enum Inheritance {
-    NONE, OVERRIDE, INHERIT
+    NONE, OVERRIDES, INHERITED;
+    public static final List<Inheritance> ALL = ImmutableList.of(NONE, OVERRIDES, INHERITED);
   }
 
   ActiveRuleKey key();
 
   String severity();
 
-  Inheritance  inheritance();
+  Inheritance inheritance();
 
   @CheckForNull
   ActiveRuleKey parentKey();
index 5fc6ac8b52cf3a85dd6a97a6ef55de1a50cbce58..c4710af81719a2acb4f55b0bdbdc63de506c1abf 100644 (file)
@@ -79,8 +79,7 @@ public class RuleActivationContextFactory implements ServerComponent {
   }
 
   private QualityProfileDto initProfile(ActiveRuleKey key, RuleActivationContext context, DbSession session, boolean parent) {
-    QualityProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(
-      key.qProfile().name(), key.qProfile().lang());
+    QualityProfileDto profile = db.qualityProfileDao().getByKey(key.qProfile(),session);
     if (profile == null) {
       throw new IllegalArgumentException("Quality profile not found: " + key.qProfile());
     }
index c6769801be9ed7fae8517feb18e0d2eed452b621..ca07838e2daa9efeeda4d4cf628e9eada3101a62 100644 (file)
@@ -56,9 +56,9 @@ public class ActiveRuleDoc extends BaseDoc implements ActiveRule {
       inheritance.toLowerCase().contains("none")) {
       return Inheritance.NONE;
     } else if (inheritance.toLowerCase().contains("herit")) {
-      return Inheritance.INHERIT;
+      return Inheritance.INHERITED;
     } else if (inheritance.toLowerCase().contains("over")) {
-      return Inheritance.OVERRIDE;
+      return Inheritance.OVERRIDES;
     } else {
       throw new IllegalStateException("Value \"" + inheritance + "\" is not valid for rule's inheritance");
     }