<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>
--- /dev/null
+/*
+ * 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();
+ }
+
+}
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);
}
}
@Test
public void testGetExtensions() {
- assertThat(new JavaPlugin().getExtensions().size()).isEqualTo(0);
+ assertThat(new JavaPlugin().getExtensions().size()).isEqualTo(1);
}
}
--- /dev/null
+#
+# 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.
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
<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>