From 3c35737da4a6c229f73cf7201412542efa180210 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Wed, 20 Jun 2012 12:24:27 +0200 Subject: [PATCH] SONAR-3496, SONAR-3497 & SONAR-3498 Add new rules for Java => Those rules are the ones pulled out from the SQALE plugin and put in an independant lib called "sonar-common-rules" --- plugins/sonar-java-plugin/pom.xml | 45 ++++++++++++++++- .../java/JavaCommonRulesEngineProvider.java | 49 +++++++++++++++++++ .../org/sonar/plugins/java/JavaPlugin.java | 5 +- .../sonar/plugins/java/JavaPluginTest.java | 2 +- .../resources/org/sonar/l10n/java.properties | 16 ++++++ .../rules/common-java/DuplicatedBlocks.html | 4 ++ .../InsufficientBranchCoverage.html | 4 ++ .../InsufficientCommentDensity.html | 4 ++ .../common-java/InsufficientLineCoverage.html | 4 ++ sonar-application/pom.xml | 6 +++ 10 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 plugins/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaCommonRulesEngineProvider.java create mode 100644 plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java.properties create mode 100644 plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/DuplicatedBlocks.html create mode 100644 plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientBranchCoverage.html create mode 100644 plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientCommentDensity.html create mode 100644 plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientLineCoverage.html diff --git a/plugins/sonar-java-plugin/pom.xml b/plugins/sonar-java-plugin/pom.xml index 73d45773ed0..d3fb017c087 100644 --- a/plugins/sonar-java-plugin/pom.xml +++ b/plugins/sonar-java-plugin/pom.xml @@ -19,6 +19,11 @@ sonar-plugin-api provided + + org.codehaus.sonar.common-rules + sonar-common-rules + 1.0-SNAPSHOT + @@ -39,6 +44,44 @@ org.sonar.plugins.java.JavaPlugin + + org.codehaus.mojo + native2ascii-maven-plugin + 1.0-beta-1 + + + + native2ascii + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-plugin-size + + enforce + + verify + + + + + 50000 + 20000 + + ${project.build.directory}/${project.build.finalName}.jar + + + + + + + - + + diff --git a/plugins/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaCommonRulesEngineProvider.java b/plugins/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaCommonRulesEngineProvider.java new file mode 100644 index 00000000000..021510d812b --- /dev/null +++ b/plugins/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaCommonRulesEngineProvider.java @@ -0,0 +1,49 @@ +/* + * 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.plugins.java; + +import org.sonar.api.BatchExtension; +import org.sonar.api.ExtensionProvider; +import org.sonar.api.ServerExtension; +import org.sonar.api.resources.Language; +import org.sonar.commonrules.api.CommonRulesEngine; + +import java.util.List; + +public class JavaCommonRulesEngineProvider extends ExtensionProvider implements ServerExtension, BatchExtension { + + private Language language; + + public JavaCommonRulesEngineProvider(Language language) { + this.language = language; + } + + @Override + public List provide() { + CommonRulesEngine engine = new CommonRulesEngine(language); + engine.activateRule("InsufficientBranchCoverage"); + engine.activateRule("InsufficientCommentDensity"); + engine.activateRule("DuplicatedBlocks"); + engine.activateRule("InsufficientLineCoverage"); + + return engine.getExtensions(); + } + +} diff --git a/plugins/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaPlugin.java b/plugins/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaPlugin.java index 137b4c470f8..aa137879589 100644 --- a/plugins/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaPlugin.java +++ b/plugins/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaPlugin.java @@ -20,15 +20,14 @@ package org.sonar.plugins.java; import com.google.common.collect.ImmutableList; -import org.sonar.api.Extension; import org.sonar.api.SonarPlugin; import java.util.List; public class JavaPlugin extends SonarPlugin { - public List> getExtensions() { - return ImmutableList.of(); + public List getExtensions() { + return ImmutableList.of(JavaCommonRulesEngineProvider.class); } } diff --git a/plugins/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaPluginTest.java b/plugins/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaPluginTest.java index 7e7a0fbeb7e..1a5097d59af 100644 --- a/plugins/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaPluginTest.java +++ b/plugins/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaPluginTest.java @@ -27,7 +27,7 @@ public class JavaPluginTest { @Test public void testGetExtensions() { - assertThat(new JavaPlugin().getExtensions().size()).isEqualTo(0); + assertThat(new JavaPlugin().getExtensions().size()).isEqualTo(1); } } diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java.properties new file mode 100644 index 00000000000..f896099bfd7 --- /dev/null +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java.properties @@ -0,0 +1,16 @@ +# +# IMPORTANT: the bundle for the Java plugin (and the corresponding rule descriptions in the "java" fodler) are currently located here +# because the sonar-java-plugin is currently a Core plugin. They should be moved out and placed inside the Java Plugin once +# (or if one day) the plugin is pulled out of the Sonar Platform to be an independant plugin (like any other language plugin). +# + +rule.common-java.InsufficientBranchCoverage.name=Insufficient branch coverage by unit tests +rule.common-java.InsufficientBranchCoverage.param.minimumBranchCoverageRatio=The minimum required branch coverage ratio. + +rule.common-java.InsufficientCommentDensity.name=Insufficient comment density +rule.common-java.InsufficientCommentDensity.param.minimumCommentDensity=The minimum required comment density. + +rule.common-java.DuplicatedBlocks.name=Duplicated blocks + +rule.common-java.InsufficientLineCoverage.name=Insufficient line coverage by unit tests +rule.common-java.InsufficientLineCoverage.param.minimumLineCoverageRatio=The minimum required line coverage ratio. diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/DuplicatedBlocks.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/DuplicatedBlocks.html new file mode 100644 index 00000000000..5dc95b807cd --- /dev/null +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/DuplicatedBlocks.html @@ -0,0 +1,4 @@ +

+ A violation is created on a file as soon as there is a block of duplicated code on this file. + It gives the number of blocks in the file. +

\ No newline at end of file diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientBranchCoverage.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientBranchCoverage.html new file mode 100644 index 00000000000..d1918ce81d3 --- /dev/null +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientBranchCoverage.html @@ -0,0 +1,4 @@ +

+ A violation is created on a file as soon as the branch coverage on this file is less than the required threshold. + It gives the number of lines to be covered in order to reach the required threshold. +

\ No newline at end of file diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientCommentDensity.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientCommentDensity.html new file mode 100644 index 00000000000..88ec282b86b --- /dev/null +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientCommentDensity.html @@ -0,0 +1,4 @@ +

+ A violation is created on a file as soon as the comment density coverage on this file is less than the required threshold. + It gives the number of comment lines to be written in order to reach the required threshold. +

\ No newline at end of file diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientLineCoverage.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientLineCoverage.html new file mode 100644 index 00000000000..28482859aa7 --- /dev/null +++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientLineCoverage.html @@ -0,0 +1,4 @@ +

+ A violation is created on a file as soon as the line coverage on this file is less than the required threshold. + It gives the number of lines to be covered in order to reach the required threshold. +

\ No newline at end of file diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml index f04fba951f3..1fba0b0bfd6 100644 --- a/sonar-application/pom.xml +++ b/sonar-application/pom.xml @@ -182,6 +182,12 @@ ${project.version} runtime
+ + org.codehaus.sonar.plugins + sonar-java-plugin + ${project.version} + runtime + org.sonatype.jsw-binaries jsw-binaries -- 2.39.5