diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2012-06-20 12:24:27 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2012-06-25 14:28:24 +0200 |
commit | 3c35737da4a6c229f73cf7201412542efa180210 (patch) | |
tree | b92e2c366192d26fc9052f4a65494c1c9e80bb25 | |
parent | 3f770e492aef9eb4ce0e38d28ea13ebe712d8757 (diff) | |
download | sonarqube-3c35737da4a6c229f73cf7201412542efa180210.tar.gz sonarqube-3c35737da4a6c229f73cf7201412542efa180210.zip |
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"
10 files changed, 134 insertions, 5 deletions
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 @@ <artifactId>sonar-plugin-api</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.codehaus.sonar.common-rules</groupId> + <artifactId>sonar-common-rules</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> <!-- unit tests --> <dependency> @@ -39,6 +44,44 @@ <pluginClass>org.sonar.plugins.java.JavaPlugin</pluginClass> </configuration> </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>native2ascii-maven-plugin</artifactId> + <version>1.0-beta-1</version> + <executions> + <execution> + <goals> + <goal>native2ascii</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <executions> + <execution> + <id>enforce-plugin-size</id> + <goals> + <goal>enforce</goal> + </goals> + <phase>verify</phase> + <configuration> + <rules> + <requireFilesSize> + <!-- Do not forget to check correctness of those numbers, when obfuscation disabled --> + <maxsize>50000</maxsize> + <minsize>20000</minsize> + <files> + <file>${project.build.directory}/${project.build.finalName}.jar</file> + </files> + </requireFilesSize> + </rules> + </configuration> + </execution> + </executions> + </plugin> </plugins> - </build> + </build> + </project> 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<Class<? extends Extension>> 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 @@ +<p> + 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. +</p>
\ 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 @@ +<p> + 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. +</p>
\ 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 @@ +<p> + 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. +</p>
\ 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 @@ +<p> + 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. +</p>
\ 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 @@ -183,6 +183,12 @@ <scope>runtime</scope> </dependency> <dependency> + <groupId>org.codehaus.sonar.plugins</groupId> + <artifactId>sonar-java-plugin</artifactId> + <version>${project.version}</version> + <scope>runtime</scope> + </dependency> + <dependency> <groupId>org.sonatype.jsw-binaries</groupId> <artifactId>jsw-binaries</artifactId> <version>3.2.3.6</version> |