diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-10-08 14:38:32 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-10-08 14:38:32 +0000 |
commit | 7ca495d67492c6b3dbb653102e345f8fc43f09ae (patch) | |
tree | 2dd4d54faaad9c4c74f172fba50bdfb5f3b734c8 /plugins/sonar-checkstyle-plugin | |
parent | 9185222d18826c0648a8bf3cf8e2e491537b472e (diff) | |
download | sonarqube-7ca495d67492c6b3dbb653102e345f8fc43f09ae.tar.gz sonarqube-7ca495d67492c6b3dbb653102e345f8fc43f09ae.zip |
API: improve the pattern to define quality profiles. The extension point is org.sonar.api.profiles.ProfileDefinition, whereas XMLProfileParser and AnnotationProfileParser are components that can be used but not extended.
Diffstat (limited to 'plugins/sonar-checkstyle-plugin')
6 files changed, 36 insertions, 22 deletions
diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayProfile.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayProfile.java index a189560a695..a0cf3410ce0 100644 --- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayProfile.java +++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayProfile.java @@ -19,14 +19,20 @@ */ package org.sonar.plugins.checkstyle; +import org.sonar.api.profiles.ProfileDefinition; import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.profiles.XMLProfileDefinition; -import org.sonar.api.resources.Java; -import org.sonar.api.rules.RuleFinder; +import org.sonar.api.profiles.XMLProfileParser; +import org.sonar.api.utils.ValidationMessages; -public final class SonarWayProfile extends XMLProfileDefinition { +public final class SonarWayProfile extends ProfileDefinition { - public SonarWayProfile(RuleFinder ruleFinder) { - super(SunConventionsProfile.class.getClassLoader(), "org/sonar/plugins/checkstyle/profile-sonar-way.xml", ruleFinder); + private XMLProfileParser xmlProfileParser; + + public SonarWayProfile(XMLProfileParser xmlProfileParser) { + this.xmlProfileParser = xmlProfileParser; + } + + public RulesProfile createProfile(ValidationMessages messages) { + return xmlProfileParser.parseResource(getClass().getClassLoader(), "org/sonar/plugins/checkstyle/profile-sonar-way.xml", messages); } } diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfile.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfile.java index 398f137c451..d9b26e2b43f 100644 --- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfile.java +++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfile.java @@ -21,9 +21,6 @@ package org.sonar.plugins.checkstyle; import org.sonar.api.profiles.ProfileDefinition; import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.profiles.XMLProfileDefinition; -import org.sonar.api.resources.Java; -import org.sonar.api.rules.RuleFinder; import org.sonar.api.utils.ValidationMessages; public class SonarWayWithFindbugsProfile extends ProfileDefinition { diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SunConventionsProfile.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SunConventionsProfile.java index 6351afed31c..82b0e8b7177 100644 --- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SunConventionsProfile.java +++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SunConventionsProfile.java @@ -19,14 +19,22 @@ */ package org.sonar.plugins.checkstyle; +import org.sonar.api.profiles.ProfileDefinition; import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.profiles.XMLProfileDefinition; -import org.sonar.api.resources.Java; -import org.sonar.api.rules.RuleFinder; +import org.sonar.api.profiles.XMLProfileParser; +import org.sonar.api.utils.ValidationMessages; -public final class SunConventionsProfile extends XMLProfileDefinition { +public final class SunConventionsProfile extends ProfileDefinition { - public SunConventionsProfile(RuleFinder ruleFinder) { - super(SunConventionsProfile.class.getClassLoader(), "org/sonar/plugins/checkstyle/profile-sun-conventions.xml", ruleFinder); + private XMLProfileParser xmlProfileParser; + + public SunConventionsProfile(XMLProfileParser xmlProfileParser) { + this.xmlProfileParser = xmlProfileParser; } + + + public RulesProfile createProfile(ValidationMessages messages) { + return xmlProfileParser.parseResource(getClass().getClassLoader(), "org/sonar/plugins/checkstyle/profile-sun-conventions.xml", messages); + } + } diff --git a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayProfileTest.java b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayProfileTest.java index 268f94fe15b..23a39650517 100644 --- a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayProfileTest.java +++ b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayProfileTest.java @@ -24,6 +24,7 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.sonar.api.profiles.ProfileDefinition; import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.profiles.XMLProfileParser; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.utils.ValidationMessages; @@ -38,8 +39,8 @@ import static org.mockito.Mockito.when; public class SonarWayProfileTest { @Test - public void create() { - ProfileDefinition sonarWay = new SonarWayProfile(newRuleFinder()); + public void shouldCreateProfile() { + ProfileDefinition sonarWay = new SonarWayProfile(new XMLProfileParser(newRuleFinder())); ValidationMessages validation = ValidationMessages.create(); RulesProfile profile = sonarWay.createProfile(validation); assertThat(profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY).size(), greaterThan(1)); diff --git a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfileTest.java b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfileTest.java index 6ed6bbca83c..d5af6c0b236 100644 --- a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfileTest.java +++ b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfileTest.java @@ -23,11 +23,12 @@ import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.profiles.XMLProfileParser; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.utils.ValidationMessages; -import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; @@ -36,9 +37,9 @@ import static org.mockito.Mockito.when; public class SonarWayWithFindbugsProfileTest { @Test - public void sameAsSonarWay() { + public void shouldBeSameAsSonarWay() { RuleFinder ruleFinder = newRuleFinder(); - SonarWayProfile sonarWay = new SonarWayProfile(ruleFinder); + SonarWayProfile sonarWay = new SonarWayProfile(new XMLProfileParser(ruleFinder)); RulesProfile withoutFindbugs = sonarWay.createProfile(ValidationMessages.create()); RulesProfile withFindbugs = new SonarWayWithFindbugsProfile(sonarWay).createProfile(ValidationMessages.create()); assertThat(withFindbugs.getActiveRules().size(), is(withoutFindbugs.getActiveRules().size())); diff --git a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SunConventionsProfileTest.java b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SunConventionsProfileTest.java index ff80d97a02e..147006e30eb 100644 --- a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SunConventionsProfileTest.java +++ b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SunConventionsProfileTest.java @@ -25,6 +25,7 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.sonar.api.profiles.ProfileDefinition; import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.profiles.XMLProfileParser; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.utils.ValidationMessages; @@ -37,8 +38,8 @@ import static org.mockito.Mockito.when; public class SunConventionsProfileTest { @Test - public void create() { - ProfileDefinition definition = new SunConventionsProfile(newRuleFinder()); + public void shouldCreateProfile() { + ProfileDefinition definition = new SunConventionsProfile(new XMLProfileParser(newRuleFinder())); ValidationMessages validation = ValidationMessages.create(); RulesProfile sunProfile = definition.createProfile(validation); assertThat(sunProfile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY).size(), greaterThan(1)); |