]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3496, SONAR-3497 & SONAR-3498 Add new rules for Java
authorFabrice Bellingard <bellingard@gmail.com>
Wed, 20 Jun 2012 10:24:27 +0000 (12:24 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 25 Jun 2012 12:28:24 +0000 (14:28 +0200)
=> 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
plugins/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaCommonRulesEngineProvider.java [new file with mode: 0644]
plugins/sonar-java-plugin/src/main/java/org/sonar/plugins/java/JavaPlugin.java
plugins/sonar-java-plugin/src/test/java/org/sonar/plugins/java/JavaPluginTest.java
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java.properties [new file with mode: 0644]
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/DuplicatedBlocks.html [new file with mode: 0644]
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientBranchCoverage.html [new file with mode: 0644]
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientCommentDensity.html [new file with mode: 0644]
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/java/rules/common-java/InsufficientLineCoverage.html [new file with mode: 0644]
sonar-application/pom.xml

index 73d45773ed0d42a60ebff79d13380636d17a6750..d3fb017c0871e43440afe80807f1d7ec485ebb9d 100644 (file)
       <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>
           <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 (file)
index 0000000..021510d
--- /dev/null
@@ -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();
+  }
+
+}
index 137b4c470f8a4fae40651fe265e659dab96c1be7..aa137879589a1fb6f754d3591a02e291e40e1da2 100644 (file)
 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);
   }
 
 }
index 7e7a0fbeb7efbd7e35a9db039ad738e66e79ebd0..1a5097d59afed1d731c1f9634e0837e9a745fa27 100644 (file)
@@ -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 (file)
index 0000000..f896099
--- /dev/null
@@ -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 (file)
index 0000000..5dc95b8
--- /dev/null
@@ -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 (file)
index 0000000..d1918ce
--- /dev/null
@@ -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 (file)
index 0000000..88ec282
--- /dev/null
@@ -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 (file)
index 0000000..2848285
--- /dev/null
@@ -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
index f04fba951f37d379d7c6bb49074da7da95a6fec4..1fba0b0bfd6de5eade9568370b2c85c74b0650a2 100644 (file)
       <version>${project.version}</version>
       <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>