diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-08-14 14:44:04 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-08-18 09:36:10 +0200 |
commit | 7411d5f884904c10bde62ea913d91ce6d27cdfde (patch) | |
tree | 50f7adb63e4835e77acd6eadf680df510ceb19af /plugins | |
parent | 19c15d18bfa00d03c28919fb254e59061a87f5c1 (diff) | |
download | sonarqube-7411d5f884904c10bde62ea913d91ce6d27cdfde.tar.gz sonarqube-7411d5f884904c10bde62ea913d91ce6d27cdfde.zip |
Add xoo2 language with 2 rules
Diffstat (limited to 'plugins')
7 files changed, 149 insertions, 13 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/Xoo2.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/Xoo2.java new file mode 100644 index 00000000000..788bd09d3a5 --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/Xoo2.java @@ -0,0 +1,48 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.xoo; + +import org.sonar.api.resources.Language; + +public class Xoo2 implements Language { + + public static final String KEY = "xoo2"; + public static final String NAME = "Xoo2"; + public static final String FILE_SUFFIX = ".xoo2"; + + private static final String[] XOO_SUFFIXES = { + FILE_SUFFIX + }; + + @Override + public String getKey() { + return KEY; + } + + @Override + public String getName() { + return NAME; + } + + @Override + public String[] getFileSuffixes() { + return XOO_SUFFIXES; + } +} diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java index fdd9505fac0..cffaa39b8af 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java @@ -19,6 +19,8 @@ */ package org.sonar.xoo; +import org.sonar.xoo.rule.Xoo2BasicProfile; + import org.sonar.api.SonarPlugin; import org.sonar.xoo.coverage.ItCoverageSensor; import org.sonar.xoo.coverage.OverallCoverageSensor; @@ -63,8 +65,10 @@ public class XooPlugin extends SonarPlugin { public List getExtensions() { return Arrays.asList( Xoo.class, + Xoo2.class, XooRulesDefinition.class, XooBasicProfile.class, + Xoo2BasicProfile.class, XooEmptyProfile.class, XooFakeExporter.class, diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java index 8ef94f3d99f..f8d2a524708 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/OneIssuePerLineSensor.java @@ -19,6 +19,8 @@ */ package org.sonar.xoo.rule; +import org.sonar.xoo.Xoo2; + import org.sonar.api.batch.fs.FilePredicates; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; @@ -41,21 +43,26 @@ public class OneIssuePerLineSensor implements Sensor { public void describe(SensorDescriptor descriptor) { descriptor .name("One Issue Per Line") - .onlyOnLanguages(Xoo.KEY) - .createIssuesForRuleRepositories(XooRulesDefinition.XOO_REPOSITORY); + .onlyOnLanguages(Xoo.KEY, Xoo2.KEY) + .createIssuesForRuleRepositories(XooRulesDefinition.XOO_REPOSITORY, XooRulesDefinition.XOO2_REPOSITORY); } @Override public void execute(SensorContext context) { + analyse(context, Xoo.KEY, XooRulesDefinition.XOO_REPOSITORY); + analyse(context, Xoo2.KEY, XooRulesDefinition.XOO2_REPOSITORY); + } + + private void analyse(SensorContext context, String language, String repo) { FileSystem fs = context.fileSystem(); FilePredicates p = fs.predicates(); - for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(Xoo.KEY), p.hasType(Type.MAIN)))) { - createIssues(file, context); + for (InputFile file : fs.inputFiles(p.and(p.hasLanguages(language), p.hasType(Type.MAIN)))) { + createIssues(file, context, repo); } } - private void createIssues(InputFile file, SensorContext context) { - RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY); + private void createIssues(InputFile file, SensorContext context, String repo) { + RuleKey ruleKey = RuleKey.of(repo, RULE_KEY); String severity = context.settings().getString(FORCE_SEVERITY_PROPERTY); for (int line = 1; line <= file.lines(); line++) { NewIssue newIssue = context.newIssue(); diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2BasicProfile.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2BasicProfile.java new file mode 100644 index 00000000000..a735d0840c0 --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/Xoo2BasicProfile.java @@ -0,0 +1,40 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 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.xoo.rule; + +import org.sonar.xoo.Xoo2; + +import org.sonar.api.profiles.ProfileDefinition; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.rules.Rule; +import org.sonar.api.rules.RulePriority; +import org.sonar.api.utils.ValidationMessages; + +public class Xoo2BasicProfile extends ProfileDefinition { + + public RulesProfile createProfile(ValidationMessages messages) { + RulesProfile profile = RulesProfile.create("Basic", Xoo2.KEY); + + // so UGLY + profile.activateRule(Rule.create(XooRulesDefinition.XOO2_REPOSITORY, HasTagSensor.RULE_KEY), RulePriority.MAJOR); + + return profile; + } +} diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java index 3666ac23d4c..ef8d3df6af6 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java @@ -19,21 +19,44 @@ */ package org.sonar.xoo.rule; +import org.sonar.xoo.Xoo2; + import org.sonar.api.server.rule.RuleParamType; import org.sonar.api.server.rule.RulesDefinition; import org.sonar.xoo.Xoo; /** - * Define all the coding rules that are supported on the repository named "xoo". + * Define all the coding rules that are supported on the repositories named "xoo" and "xoo2" */ public class XooRulesDefinition implements RulesDefinition { public static final String XOO_REPOSITORY = "xoo"; + public static final String XOO2_REPOSITORY = "xoo2"; @Override public void define(Context context) { - NewRepository repo = context.createRepository(XOO_REPOSITORY, Xoo.KEY).setName("Xoo"); + defineRulesXoo(context); + defineRulesXoo2(context); + } + + private static void defineRulesXoo2(Context context) { + NewRepository repo = context.createRepository(XOO2_REPOSITORY, Xoo2.KEY).setName("Xoo2"); + + NewRule hasTag = repo.createRule(HasTagSensor.RULE_KEY).setName("Has Tag") + .setHtmlDescription("Search for a given tag in Xoo files"); + + NewRule oneIssuePerLine = repo.createRule(OneIssuePerLineSensor.RULE_KEY).setName("One Issue Per Line") + .setHtmlDescription("Generate an issue on each line of a file. It requires the metric \"lines\"."); + oneIssuePerLine.setDebtSubCharacteristic(RulesDefinition.SubCharacteristics.MEMORY_EFFICIENCY) + .setDebtRemediationFunction(hasTag.debtRemediationFunctions().linear("1min")) + .setEffortToFixDescription("It takes about 1 minute to an experienced software craftsman to remove a line of code"); + + repo.done(); + } + private static void defineRulesXoo(Context context) { + NewRepository repo = context.createRepository(XOO_REPOSITORY, Xoo.KEY).setName("Xoo"); + NewRule hasTag = repo.createRule(HasTagSensor.RULE_KEY).setName("Has Tag") .setHtmlDescription("Search for a given tag in Xoo files"); hasTag.setDebtSubCharacteristic(RulesDefinition.SubCharacteristics.READABILITY) diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java index 2b422ba50ee..8614c0992a4 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/OneIssuePerLineSensorTest.java @@ -56,7 +56,7 @@ public class OneIssuePerLineSensorTest { public void testDescriptor() { DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor(); sensor.describe(descriptor); - assertThat(descriptor.ruleRepositories()).containsOnly(XooRulesDefinition.XOO_REPOSITORY); + assertThat(descriptor.ruleRepositories()).containsOnly(XooRulesDefinition.XOO_REPOSITORY, XooRulesDefinition.XOO2_REPOSITORY); } @Test diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java index b9ae69bb0dd..923f4d94f5f 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java @@ -19,20 +19,25 @@ */ package org.sonar.xoo.rule; +import org.junit.Before; + import org.junit.Test; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.server.rule.RulesDefinition; - import static org.assertj.core.api.Assertions.assertThat; public class XooRulesDefinitionTest { + RulesDefinition.Context context; - @Test - public void define_xoo_rules() { + @Before + public void setUp() { XooRulesDefinition def = new XooRulesDefinition(); - RulesDefinition.Context context = new RulesDefinition.Context(); + context = new RulesDefinition.Context(); def.define(context); + } + @Test + public void define_xoo_rules() { RulesDefinition.Repository repo = context.repository("xoo"); assertThat(repo).isNotNull(); assertThat(repo.name()).isEqualTo("Xoo"); @@ -47,4 +52,13 @@ public class XooRulesDefinitionTest { assertThat(rule.debtRemediationFunction().offset()).isNull(); assertThat(rule.effortToFixDescription()).isNotEmpty(); } + + @Test + public void define_xoo2_rules() { + RulesDefinition.Repository repo = context.repository("xoo2"); + assertThat(repo).isNotNull(); + assertThat(repo.name()).isEqualTo("Xoo2"); + assertThat(repo.language()).isEqualTo("xoo2"); + assertThat(repo.rules()).hasSize(2); + } } |