aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-10-08 14:38:32 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-10-08 14:38:32 +0000
commit7ca495d67492c6b3dbb653102e345f8fc43f09ae (patch)
tree2dd4d54faaad9c4c74f172fba50bdfb5f3b734c8 /plugins
parent9185222d18826c0648a8bf3cf8e2e491537b472e (diff)
downloadsonarqube-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')
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayProfile.java18
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfile.java3
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SunConventionsProfile.java20
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayProfileTest.java5
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfileTest.java7
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SunConventionsProfileTest.java5
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsRuleRepository.java10
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java2
-rw-r--r--plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java2
-rw-r--r--plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java2
-rw-r--r--plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java2
11 files changed, 43 insertions, 33 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));
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsRuleRepository.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsRuleRepository.java
index bf4b11febb6..0f43b2cd4d2 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsRuleRepository.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsRuleRepository.java
@@ -19,15 +19,13 @@
*/
package org.sonar.plugins.findbugs;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.sonar.api.platform.ServerFileSystem;
import org.sonar.api.resources.Java;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.rules.XMLRuleParser;
+import java.util.List;
+
public final class FindbugsRuleRepository extends RuleRepository {
public FindbugsRuleRepository() {
@@ -37,8 +35,6 @@ public final class FindbugsRuleRepository extends RuleRepository {
@Override
public List<Rule> createRules() {
- List<Rule> rules = new ArrayList<Rule>();
- rules.addAll(XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/plugins/findbugs/rules.xml")));
- return rules;
+ return XMLRuleParser.parseXML(getClass().getResourceAsStream("/org/sonar/plugins/findbugs/rules.xml"));
}
}
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java
index 0d1e3b73112..881fbf9a36b 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/SonarWayWithFindbugsProfileTest.java
@@ -30,7 +30,7 @@ import org.sonar.api.utils.ValidationMessages;
public class SonarWayWithFindbugsProfileTest {
@Test
- public void create() {
+ public void shouldCreateProfile() {
FindbugsProfileImporter importer = new FindbugsProfileImporter(new FindbugsRuleFinder());
SonarWayWithFindbugsProfile sonarWayWithFindbugs = new SonarWayWithFindbugsProfile(importer);
ValidationMessages validation = ValidationMessages.create();
diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java
index 966021adfc4..844dfa9100e 100644
--- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java
+++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayProfileTest.java
@@ -40,7 +40,7 @@ import org.sonar.api.utils.ValidationMessages;
public class SonarWayProfileTest {
@Test
- public void create() {
+ public void shouldCreateProfile() {
ProfileDefinition sonarWay = new SonarWayProfile(createPmdProfileImporter());
ValidationMessages validation = ValidationMessages.create();
RulesProfile profile = sonarWay.createProfile(validation);
diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java
index 95f8ffc4592..7f0aa81c969 100644
--- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java
+++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SonarWayWithFindbugsProfileTest.java
@@ -39,7 +39,7 @@ import org.sonar.api.utils.ValidationMessages;
public class SonarWayWithFindbugsProfileTest {
@Test
- public void create() {
+ public void shouldCreateProfile() {
SonarWayWithFindbugsProfile sonarWayWithFindbugs = new SonarWayWithFindbugsProfile(new SonarWayProfile(createPmdProfileImporter()));
ValidationMessages validation = ValidationMessages.create();
RulesProfile profile = sonarWayWithFindbugs.createProfile(validation);
diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java
index bd9a6f9fffb..cdd9f1e396d 100644
--- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java
+++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/SunConventionsProfileTest.java
@@ -38,7 +38,7 @@ import org.sonar.api.utils.ValidationMessages;
public class SunConventionsProfileTest {
@Test
- public void create() {
+ public void shouldCreateProfile() {
SunConventionsProfile sunConvention = new SunConventionsProfile(createPmdProfileImporter());
ValidationMessages validation = ValidationMessages.create();
RulesProfile profile = sunConvention.createProfile(validation);