From 191b5b45dbcb54ec71814ed617da6f2948c5c3a4 Mon Sep 17 00:00:00 2001 From: Godin Date: Mon, 25 Oct 2010 15:09:22 +0000 Subject: [PATCH] SONAR-1903: Fix problem with cloned rules and AnnotationCheckFactory --- .../java/org/sonar/api/checks/AnnotationCheckFactory.java | 6 +++--- .../org/sonar/api/checks/AnnotationCheckFactoryTest.java | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java b/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java index 918a755e16a..2e0d9f2883b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java @@ -19,7 +19,6 @@ */ package org.sonar.api.checks; -import com.google.common.collect.Maps; import org.apache.commons.lang.StringUtils; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.rules.ActiveRule; @@ -30,6 +29,8 @@ import org.sonar.check.CheckProperty; import org.sonar.check.Rule; import org.sonar.check.RuleProperty; +import com.google.common.collect.Maps; + import java.lang.reflect.Field; import java.util.Collection; import java.util.Map; @@ -46,7 +47,6 @@ public final class AnnotationCheckFactory extends CheckFactory { groupClassesByKey(checkClasses); } - public static AnnotationCheckFactory create(RulesProfile profile, String repositoryKey, Collection checkClasses) { AnnotationCheckFactory factory = new AnnotationCheckFactory(profile, repositoryKey, checkClasses); factory.init(); @@ -63,7 +63,7 @@ public final class AnnotationCheckFactory extends CheckFactory { } protected Object createCheck(ActiveRule activeRule) { - Class clazz = checkClassesByKey.get(activeRule.getRuleKey()); + Class clazz = checkClassesByKey.get(activeRule.getConfigKey()); if (clazz != null) { return instantiate(activeRule, clazz); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java index 4c4d4bdafb3..9b0e286506c 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java @@ -19,6 +19,7 @@ */ package org.sonar.api.checks; +import org.hamcrest.Matcher; import org.junit.Test; import org.sonar.api.profiles.RulesProfile; import org.sonar.api.rules.ActiveRule; @@ -134,12 +135,12 @@ public class AnnotationCheckFactoryTest { public void shouldWorkWithClonedRules() { RulesProfile profile = RulesProfile.create("repo", "java"); Rule rule = Rule.create("repo", "CheckWithKey", ""); - Rule clonedRule = Rule.create("repo", "CheckWithKey_2", "").setParent(rule); + Rule clonedRule = Rule.create("repo", "CheckWithKey_2", "").setConfigKey("CheckWithKey").setParent(rule); profile.activateRule(rule, null); profile.activateRule(clonedRule, null); AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays. asList(CheckWithKey.class)); - assertThat(factory.getChecks(), not(hasItems(nullValue()))); + assertThat(factory.getChecks(), (Matcher) not(hasItems(nullValue()))); } } -- 2.39.5