aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/main
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-01-15 22:54:26 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-01-15 22:54:26 +0100
commit93e365a6833d41304b654c2e9da87c58a694339e (patch)
tree841c265fa94ff1b33d5e1ffb91f3c5b5aa5f2286 /sonar-plugin-api/src/main
parentbc5680768a184c41e8c8871f8262ef607e01172c (diff)
downloadsonarqube-93e365a6833d41304b654c2e9da87c58a694339e.tar.gz
sonarqube-93e365a6833d41304b654c2e9da87c58a694339e.zip
SONAR-4908 move some classes to module sonar-deprecated
Diffstat (limited to 'sonar-plugin-api/src/main')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleDefinitions.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java115
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java79
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleUtils.java57
4 files changed, 1 insertions, 252 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleDefinitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleDefinitions.java
index 98d07f53cfb..996f1987a58 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleDefinitions.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleDefinitions.java
@@ -35,7 +35,7 @@ import java.util.Set;
* Defines the coding rules. For example the Java Findbugs plugin provides an implementation of
* this extension point in order to define the rules that it supports.
* <p/>
- * This interface replaces the deprecated class {@link org.sonar.api.rules.RuleRepository}.
+ * This interface replaces the deprecated class org.sonar.api.rules.RuleRepository.
*
* @since 4.2
*/
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java
deleted file mode 100644
index 0e93972d703..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.rules;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Functions;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.PropertyType;
-import org.sonar.api.ServerComponent;
-import org.sonar.api.utils.AnnotationUtils;
-import org.sonar.api.utils.FieldUtils2;
-import org.sonar.api.utils.SonarException;
-
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @since 2.3
- */
-public final class AnnotationRuleParser implements ServerComponent {
-
- private static final Logger LOG = LoggerFactory.getLogger(AnnotationRuleParser.class);
-
- public List<Rule> parse(String repositoryKey, Collection<Class> annotatedClasses) {
- List<Rule> rules = Lists.newArrayList();
- for (Class annotatedClass : annotatedClasses) {
- rules.add(create(repositoryKey, annotatedClass));
- }
- return rules;
- }
-
- private Rule create(String repositoryKey, Class annotatedClass) {
- org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClass, org.sonar.check.Rule.class);
- if (ruleAnnotation != null) {
- return toRule(repositoryKey, annotatedClass, ruleAnnotation);
- }
- LOG.warn("The class " + annotatedClass.getCanonicalName() + " should be annotated with " + Rule.class);
- return null;
- }
-
- private Rule toRule(String repositoryKey, Class clazz, org.sonar.check.Rule ruleAnnotation) {
- String ruleKey = StringUtils.defaultIfEmpty(ruleAnnotation.key(), clazz.getCanonicalName());
- String ruleName = StringUtils.defaultIfEmpty(ruleAnnotation.name(), null);
- String description = StringUtils.defaultIfEmpty(ruleAnnotation.description(), null);
- Rule rule = Rule.create(repositoryKey, ruleKey, ruleName);
- rule.setDescription(description);
- rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
- rule.setCardinality(ruleAnnotation.cardinality());
- rule.setStatus(ruleAnnotation.status());
-
- List<Field> fields = FieldUtils2.getFields(clazz, true);
- for (Field field : fields) {
- addRuleProperty(rule, field);
- }
- return rule;
- }
-
- private void addRuleProperty(Rule rule, Field field) {
- org.sonar.check.RuleProperty propertyAnnotation = field.getAnnotation(org.sonar.check.RuleProperty.class);
- if (propertyAnnotation != null) {
- String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName());
- RuleParam param = rule.createParameter(fieldKey);
- param.setDescription(propertyAnnotation.description());
- param.setDefaultValue(propertyAnnotation.defaultValue());
- if (!StringUtils.isBlank(propertyAnnotation.type())) {
- try {
- param.setType(PropertyType.valueOf(propertyAnnotation.type().trim()).name());
- } catch (IllegalArgumentException e) {
- throw new SonarException("Invalid property type [" + propertyAnnotation.type() + "]", e);
- }
- } else {
- param.setType(guessType(field.getType()).name());
- }
- }
- }
-
- private static final Function<Class<?>, PropertyType> TYPE_FOR_CLASS = Functions.forMap(
- ImmutableMap.<Class<?>, PropertyType> builder()
- .put(Integer.class, PropertyType.INTEGER)
- .put(int.class, PropertyType.INTEGER)
- .put(Float.class, PropertyType.FLOAT)
- .put(float.class, PropertyType.FLOAT)
- .put(Boolean.class, PropertyType.BOOLEAN)
- .put(boolean.class, PropertyType.BOOLEAN)
- .build(),
- PropertyType.STRING);
-
- @VisibleForTesting
- static PropertyType guessType(Class<?> type) {
- return TYPE_FOR_CLASS.apply(type);
- }
-}
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
deleted file mode 100644
index c0f0f03a292..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleRepository.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-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;
-
-/**
- * @since 2.3
- * @deprecated in 4.2. Replaced by {@link org.sonar.api.rule.RuleDefinitions}
- */
-@Deprecated
-public abstract class RuleRepository implements ServerExtension {
-
- private String key;
- private String language;
- private String name;
-
- protected RuleRepository(String key, String language) {
- this.key = key;
- this.language = language;
- }
-
- public final String getKey() {
- return key;
- }
-
- public final String getLanguage() {
- return language;
- }
-
- public final String getName() {
- return name;
- }
-
- public final String getName(boolean useKeyIfEmpty) {
- if (useKeyIfEmpty) {
- return StringUtils.defaultIfEmpty(name, key);
- }
- return name;
- }
-
- public final RuleRepository setName(String s) {
- this.name = s;
- return this;
- }
-
- public abstract List<Rule> createRules();
-
- @Override
- 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/RuleUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleUtils.java
deleted file mode 100644
index c6f2953d62d..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleUtils.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.rules;
-
-import java.util.Map;
-
-import org.apache.commons.configuration.Configuration;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.utils.KeyValueFormat;
-
-/**
- * A utility class to manipulate concepts around rules
- * @deprecated in 3.7. Commons Configuration must be replaced by {@link org.sonar.api.config.Settings}
- */
-@Deprecated
-public final class RuleUtils {
-
- private RuleUtils() {
- }
-
- /**
- * Gets a Map<RulePriority, Integer> containing the weights defined in the settings
- * Default value is used when the property is not set (see property key and default value in the class CoreProperties)
- *
- * @param configuration the Sonar configuration
- * @return a map
- */
- public static Map<RulePriority, Integer> getPriorityWeights(final Configuration configuration) {
- String levelWeight = configuration.getString(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY, CoreProperties.CORE_RULE_WEIGHTS_DEFAULT_VALUE);
-
- Map<RulePriority, Integer> weights = KeyValueFormat.parse(levelWeight, new KeyValueFormat.RulePriorityNumbersPairTransformer());
-
- for (RulePriority priority : RulePriority.values()) {
- if (!weights.containsKey(priority)) {
- weights.put(priority, 1);
- }
- }
- return weights;
- }
-}