diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-06 14:08:06 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-06 14:08:06 +0000 |
commit | aeadc1f9129274949daaa57738c7c4550bdfbc7b (patch) | |
tree | 08dadf5ef7474fc41d1d48f74648f1ba8b55f34d /sonar-check-api/src/main | |
download | sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.tar.gz sonarqube-aeadc1f9129274949daaa57738c7c4550bdfbc7b.zip |
SONAR-236 remove deprecated code from checkstyle plugin + display default value of rule parameters in Q profile console
Diffstat (limited to 'sonar-check-api/src/main')
8 files changed, 343 insertions, 0 deletions
diff --git a/sonar-check-api/src/main/java/org/sonar/check/AnnotationIntrospector.java b/sonar-check-api/src/main/java/org/sonar/check/AnnotationIntrospector.java new file mode 100644 index 00000000000..15def7431c3 --- /dev/null +++ b/sonar-check-api/src/main/java/org/sonar/check/AnnotationIntrospector.java @@ -0,0 +1,71 @@ +/* + * 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.check; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +public final class AnnotationIntrospector { + + private AnnotationIntrospector() { + // only static methods + } + + public static String getCheckKey(Class annotatedClass) { + Check checkAnnotation = getCheckAnnotation(annotatedClass); + if (checkAnnotation == null) { + return null; + } + + String key = checkAnnotation.key(); + if (key == null || "".equals(key.trim())) { + key = annotatedClass.getCanonicalName(); + } + return key; + } + + public static Check getCheckAnnotation(Class annotatedClass) { + return (Check) annotatedClass.getAnnotation(Check.class); + } + + public static List<Field> getPropertyFields(Class annotatedClass) { + List<Field> fields = new ArrayList<Field>(); + for (Field field : annotatedClass.getDeclaredFields()) { + org.sonar.check.CheckProperty propertyAnnotation = field.getAnnotation(org.sonar.check.CheckProperty.class); + if (propertyAnnotation != null) { + fields.add(field); + } + } + return fields; + } + + public static String getPropertyFieldKey(Field field) { + String key = null; + org.sonar.check.CheckProperty propertyAnnotation = field.getAnnotation(org.sonar.check.CheckProperty.class); + if (propertyAnnotation != null) { + key = propertyAnnotation.key(); + if (key == null || "".equals(key)) { + key = field.getName(); + } + } + return key; + } +} diff --git a/sonar-check-api/src/main/java/org/sonar/check/BelongsToProfile.java b/sonar-check-api/src/main/java/org/sonar/check/BelongsToProfile.java new file mode 100644 index 00000000000..a79a64817f8 --- /dev/null +++ b/sonar-check-api/src/main/java/org/sonar/check/BelongsToProfile.java @@ -0,0 +1,38 @@ +/* + * 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.check; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @since 2.1 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface BelongsToProfile { + + String title(); + + Priority priority(); + +} diff --git a/sonar-check-api/src/main/java/org/sonar/check/BelongsToProfiles.java b/sonar-check-api/src/main/java/org/sonar/check/BelongsToProfiles.java new file mode 100644 index 00000000000..a7d15fdf891 --- /dev/null +++ b/sonar-check-api/src/main/java/org/sonar/check/BelongsToProfiles.java @@ -0,0 +1,36 @@ +/* + * 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.check; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @since 2.1 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface BelongsToProfiles { + + BelongsToProfile[] value() default {}; + +} 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 new file mode 100644 index 00000000000..8a8ae8ef1af --- /dev/null +++ b/sonar-check-api/src/main/java/org/sonar/check/Check.java @@ -0,0 +1,64 @@ +/* + * 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.check; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @since 2.1 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +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 in version 2.2 + */ + 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 new file mode 100644 index 00000000000..17ac5801e53 --- /dev/null +++ b/sonar-check-api/src/main/java/org/sonar/check/CheckProperty.java @@ -0,0 +1,46 @@ +/* + * 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.check; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @since 2.1 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +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/main/java/org/sonar/check/IsoCategory.java b/sonar-check-api/src/main/java/org/sonar/check/IsoCategory.java new file mode 100644 index 00000000000..d85967bf0a2 --- /dev/null +++ b/sonar-check-api/src/main/java/org/sonar/check/IsoCategory.java @@ -0,0 +1,26 @@ +/* + * 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.check; + +public enum IsoCategory { + + Reliability, Efficiency, Portability, Usability, Maintainability, NONE + +} diff --git a/sonar-check-api/src/main/java/org/sonar/check/Message.java b/sonar-check-api/src/main/java/org/sonar/check/Message.java new file mode 100644 index 00000000000..0eecb1437c2 --- /dev/null +++ b/sonar-check-api/src/main/java/org/sonar/check/Message.java @@ -0,0 +1,34 @@ +/* + * 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.check; + +import java.util.Locale; + +public interface Message { + + /** + * Return the checker which logged the message. The checker class must be annotated with <code>@Check</code> + */ + Object getChecker(); + + Integer getLine(); + + String getText(Locale locale); +} diff --git a/sonar-check-api/src/main/java/org/sonar/check/Priority.java b/sonar-check-api/src/main/java/org/sonar/check/Priority.java new file mode 100644 index 00000000000..bdeb121b3a5 --- /dev/null +++ b/sonar-check-api/src/main/java/org/sonar/check/Priority.java @@ -0,0 +1,28 @@ +/* + * 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.check; + +public enum Priority { + /** + * WARNING : DO NOT CHANGE THE ENUMERATION ORDER + * the enum ordinal is used for db persistence + */ + INFO, MINOR, MAJOR, CRITICAL, BLOCKER +} |