From: Simon Brandhof Date: Thu, 16 Aug 2012 16:00:48 +0000 (+0200) Subject: SONAR-3706 API : remove the deprecated annotation org.sonar.check.Check X-Git-Tag: 3.3~340 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=faa012f7b03c7e62dcd6aefd59bbad0c6b4be351;p=sonarqube.git SONAR-3706 API : remove the deprecated annotation org.sonar.check.Check --- diff --git a/sonar-check-api/src/main/java/org/sonar/check/Check.java b/sonar-check-api/src/main/java/org/sonar/check/Check.java deleted file mode 100644 index b96b655dd3e..00000000000 --- a/sonar-check-api/src/main/java/org/sonar/check/Check.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * 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.check; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @since 2.1 (experimental) - * @deprecated since 2.3. Use @Rule - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -@Deprecated -public @interface Check { - - /** - * The default key is the class name. - */ - String key() default ""; - - /** - * The path to resource bundles (optional). If not set, then it equals the class name. - */ - String bundle() default ""; - - /** - * The check title. If not defined, then the title is the key - */ - String title() default ""; - - /** - * The check description, optional. - */ - String description() default ""; - - /** - * Default priority. - */ - Priority priority() default Priority.MAJOR; - - /** - * Will probably be deprecated and replaced by tags - * - * @deprecated since 2.5. See http://jira.codehaus.org/browse/SONAR-2007 - */ - @Deprecated - IsoCategory isoCategory(); -} diff --git a/sonar-check-api/src/main/java/org/sonar/check/CheckProperty.java b/sonar-check-api/src/main/java/org/sonar/check/CheckProperty.java deleted file mode 100644 index 64ba5859034..00000000000 --- a/sonar-check-api/src/main/java/org/sonar/check/CheckProperty.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * 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.check; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @since 2.1 (experimental) - * @deprecated since 2.3. Use @RuleProperty - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Deprecated -public @interface CheckProperty { - - /** - * The default key is the field name, read by reflection. Overriding this key can be useful when - * obfuscating the code. - */ - String key() default ""; - - String title() default ""; - - /** - * Optional description - */ - String description() default ""; -} diff --git a/sonar-check-api/src/test/java/org/sonar/check/AnnotationIntrospectorTest.java b/sonar-check-api/src/test/java/org/sonar/check/AnnotationIntrospectorTest.java deleted file mode 100644 index 0370e8e1ded..00000000000 --- a/sonar-check-api/src/test/java/org/sonar/check/AnnotationIntrospectorTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * 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.check; - - -@Check(isoCategory = IsoCategory.Portability, priority = Priority.CRITICAL) -class SimplestCheck { - -} - -@Check(key = "overridenKey", isoCategory = IsoCategory.Portability, priority = Priority.CRITICAL) -class CheckWithOverridenKey { - -} - -@Check(isoCategory = IsoCategory.Portability, priority = Priority.CRITICAL) -class CheckWithProperties { - - @CheckProperty - private boolean active = false; - - @CheckProperty(key = "Maximum") - private int max = 50; - - private String nonProperty; -} \ No newline at end of file diff --git a/sonar-check-api/src/test/java/org/sonar/check/CheckTest.java b/sonar-check-api/src/test/java/org/sonar/check/CheckTest.java deleted file mode 100644 index 10c690480e6..00000000000 --- a/sonar-check-api/src/test/java/org/sonar/check/CheckTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * 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.check; - -import org.junit.Test; - -import java.lang.reflect.Field; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -public class CheckTest { - @Test - public void getCheckMetadata() { - Check check = FakeCheck.class.getAnnotation(Check.class); - assertThat(check.title(), is("Detailed Check")); - assertThat(check.description(), is("Detailed description")); - } - - @Test - public void getCheckProperty() throws NoSuchFieldException { - Field field = FakeCheck.class.getDeclaredField("max"); - CheckProperty propertyAnnotation = field.getAnnotation(CheckProperty.class); - assertThat(propertyAnnotation.description(), is("Maximum value")); - } -} diff --git a/sonar-check-api/src/test/java/org/sonar/check/FakeCheck.java b/sonar-check-api/src/test/java/org/sonar/check/FakeCheck.java deleted file mode 100644 index 051922c6dac..00000000000 --- a/sonar-check-api/src/test/java/org/sonar/check/FakeCheck.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * 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.check; - -@Check(title ="Detailed Check", description = "Detailed description", isoCategory = IsoCategory.Reliability) -public class FakeCheck { - - @CheckProperty(description = "Maximum value") - private String max; - - @CheckProperty(description ="Minimum value") - protected String min; - - private int nonConfigurableProperty; - - public String getMax() { - return max; - } - - public void setMax(String max) { - this.max = max; - } -} 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 dae81a92702..b5d407ea3a8 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 @@ -27,8 +27,6 @@ import org.sonar.api.rules.ActiveRuleParam; import org.sonar.api.utils.AnnotationUtils; import org.sonar.api.utils.FieldUtils2; import org.sonar.api.utils.SonarException; -import org.sonar.check.Check; -import org.sonar.check.CheckProperty; import org.sonar.check.Rule; import org.sonar.check.RuleProperty; @@ -156,13 +154,6 @@ public final class AnnotationCheckFactory extends CheckFactory { if (StringUtils.equals(key, field.getName()) || StringUtils.equals(key, propertyAnnotation.key())) { return field; } - } else { - CheckProperty checkAnnotation = field.getAnnotation(CheckProperty.class); - if (checkAnnotation != null) { - if (StringUtils.equals(key, field.getName()) || StringUtils.equals(key, checkAnnotation.key())) { - return field; - } - } } } return null; @@ -173,12 +164,6 @@ public final class AnnotationCheckFactory extends CheckFactory { Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClassOrObject, Rule.class); if (ruleAnnotation != null) { key = ruleAnnotation.key(); - } else { - Check checkAnnotation = AnnotationUtils.getAnnotation(annotatedClassOrObject, Check.class); - if (checkAnnotation != null) { - key = checkAnnotation.key(); - - } } Class clazz = annotatedClassOrObject.getClass(); if (annotatedClassOrObject instanceof Class) { 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 index ce3bdfacae0..ce4bdbc814e 100644 --- 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 @@ -29,7 +29,6 @@ import org.sonar.api.ServerComponent; import org.sonar.api.utils.AnnotationUtils; import org.sonar.api.utils.FieldUtils2; import org.sonar.api.utils.SonarException; -import org.sonar.check.Check; import java.lang.reflect.Field; import java.util.Collection; @@ -55,10 +54,6 @@ public final class AnnotationRuleParser implements ServerComponent { if (ruleAnnotation != null) { return toRule(repositoryKey, annotatedClass, ruleAnnotation); } - Check checkAnnotation = AnnotationUtils.getAnnotation(annotatedClass, Check.class); - if (checkAnnotation != null) { - return toRule(repositoryKey, annotatedClass, checkAnnotation); - } LOG.warn("The class " + annotatedClass.getCanonicalName() + " should be annotated with " + Rule.class); return null; } @@ -79,20 +74,6 @@ public final class AnnotationRuleParser implements ServerComponent { return rule; } - private Rule toRule(String repositoryKey, Class clazz, Check checkAnnotation) { - String ruleKey = StringUtils.defaultIfEmpty(checkAnnotation.key(), clazz.getCanonicalName()); - String ruleName = StringUtils.defaultIfEmpty(checkAnnotation.title(), ruleKey); - Rule rule = Rule.create(repositoryKey, ruleKey, ruleName); - rule.setDescription(checkAnnotation.description()); - rule.setSeverity(RulePriority.fromCheckPriority(checkAnnotation.priority())); - - List fields = FieldUtils2.getFields(clazz, true); - for (Field field : fields) { - addCheckProperty(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) { @@ -112,15 +93,6 @@ public final class AnnotationRuleParser implements ServerComponent { } } - private void addCheckProperty(Rule rule, Field field) { - org.sonar.check.CheckProperty propertyAnnotation = field.getAnnotation(org.sonar.check.CheckProperty.class); - if (propertyAnnotation != null) { - String fieldKey = StringUtils.defaultIfEmpty(propertyAnnotation.key(), field.getName()); - RuleParam param = rule.createParameter(fieldKey); - param.setDescription(propertyAnnotation.description()); - } - } - @VisibleForTesting static PropertyType guessType(Class type) { if ((type == Integer.class) || (type == int.class)) { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleAnnotationUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleAnnotationUtils.java index 517eaf44877..34168cd2b04 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleAnnotationUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/RuleAnnotationUtils.java @@ -21,7 +21,6 @@ package org.sonar.api.rules; import org.apache.commons.lang.StringUtils; import org.sonar.api.utils.AnnotationUtils; -import org.sonar.check.Check; /** * @since 2.3 @@ -37,11 +36,6 @@ public final class RuleAnnotationUtils { org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClass, org.sonar.check.Rule.class); if (ruleAnnotation != null) { key = ruleAnnotation.key(); - } else { - Check checkAnnotation = AnnotationUtils.getAnnotation(annotatedClass, Check.class); - if (checkAnnotation != null) { - key = checkAnnotation.key(); - } } return StringUtils.defaultIfEmpty(key, annotatedClass.getCanonicalName()); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java index 74877514357..8fe75c018ee 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/AnnotationRuleParserTest.java @@ -23,7 +23,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.PropertyType; import org.sonar.api.utils.SonarException; -import org.sonar.check.IsoCategory; import org.sonar.check.Priority; import java.util.Collections; @@ -126,17 +125,6 @@ public class AnnotationRuleParserTest { assertThat(rule.getParams()).hasSize(2); } - @Test - public void supportDeprecatedAnnotations() { - List rules = parseAnnotatedClass(Check.class); - assertThat(rules).hasSize(1); - Rule rule = rules.get(0); - assertThat(rule.getKey()).isEqualTo(Check.class.getCanonicalName()); - assertThat(rule.getName()).isEqualTo(Check.class.getCanonicalName()); - assertThat(rule.getDescription()).isEqualTo("Deprecated check"); - assertThat(rule.getSeverity()).isEqualTo(RulePriority.BLOCKER); - } - private List parseAnnotatedClass(Class annotatedClass) { return new AnnotationRuleParser().parse("repo", Collections.singleton(annotatedClass)); } @@ -178,8 +166,4 @@ public class AnnotationRuleParserTest { @org.sonar.check.RuleProperty(description = "text", defaultValue = "Long text", type = "INVALID") public String property; } - - @org.sonar.check.Check(description = "Deprecated check", priority = Priority.BLOCKER, isoCategory = IsoCategory.Maintainability) - static class Check { - } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/DeprecatedAnnotatedCheck.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/DeprecatedAnnotatedCheck.java deleted file mode 100644 index 17fd2b7a707..00000000000 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/DeprecatedAnnotatedCheck.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * 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.rules; - -import org.sonar.check.Check; -import org.sonar.check.IsoCategory; - -@Check(title ="Annotated Check", description = "Description", isoCategory = IsoCategory.Reliability) -public class DeprecatedAnnotatedCheck { -} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleAnnotationUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleAnnotationUtilsTest.java index e20de021e7f..aa07c80f242 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleAnnotationUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/RuleAnnotationUtilsTest.java @@ -32,12 +32,6 @@ public class RuleAnnotationUtilsTest { assertThat(key, is(AnnotatedCheck.class.getName())); } - @Test - public void shouldGetKeyFromDeprecatedCheckAnnotation() { - String key = RuleAnnotationUtils.getRuleKey(DeprecatedAnnotatedCheck.class); - assertThat(key, is(DeprecatedAnnotatedCheck.class.getName())); - } - @Test public void shouldGetKey() { String key = RuleAnnotationUtils.getRuleKey(AnnotatedCheckWithParameters.class);