aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-10 13:04:24 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-10 13:04:24 +0000
commit23830d07ed51853724dc660fff187c9e5aa4b36a (patch)
tree6873e45ea9642bf45d91c4058dc1a5e54b8416c9
parent5cd839bbecd061d9463694d025788754bfca0f08 (diff)
downloadsonarqube-23830d07ed51853724dc660fff187c9e5aa4b36a.tar.gz
sonarqube-23830d07ed51853724dc660fff187c9e5aa4b36a.zip
* rename RuleProvider to RuleFinder
* deprecate some classes in the rule API * add the parameter ValidationMessages to ProfileDefinition.createPrototype()
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayProfileTest.java6
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfileTest.java6
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SunConventionsProfileTest.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java (renamed from sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleProvider.java)6
-rw-r--r--sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleFinderTest.java (renamed from sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleProviderTest.java)14
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/DefaultRuleFinderTest/shared.xml (renamed from sonar-core/src/test/resources/org/sonar/core/rule/DefaultRuleProviderTest/shared.xml)0
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/MetricThreshold.java127
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileDefinition.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileImporter.java21
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationExportable.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationImportable.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleProvider.java)2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriorityMapper.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleQuery.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java23
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Profile.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Property.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Rule.java1
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/platform/Platform.java4
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java3
-rw-r--r--sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java12
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java24
-rw-r--r--sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java5
29 files changed, 223 insertions, 71 deletions
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 4bce25c4af8..697a9c6685c 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
@@ -22,7 +22,9 @@ package org.sonar.plugins.checkstyle;
import org.junit.Test;
import org.sonar.api.profiles.ProfileDefinition;
import org.sonar.api.profiles.ProfilePrototype;
+import org.sonar.api.utils.ValidationMessages;
+import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.OrderingComparisons.greaterThan;
import static org.junit.Assert.assertThat;
@@ -31,8 +33,10 @@ public class SonarWayProfileTest {
@Test
public void create() {
ProfileDefinition sonarWay = new SonarWayProfile();
- ProfilePrototype prototype = sonarWay.createPrototype();
+ ValidationMessages validation = ValidationMessages.create();
+ ProfilePrototype prototype = sonarWay.createPrototype(validation);
assertThat(prototype.getRulesByRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).size(), greaterThan(1));
+ assertThat(validation.hasErrors(), is(false));
}
}
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 98d2b7a996e..ae6513bbfa2 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
@@ -19,8 +19,10 @@
*/
package org.sonar.plugins.checkstyle;
+import org.hamcrest.core.Is;
import org.junit.Test;
import org.sonar.api.profiles.ProfilePrototype;
+import org.sonar.api.utils.ValidationMessages;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;
@@ -29,8 +31,8 @@ public class SonarWayWithFindbugsProfileTest {
@Test
public void sameAsSonarWay() {
- ProfilePrototype withFindbugs = new SonarWayWithFindbugsProfile().createPrototype();
- ProfilePrototype withoutFindbugs = new SonarWayProfile().createPrototype();
+ ProfilePrototype withFindbugs = new SonarWayWithFindbugsProfile().createPrototype(ValidationMessages.create());
+ ProfilePrototype withoutFindbugs = new SonarWayProfile().createPrototype(ValidationMessages.create());
assertThat(withFindbugs.getRules().size(), is(withoutFindbugs.getRules().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 28c82ac350e..73eaa38e8e8 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
@@ -19,9 +19,11 @@
*/
package org.sonar.plugins.checkstyle;
+import org.hamcrest.core.Is;
import org.junit.Test;
import org.sonar.api.profiles.ProfileDefinition;
import org.sonar.api.profiles.ProfilePrototype;
+import org.sonar.api.utils.ValidationMessages;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.number.OrderingComparisons.greaterThan;
@@ -31,10 +33,12 @@ public class SunConventionsProfileTest {
@Test
public void create() {
ProfileDefinition sunConventionsProfile = new SunConventionsProfile();
- ProfilePrototype prototype = sunConventionsProfile.createPrototype();
+ ValidationMessages validation = ValidationMessages.create();
+ ProfilePrototype prototype = sunConventionsProfile.createPrototype(validation);
assertThat(prototype.getRulesByRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).size(), greaterThan(1));
assertThat(
prototype.getRule(CheckstyleConstants.REPOSITORY_KEY, "com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck").getParameter("lineSeparator"),
is("system"));
+ assertThat(validation.hasErrors(), Is.is(false));
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java
index 2f0894a2c61..48509f15dc5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java
@@ -34,7 +34,7 @@ import org.sonar.api.rules.DefaultRulesManager;
import org.sonar.api.utils.IocContainer;
import org.sonar.batch.indexer.DefaultSonarIndex;
import org.sonar.core.qualitymodel.DefaultModelProvider;
-import org.sonar.core.rule.DefaultRuleProvider;
+import org.sonar.core.rule.DefaultRuleFinder;
import org.sonar.jpa.dao.*;
public class ProjectBatch {
@@ -89,7 +89,7 @@ public class ProjectBatch {
batchContainer.as(Characteristics.CACHE).addComponent(ViolationFilters.class);
batchContainer.as(Characteristics.CACHE).addComponent(ResourceFilters.class);
batchContainer.as(Characteristics.CACHE).addComponent(DefaultModelProvider.class);
- batchContainer.as(Characteristics.CACHE).addComponent(DefaultRuleProvider.class);
+ batchContainer.as(Characteristics.CACHE).addComponent(DefaultRuleFinder.class);
batchContainer.addAdapter(new ProfileProvider());
batchContainer.addAdapter(new CheckProfileProvider());
loadCoreComponents(batchContainer);
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleProvider.java b/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java
index 0512cff60e9..6a167b180f7 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleProvider.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/DefaultRuleFinder.java
@@ -22,7 +22,7 @@ package org.sonar.core.rule;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleProvider;
+import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RuleQuery;
import org.sonar.jpa.session.DatabaseSessionFactory;
@@ -31,11 +31,11 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-public class DefaultRuleProvider implements RuleProvider {
+public class DefaultRuleFinder implements RuleFinder {
private DatabaseSessionFactory sessionFactory;
- public DefaultRuleProvider(DatabaseSessionFactory sessionFactory) {
+ public DefaultRuleFinder(DatabaseSessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
diff --git a/sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleProviderTest.java b/sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleFinderTest.java
index 69287804e8c..c80573be1c0 100644
--- a/sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleProviderTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/rule/DefaultRuleFinderTest.java
@@ -32,12 +32,12 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
-public class DefaultRuleProviderTest extends AbstractDbUnitTestCase {
+public class DefaultRuleFinderTest extends AbstractDbUnitTestCase {
@Test
public void findByKey() {
setupData("shared");
- DefaultRuleProvider provider = new DefaultRuleProvider(getSessionFactory());
+ DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
Rule rule = provider.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck");
assertNotNull(rule);
assertThat(rule.getKey(), is("com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"));
@@ -47,7 +47,7 @@ public class DefaultRuleProviderTest extends AbstractDbUnitTestCase {
@Test
public void findReturnsNullIfNoResults() {
setupData("shared");
- DefaultRuleProvider provider = new DefaultRuleProvider(getSessionFactory());
+ DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
assertNull(provider.findByKey("checkstyle", "unknown"));
assertNull(provider.find(RuleQuery.create().withRepositoryKey("checkstyle").withConfigKey("unknown")));
}
@@ -55,7 +55,7 @@ public class DefaultRuleProviderTest extends AbstractDbUnitTestCase {
@Test
public void findRepositoryRules() {
setupData("shared");
- DefaultRuleProvider provider = new DefaultRuleProvider(getSessionFactory());
+ DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
Collection<Rule> rules = provider.findAll(RuleQuery.create().withRepositoryKey("checkstyle"));
assertNotNull(rules);
assertThat(rules.size(), is(2)); // only enabled checkstyle rules
@@ -64,7 +64,7 @@ public class DefaultRuleProviderTest extends AbstractDbUnitTestCase {
@Test
public void findAllEnabled() {
setupData("shared");
- DefaultRuleProvider provider = new DefaultRuleProvider(getSessionFactory());
+ DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
Collection<Rule> rules = provider.findAll(RuleQuery.create());
assertNotNull(rules);
assertThat(rules.size(), is(3)); // only enabled checkstyle+pmd rules
@@ -76,7 +76,7 @@ public class DefaultRuleProviderTest extends AbstractDbUnitTestCase {
@Test
public void doNotFindDisabledRules() {
setupData("shared");
- DefaultRuleProvider provider = new DefaultRuleProvider(getSessionFactory());
+ DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
Rule rule = provider.findByKey("checkstyle", "DisabledCheck");
assertNull(rule);
}
@@ -84,7 +84,7 @@ public class DefaultRuleProviderTest extends AbstractDbUnitTestCase {
@Test
public void doNotFindUnknownRules() {
setupData("shared");
- DefaultRuleProvider provider = new DefaultRuleProvider(getSessionFactory());
+ DefaultRuleFinder provider = new DefaultRuleFinder(getSessionFactory());
Collection<Rule> rules = provider.findAll(RuleQuery.create().withRepositoryKey("unknown_repository"));
assertThat(rules.size(), is(0));
}
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/DefaultRuleProviderTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/rule/DefaultRuleFinderTest/shared.xml
index f6adafee0da..f6adafee0da 100644
--- a/sonar-core/src/test/resources/org/sonar/core/rule/DefaultRuleProviderTest/shared.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/rule/DefaultRuleFinderTest/shared.xml
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java
index c33c9bff795..e18e8e490ba 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileDefinition.java
@@ -20,6 +20,7 @@
package org.sonar.api.profiles;
import org.sonar.api.rules.RulePriority;
+import org.sonar.api.utils.ValidationMessages;
import org.sonar.check.AnnotationIntrospector;
import org.sonar.check.BelongsToProfile;
@@ -43,7 +44,7 @@ public abstract class AnnotationProfileDefinition extends ProfileDefinition {
}
@Override
- public ProfilePrototype createPrototype() {
+ public ProfilePrototype createPrototype(ValidationMessages validation) {
ProfilePrototype profile = ProfilePrototype.create(name, language);
if (annotatedClasses != null) {
for (Class aClass : annotatedClasses) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/MetricThreshold.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/MetricThreshold.java
new file mode 100644
index 00000000000..79c95a8a92d
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/MetricThreshold.java
@@ -0,0 +1,127 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.api.profiles;
+
+/**
+ * @since 2.3
+ */
+public final class MetricThreshold implements Cloneable {
+
+ /**
+ * Operator strictly greater than
+ */
+ public static final String OPERATOR_GREATER = ">";
+
+ /**
+ * Operator strictly lesser than
+ */
+ public static final String OPERATOR_SMALLER = "<";
+
+ /**
+ * Operator equals
+ */
+ public static final String OPERATOR_EQUALS = "=";
+
+ /**
+ * Operator not equals
+ */
+ public static final String OPERATOR_NOT_EQUALS = "!=";
+
+ private String metric;
+ private String operator;
+ private String valueError;
+ private String valueWarning;
+
+ private MetricThreshold() {
+ }
+
+ public static MetricThreshold create() {
+ return new MetricThreshold();
+ }
+
+ public static MetricThreshold createForMetric(String metricKey) {
+ return new MetricThreshold().setMetric(metricKey);
+ }
+
+ public String getMetric() {
+ return metric;
+ }
+
+ public MetricThreshold setMetric(String metric) {
+ this.metric = metric;
+ return this;
+ }
+
+ public String getOperator() {
+ return operator;
+ }
+
+ public MetricThreshold setOperator(String operator) {
+ this.operator = operator;
+ return this;
+ }
+
+ public String getValueError() {
+ return valueError;
+ }
+
+ public MetricThreshold setValueError(String valueError) {
+ this.valueError = valueError;
+ return this;
+ }
+
+ public String getValueWarning() {
+ return valueWarning;
+ }
+
+ public MetricThreshold setValueWarning(String valueWarning) {
+ this.valueWarning = valueWarning;
+ return this;
+ }
+
+ /**
+ * @return whether the operator is greater than
+ */
+ public boolean isGreaterOperator() {
+ return OPERATOR_GREATER.equals(operator);
+ }
+
+ /**
+ * @return whether the operator is lesser than
+ */
+ public boolean isSmallerOperator() {
+ return OPERATOR_SMALLER.equals(operator);
+ }
+
+ /**
+ * @return whether the operator is equals
+ */
+ public boolean isEqualsOperator() {
+ return OPERATOR_EQUALS.equals(operator);
+ }
+
+ /**
+ * @return whether the operator is not equals
+ */
+ public boolean isNotEqualsOperator() {
+ return OPERATOR_NOT_EQUALS.equals(operator);
+ }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java
index 8a8043c720f..4f14c50da4a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileDefinition.java
@@ -20,12 +20,13 @@
package org.sonar.api.profiles;
import org.sonar.api.ServerExtension;
+import org.sonar.api.utils.ValidationMessages;
/**
* @since 2.3
*/
public abstract class ProfileDefinition implements ServerExtension {
- public abstract ProfilePrototype createPrototype();
+ public abstract ProfilePrototype createPrototype(ValidationMessages validation);
} \ No newline at end of file
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java
index 01be1e63567..578f40b3578 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/RulesProfile.java
@@ -310,7 +310,9 @@ public class RulesProfile implements Cloneable {
@Override
public Object clone() {
- RulesProfile clone = new RulesProfile(getName(), getLanguage(), getDefaultProfile(), getProvided());
+ RulesProfile clone = RulesProfile.create(getName(), getLanguage());
+ clone.setDefaultProfile(getDefaultProfile());
+ clone.setProvided(getProvided());
if (CollectionUtils.isNotEmpty(getActiveRules())) {
clone.setActiveRules(new ArrayList<ActiveRule>(CollectionUtils.collect(getActiveRules(), new Transformer() {
public Object transform(Object input) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileDefinition.java
index 24888c0086d..759cbd7574c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileDefinition.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileDefinition.java
@@ -47,17 +47,12 @@ public abstract class XMLProfileDefinition extends ProfileDefinition {
}
@Override
- public final ProfilePrototype createPrototype() {
+ public final ProfilePrototype createPrototype(ValidationMessages validation) {
Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), Charset.forName(CharEncoding.UTF_8));
try {
- ValidationMessages validation = ValidationMessages.create();
ProfilePrototype profile = XMLProfileImporter.create().importProfile(reader, validation);
profile.setName(name);
profile.setLanguage(language);
- if (validation.hasErrors()) {
- // TODO do not loose messages
- throw new SonarException("Fail to parse the file: " + xmlClassPath);
- }
return profile;
} finally {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileImporter.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileImporter.java
index 92f3946b4a6..b6aaf58050f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileImporter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileImporter.java
@@ -46,15 +46,7 @@ public final class XMLProfileImporter {
public ProfilePrototype importProfile(Reader reader, ValidationMessages messages) {
ProfilePrototype profile = ProfilePrototype.create();
-
- XMLInputFactory xmlFactory = XMLInputFactory2.newInstance();
- xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
- xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
- // just so it won't try to load DTD in if there's DOCTYPE
- xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
- xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
-
- SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
+ SMInputFactory inputFactory = initStax();
try {
SMHierarchicCursor rootC = inputFactory.rootElementCursor(reader);
rootC.advance(); // <profile>
@@ -72,6 +64,17 @@ public final class XMLProfileImporter {
return profile;
}
+ private SMInputFactory initStax() {
+ XMLInputFactory xmlFactory = XMLInputFactory2.newInstance();
+ xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
+ xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
+ // just so it won't try to load DTD in if there's DOCTYPE
+ xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
+ xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
+ SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
+ return inputFactory;
+ }
+
private void processRules(SMInputCursor rulesCursor, ProfilePrototype profile) throws XMLStreamException {
while (rulesCursor.getNext() != null) {
SMInputCursor ruleCursor = rulesCursor.childElementCursor();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationExportable.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationExportable.java
index 46c9d17fda4..3a853a6ab3f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationExportable.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationExportable.java
@@ -21,6 +21,7 @@ package org.sonar.api.rules;
import org.sonar.api.profiles.RulesProfile;
+@Deprecated
public interface ConfigurationExportable {
String exportConfiguration(RulesProfile profile);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationImportable.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationImportable.java
index 07e60fd8f34..20e68fe3eed 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationImportable.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ConfigurationImportable.java
@@ -21,6 +21,7 @@ package org.sonar.api.rules;
import java.util.List;
+@Deprecated
public interface ConfigurationImportable {
List<ActiveRule> importConfiguration(String configuration, List<Rule> rules);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleProvider.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java
index 99e4ac55882..83581280908 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleProvider.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleFinder.java
@@ -27,7 +27,7 @@ import java.util.Collection;
/**
* @since 2.3
*/
-public interface RuleProvider extends BatchComponent, ServerComponent {
+public interface RuleFinder extends BatchComponent, ServerComponent {
Rule findByKey(String repositoryKey, String key);
Rule find(RuleQuery query);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriorityMapper.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriorityMapper.java
index 570c951561f..c8a382ecd89 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriorityMapper.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RulePriorityMapper.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.rules;
+@Deprecated
public interface RulePriorityMapper<IN_TYPE, OUT_TYPE> {
RulePriority from(IN_TYPE priority);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleQuery.java
index a3443c952ff..8d434e0654a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleQuery.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleQuery.java
@@ -28,6 +28,9 @@ public final class RuleQuery {
private String key = null;
private String configKey = null;
+ /**
+ * Use the factory method <code>create()</code>
+ */
RuleQuery() {
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java
index 3c21c975026..755aa90c094 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java
@@ -20,6 +20,8 @@
package org.sonar.api.rules;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.ServerExtension;
import java.util.List;
@@ -64,21 +66,12 @@ public abstract class RuleRepository implements ServerExtension {
public abstract List<Rule> createRules();
-
- @Override
- public final boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- RuleRepository that = (RuleRepository)o;
- return key.equals(that.key);
- }
-
@Override
- public final int hashCode() {
- return key.hashCode();
+ public String toString() {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("key", key)
+ .append("language", language)
+ .append("name", name)
+ .toString();
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java
index 5dec9920fe1..272b9642889 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/StandardProfileXmlParser.java
@@ -29,6 +29,7 @@ import org.sonar.api.utils.SonarException;
import java.util.ArrayList;
import java.util.List;
+@Deprecated
public class StandardProfileXmlParser {
private final List<Rule> rules;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Profile.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Profile.java
index 8ec21f61004..cd40e8a1f0e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Profile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Profile.java
@@ -26,6 +26,7 @@ import com.thoughtworks.xstream.annotations.XStreamImplicit;
import java.util.ArrayList;
import java.util.List;
+@Deprecated
@XStreamAlias("profile")
public class Profile {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Property.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Property.java
index eb338f1ab82..8e6dbec7670 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Property.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Property.java
@@ -22,6 +22,7 @@ package org.sonar.api.rules.xml;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
+@Deprecated
@XStreamAlias("property")
public class Property {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Rule.java
index 8f008aacaec..e424d1466a6 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/xml/Rule.java
@@ -26,6 +26,7 @@ import com.thoughtworks.xstream.annotations.XStreamImplicit;
import java.util.ArrayList;
import java.util.List;
+@Deprecated
@XStreamAlias("rule")
public class Rule implements Comparable<String> {
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java
index 995a4aeb626..98442f40957 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileDefinitionTest.java
@@ -38,8 +38,10 @@ public class AnnotationProfileDefinitionTest {
@Test
public void importProfile() {
ProfileDefinition definition = new FakeDefinition();
- ProfilePrototype profile = definition.createPrototype();
+ ValidationMessages validation = ValidationMessages.create();
+ ProfilePrototype profile = definition.createPrototype(validation);
assertThat(profile.getRule("squid", "fake").getPriority(), is(RulePriority.BLOCKER));
+ assertThat(validation.hasErrors(), is(false));
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
index 1a5313f91c1..bab61bf655f 100644
--- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
+++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
@@ -35,7 +35,7 @@ import org.sonar.api.utils.IocContainer;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.core.plugin.JpaPluginDao;
import org.sonar.core.qualitymodel.DefaultModelProvider;
-import org.sonar.core.rule.DefaultRuleProvider;
+import org.sonar.core.rule.DefaultRuleFinder;
import org.sonar.jpa.dao.*;
import org.sonar.jpa.session.DatabaseSessionFactory;
import org.sonar.jpa.session.DatabaseSessionProvider;
@@ -173,7 +173,7 @@ public final class Platform {
servicesContainer.as(Characteristics.NO_CACHE).addComponent(Backup.class);
servicesContainer.as(Characteristics.CACHE).addComponent(AuthenticatorFactory.class);
servicesContainer.as(Characteristics.CACHE).addComponent(ServerLifecycleNotifier.class);
- servicesContainer.as(Characteristics.CACHE).addComponent(DefaultRuleProvider.class);
+ servicesContainer.as(Characteristics.CACHE).addComponent(DefaultRuleFinder.class);
servicesContainer.as(Characteristics.CACHE).addComponent(DeprecatedRuleRepositories.class);
servicesContainer.as(Characteristics.CACHE).addComponent(DeprecatedProfiles.class);
servicesContainer.as(Characteristics.CACHE).addComponent(DeprecatedProfileExporters.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java
index 17b42d3df23..90a87b695bc 100644
--- a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java
+++ b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java
@@ -31,6 +31,7 @@ import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.ActiveRuleParam;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.RulesRepository;
+import org.sonar.api.utils.ValidationMessages;
import java.util.ArrayList;
import java.util.List;
@@ -140,7 +141,7 @@ public final class DeprecatedProfiles {
}
@Override
- public ProfilePrototype createPrototype() {
+ public ProfilePrototype createPrototype(ValidationMessages validation) {
return prototype;
}
diff --git a/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java b/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
index 9e66f2ca222..3f9451f903b 100644
--- a/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
+++ b/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java
@@ -26,7 +26,7 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.profiles.*;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleProvider;
+import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RuleQuery;
import org.sonar.api.utils.ValidationMessages;
import org.sonar.jpa.session.DatabaseSessionFactory;
@@ -42,14 +42,14 @@ import java.util.Map;
public final class ProfilesConsole implements ServerComponent {
private DatabaseSessionFactory sessionFactory;
- private RuleProvider ruleProvider;
+ private RuleFinder ruleFinder;
private List<ProfileExporter> profileExporters = new ArrayList<ProfileExporter>();
private List<ProfileImporter> profileImporters = new ArrayList<ProfileImporter>();
- public ProfilesConsole(DatabaseSessionFactory sessionFactory, RuleProvider ruleProvider,
+ public ProfilesConsole(DatabaseSessionFactory sessionFactory, RuleFinder ruleFinder,
ProfileExporter[] exporters, DeprecatedProfileExporters deprecatedExporters,
ProfileImporter[] importers) {
- this.ruleProvider = ruleProvider;
+ this.ruleFinder = ruleFinder;
this.sessionFactory = sessionFactory;
initProfileExporters(exporters, deprecatedExporters);
this.profileImporters.addAll(Arrays.asList(importers));
@@ -110,10 +110,10 @@ public final class ProfilesConsole implements ServerComponent {
private Rule findRule(ProfilePrototype.RulePrototype rulePrototype) {
if (StringUtils.isNotBlank(rulePrototype.getKey())) {
- return ruleProvider.findByKey(rulePrototype.getRepositoryKey(), rulePrototype.getKey());
+ return ruleFinder.findByKey(rulePrototype.getRepositoryKey(), rulePrototype.getKey());
}
if (StringUtils.isNotBlank(rulePrototype.getConfigKey())) {
- return ruleProvider.find(RuleQuery.create().withRepositoryKey(rulePrototype.getRepositoryKey()).withConfigKey(rulePrototype.getConfigKey()));
+ return ruleFinder.find(RuleQuery.create().withRepositoryKey(rulePrototype.getRepositoryKey()).withConfigKey(rulePrototype.getConfigKey()));
}
return null;
}
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
index 999d065f605..06fb6390035 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java
@@ -28,9 +28,10 @@ import org.sonar.api.profiles.ProfilePrototype;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleProvider;
+import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RuleQuery;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.api.utils.ValidationMessages;
import org.sonar.jpa.session.DatabaseSessionFactory;
import org.sonar.server.rules.DeprecatedProfiles;
@@ -43,14 +44,14 @@ public final class RegisterProvidedProfiles {
private static final Logger LOGGER = LoggerFactory.getLogger(RegisterProvidedProfiles.class);
- private RuleProvider ruleProvider;
+ private RuleFinder ruleFinder;
private DatabaseSessionFactory sessionFactory;
private List<ProfileDefinition> definitions = new ArrayList<ProfileDefinition>();
- public RegisterProvidedProfiles(RuleProvider ruleProvider, DatabaseSessionFactory sessionFactory,
+ public RegisterProvidedProfiles(RuleFinder ruleFinder, DatabaseSessionFactory sessionFactory,
DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore,
ProfileDefinition[] definitions) {
- this.ruleProvider = ruleProvider;
+ this.ruleFinder = ruleFinder;
this.sessionFactory = sessionFactory;
this.definitions.addAll(Arrays.asList(definitions));
if (deprecatedBridge != null) {
@@ -58,9 +59,9 @@ public final class RegisterProvidedProfiles {
}
}
- public RegisterProvidedProfiles(RuleProvider ruleProvider, DatabaseSessionFactory sessionFactory,
+ public RegisterProvidedProfiles(RuleFinder ruleFinder, DatabaseSessionFactory sessionFactory,
DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore) {
- this.ruleProvider = ruleProvider;
+ this.ruleFinder = ruleFinder;
this.sessionFactory = sessionFactory;
if (deprecatedBridge != null) {
this.definitions.addAll(deprecatedBridge.getProfiles());
@@ -80,7 +81,12 @@ public final class RegisterProvidedProfiles {
List<ProfilePrototype> createPrototypes() {
List<ProfilePrototype> result = new ArrayList<ProfilePrototype>();
for (ProfileDefinition definition : definitions) {
- result.add(definition.createPrototype());
+ ValidationMessages validation = ValidationMessages.create();
+ ProfilePrototype prototype = definition.createPrototype(validation);
+ validation.log(LOGGER);
+ if (prototype != null && !validation.hasErrors()) {
+ result.add(prototype);
+ }
}
return result;
}
@@ -136,10 +142,10 @@ public final class RegisterProvidedProfiles {
private Rule findRule(ProfilePrototype.RulePrototype rulePrototype) {
if (StringUtils.isNotBlank(rulePrototype.getKey())) {
- return ruleProvider.findByKey(rulePrototype.getRepositoryKey(), rulePrototype.getKey());
+ return ruleFinder.findByKey(rulePrototype.getRepositoryKey(), rulePrototype.getKey());
}
if (StringUtils.isNotBlank(rulePrototype.getConfigKey())) {
- return ruleProvider.find(RuleQuery.create().withRepositoryKey(rulePrototype.getRepositoryKey()).withConfigKey(rulePrototype.getConfigKey()));
+ return ruleFinder.find(RuleQuery.create().withRepositoryKey(rulePrototype.getRepositoryKey()).withConfigKey(rulePrototype.getConfigKey()));
}
return null;
}
diff --git a/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java b/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java
index 373f7369654..90ef31a03e3 100644
--- a/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java
@@ -21,6 +21,7 @@ package org.sonar.server.rules;
import org.junit.Test;
import org.sonar.api.rules.RulePriority;
+import org.sonar.api.utils.ValidationMessages;
import org.sonar.server.rules.DeprecatedProfiles;
import static org.hamcrest.Matchers.is;
@@ -31,8 +32,8 @@ public class DeprecatedProfilesTest {
@Test
public void testCreate() {
DeprecatedProfiles.DefaultProfileDefinition def = DeprecatedProfiles.DefaultProfileDefinition.create("sonar way", "java");
- assertThat(def.createPrototype().getName(), is("sonar way"));
- assertThat(def.createPrototype().getLanguage(), is("java"));
+ assertThat(def.createPrototype(ValidationMessages.create()).getName(), is("sonar way"));
+ assertThat(def.createPrototype(ValidationMessages.create()).getLanguage(), is("java"));
}
@Test