diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2014-01-27 23:27:26 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2014-01-27 23:28:03 +0100 |
commit | 36805421f21c3dbc2b0638d27ff9ece3d2cf3156 (patch) | |
tree | 82384bad6eae5720287bc8c79093455d8d624a37 /sonar-deprecated/src | |
parent | 08977044fa003bd252310c62287642630ba02d09 (diff) | |
download | sonarqube-36805421f21c3dbc2b0638d27ff9ece3d2cf3156.tar.gz sonarqube-36805421f21c3dbc2b0638d27ff9ece3d2cf3156.zip |
Move AnnotationCheckFactory to sonar-deprecated
Diffstat (limited to 'sonar-deprecated/src')
12 files changed, 741 insertions, 0 deletions
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java new file mode 100644 index 00000000000..e706da53015 --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/checks/AnnotationCheckFactory.java @@ -0,0 +1,173 @@ +/* + * 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.checks; + +import com.google.common.collect.Maps; +import org.apache.commons.lang.StringUtils; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.rules.ActiveRule; +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.Rule; +import org.sonar.check.RuleProperty; + +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * @since 2.3 + */ +public final class AnnotationCheckFactory extends CheckFactory { + + private static final String CAN_NOT_INSTANTIATE_THE_CHECK_RELATED_TO_THE_RULE = "Can not instantiate the check related to the rule "; + private Map<String, Object> checksByKey = Maps.newHashMap(); + + private AnnotationCheckFactory(RulesProfile profile, String repositoryKey, Collection checks) { + super(profile, repositoryKey); + groupByKey(checks); + } + + public static AnnotationCheckFactory create(RulesProfile profile, String repositoryKey, Collection checkClasses) { + AnnotationCheckFactory factory = new AnnotationCheckFactory(profile, repositoryKey, checkClasses); + factory.init(); + return factory; + } + + private void groupByKey(Collection checks) { + for (Object check : checks) { + String key = getRuleKey(check); + if (key != null) { + checksByKey.put(key, check); + } + } + } + + @Override + protected Object createCheck(ActiveRule activeRule) { + Object object = checksByKey.get(activeRule.getConfigKey()); + if (object != null) { + return instantiate(activeRule, object); + } + return null; + } + + private Object instantiate(ActiveRule activeRule, Object checkClassOrInstance) { + try { + Object check = checkClassOrInstance; + if (check instanceof Class) { + check = ((Class) checkClassOrInstance).newInstance(); + } + configureFields(activeRule, check); + return check; + + } catch (InstantiationException e) { + throw new SonarException(CAN_NOT_INSTANTIATE_THE_CHECK_RELATED_TO_THE_RULE + activeRule, e); + + } catch (IllegalAccessException e) { + throw new SonarException(CAN_NOT_INSTANTIATE_THE_CHECK_RELATED_TO_THE_RULE + activeRule, e); + } + } + + private void configureFields(ActiveRule activeRule, Object check) { + for (ActiveRuleParam param : activeRule.getActiveRuleParams()) { + Field field = getField(check, param.getKey()); + if (field == null) { + throw new SonarException("The field " + param.getKey() + " does not exist or is not annotated with @RuleProperty in the class " + check.getClass().getName()); + } + if (StringUtils.isNotBlank(param.getValue())) { + configureField(check, field, param.getValue()); + } + } + + } + + private void configureField(Object check, Field field, String value) { + try { + field.setAccessible(true); + + if (field.getType().equals(String.class)) { + field.set(check, value); + + } else if ("int".equals(field.getType().getSimpleName())) { + field.setInt(check, Integer.parseInt(value)); + + } else if ("short".equals(field.getType().getSimpleName())) { + field.setShort(check, Short.parseShort(value)); + + } else if ("long".equals(field.getType().getSimpleName())) { + field.setLong(check, Long.parseLong(value)); + + } else if ("double".equals(field.getType().getSimpleName())) { + field.setDouble(check, Double.parseDouble(value)); + + } else if ("boolean".equals(field.getType().getSimpleName())) { + field.setBoolean(check, Boolean.parseBoolean(value)); + + } else if ("byte".equals(field.getType().getSimpleName())) { + field.setByte(check, Byte.parseByte(value)); + + } else if (field.getType().equals(Integer.class)) { + field.set(check, Integer.parseInt(value)); + + } else if (field.getType().equals(Long.class)) { + field.set(check, Long.parseLong(value)); + + } else if (field.getType().equals(Double.class)) { + field.set(check, Double.parseDouble(value)); + + } else if (field.getType().equals(Boolean.class)) { + field.set(check, Boolean.parseBoolean(value)); + + } else { + throw new SonarException("The type of the field " + field + " is not supported: " + field.getType()); + } + } catch (IllegalAccessException e) { + throw new SonarException("Can not set the value of the field " + field + " in the class: " + check.getClass().getName(), e); + } + } + + private Field getField(Object check, String key) { + List<Field> fields = FieldUtils2.getFields(check.getClass(), true); + for (Field field : fields) { + RuleProperty propertyAnnotation = field.getAnnotation(RuleProperty.class); + if (propertyAnnotation != null && (StringUtils.equals(key, field.getName()) || StringUtils.equals(key, propertyAnnotation.key()))) { + return field; + } + } + return null; + } + + private String getRuleKey(Object annotatedClassOrObject) { + String key = null; + Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClassOrObject, Rule.class); + if (ruleAnnotation != null) { + key = ruleAnnotation.key(); + } + Class clazz = annotatedClassOrObject.getClass(); + if (annotatedClassOrObject instanceof Class) { + clazz = (Class) annotatedClassOrObject; + } + return StringUtils.defaultIfEmpty(key, clazz.getCanonicalName()); + } +} diff --git a/sonar-deprecated/src/main/java/org/sonar/api/checks/CheckFactory.java b/sonar-deprecated/src/main/java/org/sonar/api/checks/CheckFactory.java new file mode 100644 index 00000000000..a819b3c4918 --- /dev/null +++ b/sonar-deprecated/src/main/java/org/sonar/api/checks/CheckFactory.java @@ -0,0 +1,71 @@ +/* + * 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.checks; + +import com.google.common.collect.Maps; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.rules.ActiveRule; + +import java.util.Collection; +import java.util.Map; + +/** + * @since 2.3 + */ +public abstract class CheckFactory<C> { + + private Map<ActiveRule, C> checkByActiveRule = Maps.newIdentityHashMap(); + private Map<C, ActiveRule> activeRuleByCheck = Maps.newIdentityHashMap(); + private RulesProfile profile; + private String repositoryKey; + + protected CheckFactory(RulesProfile profile, String repositoryKey) { + this.repositoryKey = repositoryKey; + this.profile = profile; + } + + protected void init() { + checkByActiveRule.clear(); + activeRuleByCheck.clear(); + for (ActiveRule activeRule : profile.getActiveRulesByRepository(repositoryKey)) { + C check = createCheck(activeRule); + checkByActiveRule.put(activeRule, check); + activeRuleByCheck.put(check, activeRule); + } + } + + abstract C createCheck(ActiveRule activeRule); + + public final String getRepositoryKey() { + return repositoryKey; + } + + public final Collection<C> getChecks() { + return checkByActiveRule.values(); + } + + public final C getCheck(ActiveRule activeRule) { + return checkByActiveRule.get(activeRule); + } + + public final ActiveRule getActiveRule(C check) { + return activeRuleByCheck.get(check); + } +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/AbstractCheck.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/AbstractCheck.java new file mode 100644 index 00000000000..abf1347d55f --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/AbstractCheck.java @@ -0,0 +1,32 @@ +/* + * 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.checks; + +import org.sonar.check.RuleProperty; + +abstract class AbstractCheck { + + @RuleProperty + private Integer max; + + public Integer getMax() { + return max; + } +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java new file mode 100644 index 00000000000..a58cb83c499 --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java @@ -0,0 +1,201 @@ +/* + * 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.checks; + +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.rules.ActiveRule; +import org.sonar.api.rules.Rule; +import org.sonar.api.utils.SonarException; + +import java.util.Arrays; + +import static org.fest.assertions.Assertions.assertThat; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; + +public class AnnotationCheckFactoryTest { + + @org.junit.Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void createCheckWithoutProperties() { + RulesProfile profile = RulesProfile.create("repo", "java"); + ActiveRule activeRule = profile.activateRule(Rule.create("repo", "org.sonar.api.checks.CheckWithoutProperties", ""), null); + AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithoutProperties.class)); + + Object check = factory.getCheck(activeRule); + assertNotNull(check); + assertThat(check, is(CheckWithoutProperties.class)); + } + + @Test + public void createCheckWithStringProperty() { + RulesProfile profile = RulesProfile.create("repo", "java"); + Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithStringProperty", ""); + rule.createParameter("pattern"); + + ActiveRule activeRule = profile.activateRule(rule, null); + activeRule.setParameter("pattern", "foo"); + AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithStringProperty.class)); + + Object check = factory.getCheck(activeRule); + assertNotNull(check); + assertThat(check, is(CheckWithStringProperty.class)); + assertThat(((CheckWithStringProperty) check).getPattern(), is("foo")); + } + + @Test + public void failIfMissingProperty() { + thrown.expect(SonarException.class); + + RulesProfile profile = RulesProfile.create("repo", "java"); + Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithStringProperty", ""); + rule.createParameter("unknown"); + + ActiveRule activeRule = profile.activateRule(rule, null); + activeRule.setParameter("unknown", "bar"); + AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithStringProperty.class)); + } + + @Test + public void createCheckWithPrimitiveProperties() { + RulesProfile profile = RulesProfile.create("repo", "java"); + Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithPrimitiveProperties", ""); + rule.createParameter("max"); + rule.createParameter("ignore"); + + ActiveRule activeRule = profile.activateRule(rule, null); + activeRule.setParameter("max", "300"); + activeRule.setParameter("ignore", "true"); + AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithPrimitiveProperties.class)); + + Object check = factory.getCheck(activeRule); + assertThat(((CheckWithPrimitiveProperties) check).getMax(), is(300)); + assertThat(((CheckWithPrimitiveProperties) check).isIgnore(), is(true)); + } + + @Test + public void createCheckWithIntegerProperty() { + RulesProfile profile = RulesProfile.create("repo", "java"); + Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithIntegerProperty", ""); + rule.createParameter("max"); + + ActiveRule activeRule = profile.activateRule(rule, null); + activeRule.setParameter("max", "300"); + AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithIntegerProperty.class)); + + Object check = factory.getCheck(activeRule); + assertThat(((CheckWithIntegerProperty) check).getMax(), is(300)); + } + + /** + * SONAR-3164 + */ + @Test + public void setValueOfInheritedField() { + RulesProfile profile = RulesProfile.create("repo", "java"); + Rule rule = Rule.create("repo", "org.sonar.api.checks.ImplementedCheck", ""); + rule.createParameter("max"); + + ActiveRule activeRule = profile.activateRule(rule, null); + activeRule.setParameter("max", "300"); + AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(ImplementedCheck.class)); + + Object check = factory.getCheck(activeRule); + assertThat(((ImplementedCheck) check).getMax(), is(300)); + } + + @Test + public void failIfPropertyTypeIsNotSupported() { + thrown.expect(SonarException.class); + + RulesProfile profile = RulesProfile.create("repo", "java"); + Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithUnsupportedPropertyType", ""); + rule.createParameter("max"); + + ActiveRule activeRule = profile.activateRule(rule, null); + activeRule.setParameter("max", "300"); + AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithUnsupportedPropertyType.class)); + } + + @Test + public void shouldOverridePropertyKey() { + RulesProfile profile = RulesProfile.create("repo", "java"); + Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithOverriddenPropertyKey", ""); + rule.createParameter("maximum"); + + ActiveRule activeRule = profile.activateRule(rule, null); + activeRule.setParameter("maximum", "300"); + AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithOverriddenPropertyKey.class)); + + Object check = factory.getCheck(activeRule); + assertThat(((CheckWithOverriddenPropertyKey) check).getMax(), is(300)); + } + + @Test + public void shouldWorkWithClonedRules() { + RulesProfile profile = RulesProfile.create("repo", "java"); + Rule rule = Rule.create("repo", "CheckWithKey", ""); + Rule clonedRule = Rule.create("repo", "CheckWithKey_2", "").setConfigKey("CheckWithKey").setParent(rule); + + profile.activateRule(rule, null); + profile.activateRule(clonedRule, null); + AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithKey.class)); + + assertThat(factory.getChecks()).excludes(new Object[] {null}); + } + + /** + * SONAR-2900 + */ + @Test + public void create_accept_objects() { + RulesProfile profile = RulesProfile.create("repo", "java"); + ActiveRule activeRule = profile.activateRule(Rule.create("repo", "org.sonar.api.checks.CheckWithoutProperties", ""), null); + CheckWithoutProperties checkInstance = new CheckWithoutProperties(); + AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.asList(checkInstance)); + + Object check = factory.getCheck(activeRule); + assertNotNull(check); + assertSame(check, checkInstance); + } + + @Test + public void create_instance_with_string_property() { + RulesProfile profile = RulesProfile.create("repo", "java"); + Rule rule = Rule.create("repo", "org.sonar.api.checks.CheckWithStringProperty", ""); + rule.createParameter("pattern"); + + ActiveRule activeRule = profile.activateRule(rule, null); + activeRule.setParameter("pattern", "foo"); + CheckWithStringProperty checkInstance = new CheckWithStringProperty(); + AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.asList(checkInstance)); + + Object check = factory.getCheck(activeRule); + assertNotNull(check); + assertSame(check, checkInstance); + assertThat(checkInstance.getPattern(), is("foo")); + } +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithIntegerProperty.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithIntegerProperty.java new file mode 100644 index 00000000000..60a4096940c --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithIntegerProperty.java @@ -0,0 +1,33 @@ +/* + * 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.checks; + +import org.sonar.check.*; + +@Rule(priority = Priority.CRITICAL) +class CheckWithIntegerProperty { + + @RuleProperty + private Integer max; + + public Integer getMax() { + return max; + } +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithKey.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithKey.java new file mode 100644 index 00000000000..3b048a6b651 --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithKey.java @@ -0,0 +1,28 @@ +/* + * 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.checks; + +import org.sonar.check.Priority; +import org.sonar.check.Rule; + +@Rule(key = "CheckWithKey", priority = Priority.CRITICAL) +public class CheckWithKey { + +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithOverriddenPropertyKey.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithOverriddenPropertyKey.java new file mode 100644 index 00000000000..868027f7a46 --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithOverriddenPropertyKey.java @@ -0,0 +1,35 @@ +/* + * 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.checks; + +import org.sonar.check.Priority; +import org.sonar.check.Rule; +import org.sonar.check.RuleProperty; + +@Rule(priority = Priority.CRITICAL) +class CheckWithOverriddenPropertyKey{ + + @RuleProperty(key = "maximum") + private int max = 50; + + public int getMax() { + return max; + } +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithPrimitiveProperties.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithPrimitiveProperties.java new file mode 100644 index 00000000000..0d6a1d41c85 --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithPrimitiveProperties.java @@ -0,0 +1,43 @@ +/* + * 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.checks; + +import org.sonar.check.Priority; +import org.sonar.check.Rule; +import org.sonar.check.RuleProperty; + +@Rule(priority = Priority.CRITICAL) +class CheckWithPrimitiveProperties { + + @RuleProperty(description = "Maximum threshold") + private int max = 50; + + @RuleProperty + private boolean ignore; + + public int getMax() { + return max; + } + + public boolean isIgnore() { + return ignore; + } +} + diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithStringProperty.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithStringProperty.java new file mode 100644 index 00000000000..6f10f76dec2 --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithStringProperty.java @@ -0,0 +1,36 @@ +/* + * 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.checks; + +import org.sonar.check.Priority; +import org.sonar.check.Rule; +import org.sonar.check.RuleProperty; + +@Rule(priority = Priority.CRITICAL) +class CheckWithStringProperty { + + @RuleProperty + private String pattern; + + public String getPattern() { + return pattern; + } +} + diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithUnsupportedPropertyType.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithUnsupportedPropertyType.java new file mode 100644 index 00000000000..3401884e63d --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithUnsupportedPropertyType.java @@ -0,0 +1,32 @@ +/* + * 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.checks; + +import org.sonar.check.Priority; +import org.sonar.check.Rule; +import org.sonar.check.RuleProperty; + +@Rule(priority = Priority.CRITICAL) +class CheckWithUnsupportedPropertyType { + + @RuleProperty + private StringBuilder max = null; + +} diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithoutProperties.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithoutProperties.java new file mode 100644 index 00000000000..aaa8f0b299d --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/CheckWithoutProperties.java @@ -0,0 +1,29 @@ +/* + * 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.checks; + +import org.sonar.check.Priority; +import org.sonar.check.Rule; + +@Rule(priority = Priority.CRITICAL) +class CheckWithoutProperties { + +} + diff --git a/sonar-deprecated/src/test/java/org/sonar/api/checks/ImplementedCheck.java b/sonar-deprecated/src/test/java/org/sonar/api/checks/ImplementedCheck.java new file mode 100644 index 00000000000..09c673570a2 --- /dev/null +++ b/sonar-deprecated/src/test/java/org/sonar/api/checks/ImplementedCheck.java @@ -0,0 +1,28 @@ +/* + * 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.checks; + +import org.sonar.check.Priority; +import org.sonar.check.Rule; + +@Rule(priority = Priority.CRITICAL) +class ImplementedCheck extends AbstractCheck { + +} |