Browse Source

SONAR-236 remove deprecated code from checkstyle plugin + display default value of rule parameters in Q profile console

tags/2.6
simonbrandhof 13 years ago
commit
aeadc1f912
100 changed files with 8792 additions and 0 deletions
  1. 165
    0
      COPYING
  2. 5
    0
      archetypes/sonar-basic-plugin/README.txt
  3. 58
    0
      archetypes/sonar-basic-plugin/pom.xml
  4. 60
    0
      archetypes/sonar-basic-plugin/project/pom.xml
  5. 25
    0
      archetypes/sonar-basic-plugin/project/src/main/java/org/sonar/plugins/sample/SampleDashboardWidget.java
  6. 26
    0
      archetypes/sonar-basic-plugin/project/src/main/java/org/sonar/plugins/sample/SampleMetrics.java
  7. 43
    0
      archetypes/sonar-basic-plugin/project/src/main/java/org/sonar/plugins/sample/SamplePlugin.java
  8. 30
    0
      archetypes/sonar-basic-plugin/project/src/main/java/org/sonar/plugins/sample/SampleSensor.java
  9. 23
    0
      archetypes/sonar-basic-plugin/project/src/main/resources/sample_dashboard_widget.html.erb
  10. 16
    0
      archetypes/sonar-basic-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml
  11. 12
    0
      archetypes/sonar-basic-plugin/src/main/resources/META-INF/maven/archetype.xml
  12. 59
    0
      archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/pom.xml
  13. 28
    0
      archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/src/main/java/SampleDashboardWidget.java
  14. 29
    0
      archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/src/main/java/SampleMetrics.java
  15. 46
    0
      archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/src/main/java/SamplePlugin.java
  16. 33
    0
      archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/src/main/java/SampleSensor.java
  17. 23
    0
      archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/src/main/resources/sample_dashboard_widget.html.erb
  18. 65
    0
      archetypes/sonar-gwt-plugin/pom.xml
  19. 125
    0
      archetypes/sonar-gwt-plugin/project/pom.xml
  20. 40
    0
      archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/GwtSamplePlugin.java
  21. 18
    0
      archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/GwtSamplePage.java
  22. 13
    0
      archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/SamplePage.gwt.xml
  23. 11
    0
      archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/client/I18nConstants.java
  24. 2
    0
      archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/client/I18nConstants_fr.properties
  25. 18
    0
      archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/client/SamplePage.java
  26. 32
    0
      archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/public/test.html
  27. 17
    0
      archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/resourcetab/GwtSampleResourceTab.java
  28. 10
    0
      archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/resourcetab/SampleResourceTab.gwt.xml
  29. 14
    0
      archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/resourcetab/client/SampleResourceTab.java
  30. 13
    0
      archetypes/sonar-gwt-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml
  31. 15
    0
      archetypes/sonar-gwt-plugin/src/main/resources/META-INF/maven/archetype.xml
  32. 123
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/pom.xml
  33. 43
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/GwtSamplePlugin.java
  34. 21
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/GwtSamplePage.java
  35. 16
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/SamplePage.gwt.xml
  36. 14
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/client/I18nConstants.java
  37. 5
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/client/I18nConstants_fr.properties
  38. 21
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/client/SamplePage.java
  39. 35
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/public/test.html
  40. 20
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/resourcetab/GwtSampleResourceTab.java
  41. 13
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/resourcetab/SampleResourceTab.gwt.xml
  42. 17
    0
      archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/resourcetab/client/SampleResourceTab.java
  43. 9
    0
      deploy-docs.sh
  44. 91
    0
      plugins/sonar-checkstyle-plugin/pom.xml
  45. 127
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java
  46. 138
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
  47. 35
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConstants.java
  48. 100
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java
  49. 68
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java
  50. 178
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java
  51. 52
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepository.java
  52. 51
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java
  53. 54
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleVersion.java
  54. 31
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayProfile.java
  55. 32
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfile.java
  56. 31
    0
      plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SunConventionsProfile.java
  57. 1
    0
      plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/checkstyle-plugin.properties
  58. 152
    0
      plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sonar-way.xml
  59. 637
    0
      plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sun-conventions.xml
  60. 1682
    0
      plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml
  61. 86
    0
      plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
  62. 35
    0
      plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstylePluginTest.java
  63. 142
    0
      plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest.java
  64. 41
    0
      plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepositoryTest.java
  65. 35
    0
      plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleVersionTest.java
  66. 38
    0
      plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayProfileTest.java
  67. 36
    0
      plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfileTest.java
  68. 40
    0
      plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SunConventionsProfileTest.java
  69. 24
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/failIfConfigurationToReuseDoesNotExist/pom.xml
  70. 1
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/checkstyle.xml
  71. 25
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/pom.xml
  72. 8
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/writeConfigurationToWorkingDir/pom.xml
  73. 17
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addCustomFilters.xml
  74. 16
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addTheIdPropertyWhenManyInstancesWithTheSameConfigKey.xml
  75. 8
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/alwaysSetFileContentsHolderAndSuppressionCommentFilter.xml
  76. 13
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/exportParameters.xml
  77. 8
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/noCheckstyleRulesToExport.xml
  78. 17
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/singleCheckstyleRulesToExport.xml
  79. 15
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/checkstyle-class-without-package.xml
  80. 34
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/checkstyle-result.xml
  81. 3
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/test_header.xml
  82. 14
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/test_module_tree.xml
  83. 7
    0
      plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/test_xml_with_param_value_id.xml
  84. 57
    0
      plugins/sonar-clover-plugin/pom.xml
  85. 31
    0
      plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverConstants.java
  86. 130
    0
      plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverMavenPluginHandler.java
  87. 63
    0
      plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverPlugin.java
  88. 102
    0
      plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverSensor.java
  89. 207
    0
      plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/XmlReportParser.java
  90. 76
    0
      plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverMavenPluginHandlerTest.java
  91. 33
    0
      plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverPluginTest.java
  92. 54
    0
      plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverSensorTest.java
  93. 150
    0
      plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/XmlReportParserTest.java
  94. 30
    0
      plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/CloverMavenPluginHandlerTest/overrideConfiguration.xml
  95. 30
    0
      plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/CloverMavenPluginHandlerTest/shouldSkipCloverWithPomConfig.xml
  96. 32
    0
      plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/CloverMavenPluginHandlerTest/shouldSkipCloverWithPomProperty.xml
  97. 458
    0
      plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/XmlReportParserTest/clover.xml
  98. 1793
    0
      plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/XmlReportParserTest/clover_2_3_2.xml
  99. 12
    0
      plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/XmlReportParserTest/coverageShouldBeZeroWhenNoElements/clover.xml
  100. 0
    0
      plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/clover.license

+ 165
- 0
COPYING View File

@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.


This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.

0. Additional Definitions.

As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.

"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.

An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.

A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".

The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.

The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.

1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.

2. Conveying Modified Versions.

If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:

a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or

b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.

3. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:

a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the object code with a copy of the GNU GPL and this license
document.

4. Combined Works.

You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:

a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.

c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.

d) Do one of the following:

0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.

1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.

e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)

5. Combined Libraries.

You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:

a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.

b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.

6. Revised Versions of the GNU Lesser General Public License.

The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.

If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

+ 5
- 0
archetypes/sonar-basic-plugin/README.txt View File

@@ -0,0 +1,5 @@
To update the archetype project :

1. update sources of the initial project (/project directory)
2. /project$ mvn install -DsonarTargetVersion=<version>
3. copy the content of /project/target/generated-sources/archetype/src/main/resources to src/main/resources. Be careful with .svn files !

+ 58
- 0
archetypes/sonar-basic-plugin/pom.xml View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar</artifactId>
<version>2.3-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<groupId>org.codehaus.sonar.archetypes</groupId>
<artifactId>sonar-basic-plugin-archetype</artifactId>
<packaging>maven-archetype</packaging>
<name>Sonar :: Archetypes :: Basic</name>
<description>Maven archetype to create a basic Sonar plugin</description>

<properties>
<sonarTargetVersion>${project.version}</sonarTargetVersion>
</properties>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>2.0-alpha-4</version>
</extension>
</extensions>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.0-alpha-4</version>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 60
- 0
archetypes/sonar-basic-plugin/project/pom.xml View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.sonar.archetypes</groupId>
<artifactId>sonar-basic-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>My Sonar plugin</name>
<description>plugin description</description>

<!-- optional -->
<organization>
<name>My company</name>
<url>http://www.mycompany.com</url>
</organization>
<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonarTargetVersion}</version>
</dependency>
<!-- add your dependencies here -->
<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-testing-harness</artifactId>
<version>${sonarTargetVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>0.1</version>
<extensions>true</extensions>
<configuration>
<pluginKey>sample</pluginKey>
<pluginClass>${package}.SamplePlugin</pluginClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 25
- 0
archetypes/sonar-basic-plugin/project/src/main/java/org/sonar/plugins/sample/SampleDashboardWidget.java View File

@@ -0,0 +1,25 @@
package org.sonar.plugins.sample;

import org.sonar.api.web.AbstractRubyTemplate;
import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.RubyRailsWidget;
import org.sonar.api.web.UserRole;

@NavigationSection(NavigationSection.RESOURCE)
@UserRole(UserRole.USER)
public class SampleDashboardWidget extends AbstractRubyTemplate implements RubyRailsWidget {

public String getId() {
return "sample";
}

public String getTitle() {
// not used for the moment by widgets.
return "Sample";
}

@Override
protected String getTemplatePath() {
return "/sample_dashboard_widget.html.erb";
}
}

+ 26
- 0
archetypes/sonar-basic-plugin/project/src/main/java/org/sonar/plugins/sample/SampleMetrics.java View File

@@ -0,0 +1,26 @@
package org.sonar.plugins.sample;

import org.sonar.api.measures.Metrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.CoreMetrics;

import java.util.List;
import java.util.Arrays;

public class SampleMetrics implements Metrics {

public static final Metric MESSAGE = new Metric("message_key", "Message",
"This is a metric to store a well known message", Metric.ValueType.STRING, -1, false,
CoreMetrics.DOMAIN_GENERAL);


public static final Metric RANDOM = new Metric("random", "Random",
"Random value", Metric.ValueType.FLOAT, Metric.DIRECTION_BETTER, false,
CoreMetrics.DOMAIN_GENERAL);

// getMetrics() method is defined in the Metrics interface and is used by
// Sonar to retrieve the list of new Metric
public List<Metric> getMetrics() {
return Arrays.asList(MESSAGE, RANDOM);
}
}

+ 43
- 0
archetypes/sonar-basic-plugin/project/src/main/java/org/sonar/plugins/sample/SamplePlugin.java View File

@@ -0,0 +1,43 @@
package org.sonar.plugins.sample;
import org.sonar.api.Plugin;
import java.util.ArrayList;
import java.util.List;
/**
* This class is the entry point for all extensions
*/
public class SamplePlugin implements Plugin {
/**
* @deprecated this is not used anymore
*/
public String getKey() {
return "sample";
}
/**
* @deprecated this is not used anymore
*/
public String getName() {
return "My Sonar plugin";
}
/**
* @deprecated this is not used anymore
*/
public String getDescription() {
return "You shouldn't expect too much from this plugin except displaying the Hello World message.";
}
// This is where you're going to declare all your Sonar extensions
public List getExtensions() {
return Arrays.asList(SampleMetrics.class, SampleSensor.class, SampleDashboardWidget.class);
}
@Override
public String toString() {
return getClass().getSimpleName();
}
}

+ 30
- 0
archetypes/sonar-basic-plugin/project/src/main/java/org/sonar/plugins/sample/SampleSensor.java View File

@@ -0,0 +1,30 @@
package org.sonar.plugins.sample;

import org.apache.commons.lang.math.RandomUtils;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.Project;

public class SampleSensor implements Sensor {

public boolean shouldExecuteOnProject(Project project) {
// this sensor is executed on any type of project
return true;
}

public void analyse(Project project, SensorContext sensorContext) {
saveLabelMeasure(sensorContext);
saveNumericMeasure(sensorContext);
}

private void saveNumericMeasure(SensorContext context) {
// Sonar API includes many libraries like commons-lang and google-collections
context.saveMeasure(SampleMetrics.RANDOM, RandomUtils.nextDouble());
}

private void saveLabelMeasure(SensorContext context) {
Measure measure = new Measure(SampleMetrics.MESSAGE, "Hello World!");
context.saveMeasure(measure);
}
}

+ 23
- 0
archetypes/sonar-basic-plugin/project/src/main/resources/sample_dashboard_widget.html.erb View File

@@ -0,0 +1,23 @@
<div class="dashbox">
<h3><span title="<%= metric('random').description -%>"></span></h3>
<p>
<span class="big">
<%= format_measure('random') -%> <%= tendency_icon(measure('random')) %>
</span>
</p>
<p><%= format_measure('message') -%></p>
<p>
<%= format_measure('ncloc', :suffix => ' lines', :url => url_for_drilldown('ncloc')) -%>
</p>
</div>
<div class="dashbox">
<h3>Help</h3>
<p>
Read configuration : <%= configuration('sonar.jdbc.username') -%>
</p>

<p>
Sample of Jfree Eastwood chart : <br/>
<%= gchart('cht=bhs&chco=FF0000,00FF00,0000FF&chs=200x125&chd=s:FOE,THE,Bar&chxt=x,y&chxl=1:|Dec|Nov|Oct|0:||20K||60K||100K|') -%>
</p>
</div>

+ 16
- 0
archetypes/sonar-basic-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?><archetype-descriptor name="sonar-basic-plugin">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.erb</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>

+ 12
- 0
archetypes/sonar-basic-plugin/src/main/resources/META-INF/maven/archetype.xml View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?><archetype>
<id>sonar-basic-plugin</id>
<sources>
<source>src/main/java/SampleDashboardWidget.java</source>
<source>src/main/java/SampleMetrics.java</source>
<source>src/main/java/SamplePlugin.java</source>
<source>src/main/java/SampleSensor.java</source>
</sources>
<resources>
<resource>src/main/resources/sample_dashboard_widget.html.erb</resource>
</resources>
</archetype>

+ 59
- 0
archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/pom.xml View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>$groupId</groupId>
<artifactId>$artifactId</artifactId>
<packaging>sonar-plugin</packaging>
<version>$version</version>
<name>My Sonar plugin</name>
<description>plugin description</description>
<!-- optional -->
<organization>
<name>My company</name>
<url>http://www.mycompany.com</url>
</organization>
<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonarTargetVersion}</version>
</dependency>
<!-- add your dependencies here -->
<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-testing-harness</artifactId>
<version>${sonarTargetVersion}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>0.1</version>
<extensions>true</extensions>
<configuration>
<pluginKey>sample</pluginKey>
<pluginClass>${package}.SamplePlugin</pluginClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 28
- 0
archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/src/main/java/SampleDashboardWidget.java View File

@@ -0,0 +1,28 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package};

import org.sonar.api.web.AbstractRubyTemplate;
import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.RubyRailsWidget;
import org.sonar.api.web.UserRole;

@NavigationSection(NavigationSection.RESOURCE)
@UserRole(UserRole.USER)
public class SampleDashboardWidget extends AbstractRubyTemplate implements RubyRailsWidget {

public String getId() {
return "sample";
}

public String getTitle() {
// not used for the moment by widgets.
return "Sample";
}

@Override
protected String getTemplatePath() {
return "/sample_dashboard_widget.html.erb";
}
}

+ 29
- 0
archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/src/main/java/SampleMetrics.java View File

@@ -0,0 +1,29 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package};

import org.sonar.api.measures.Metrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.CoreMetrics;

import java.util.List;
import java.util.Arrays;

public class SampleMetrics implements Metrics {

public static final Metric MESSAGE = new Metric("message_key", "Message",
"This is a metric to store a well known message", Metric.ValueType.STRING, -1, false,
CoreMetrics.DOMAIN_GENERAL);


public static final Metric RANDOM = new Metric("random", "Random",
"Random value", Metric.ValueType.FLOAT, Metric.DIRECTION_BETTER, false,
CoreMetrics.DOMAIN_GENERAL);

// getMetrics() method is defined in the Metrics interface and is used by
// Sonar to retrieve the list of new Metric
public List<Metric> getMetrics() {
return Arrays.asList(MESSAGE, RANDOM);
}
}

+ 46
- 0
archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/src/main/java/SamplePlugin.java View File

@@ -0,0 +1,46 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package};
import org.sonar.api.Plugin;
import java.util.Arrays;
import java.util.List;
/**
* This class is the entry point for all extensions
*/
public class SamplePlugin implements Plugin {
/**
* @deprecated this is not used anymore
*/
public String getKey() {
return "sample";
}
/**
* @deprecated this is not used anymore
*/
public String getName() {
return "My Sonar plugin";
}
/**
* @deprecated this is not used anymore
*/
public String getDescription() {
return "You shouldn't expect too much from this plugin except displaying the Hello World message.";
}
// This is where you're going to declare all your Sonar extensions
public List getExtensions() {
return Arrays.asList(SampleMetrics.class, SampleSensor.class, SampleDashboardWidget.class);
}
@Override
public String toString() {
return getClass().getSimpleName();
}
}

+ 33
- 0
archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/src/main/java/SampleSensor.java View File

@@ -0,0 +1,33 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package};

import org.apache.commons.lang.math.RandomUtils;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.measures.Measure;
import org.sonar.api.resources.Project;

public class SampleSensor implements Sensor {

public boolean shouldExecuteOnProject(Project project) {
// this sensor is executed on any type of project
return true;
}

public void analyse(Project project, SensorContext sensorContext) {
saveLabelMeasure(sensorContext);
saveNumericMeasure(sensorContext);
}

private void saveNumericMeasure(SensorContext context) {
// Sonar API includes many libraries like commons-lang and google-collections
context.saveMeasure(SampleMetrics.RANDOM, RandomUtils.nextDouble());
}

private void saveLabelMeasure(SensorContext context) {
Measure measure = new Measure(SampleMetrics.MESSAGE, "Hello World!");
context.saveMeasure(measure);
}
}

+ 23
- 0
archetypes/sonar-basic-plugin/src/main/resources/archetype-resources/src/main/resources/sample_dashboard_widget.html.erb View File

@@ -0,0 +1,23 @@
<div class="dashbox">
<h3><span title="<%= metric('random').description -%>"></span></h3>
<p>
<span class="big">
<%= format_measure('random') -%> <%= tendency_icon(measure('random')) %>
</span>
</p>
<p><%= format_measure('message') -%></p>
<p>
<%= format_measure('ncloc', :suffix => ' lines', :url => url_for_drilldown('ncloc')) -%>
</p>
</div>
<div class="dashbox">
<h3>Help</h3>
<p>
Read configuration : <%= configuration('sonar.jdbc.username') -%>
</p>

<p>
Sample of Jfree Eastwood chart : <br/>
<%= gchart('cht=bhs&chco=FF0000,00FF00,0000FF&chs=200x125&chd=s:FOE,THE,Bar&chxt=x,y&chxl=1:|Dec|Nov|Oct|0:||20K||60K||100K|') -%>
</p>
</div>

+ 65
- 0
archetypes/sonar-gwt-plugin/pom.xml View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar</artifactId>
<version>2.3-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<groupId>org.codehaus.sonar.archetypes</groupId>
<artifactId>sonar-gwt-plugin-archetype</artifactId>
<packaging>maven-archetype</packaging>
<name>Sonar :: Archetypes :: GWT</name>
<description>Maven archetype to create a Sonar plugin including GWT pages</description>

<properties>
<sonarTargetVersion>${project.version}</sonarTargetVersion>
<dollar>$</dollar>
</properties>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-gwt-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>

<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>2.0-alpha-4</version>
</extension>
</extensions>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.0-alpha-4</version>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 125
- 0
archetypes/sonar-gwt-plugin/project/pom.xml View File

@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.sonar.archetypes</groupId>
<artifactId>sonar-gwt-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>My Sonar GWT plugin</name>
<description>GWT Sample description</description>
<!-- optional -->
<organization>
<name>My company</name>
<url>http://www.mycompany.com</url>
</organization>

<repositories>
<repository>
<!-- for gwt-incubator -->
<id>sonar</id>
<name>Sonar</name>
<url>http://repository.sonarsource.org/content/repositories/sonar</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonarTargetVersion}</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-gwt-api</artifactId>
<version>${sonarTargetVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-incubator</artifactId>
<version>20100204-r1747</version>
<scope>provided</scope>
</dependency>

<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-testing-harness</artifactId>
<version>${sonarTargetVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>0.1</version>
<extensions>true</extensions>
<configuration>
<pluginKey>gwt-sample</pluginKey>
<pluginName>GWT Sample</pluginName>
<pluginClass>${package}.GwtSamplePlugin</pluginClass>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<configuration>
<modules>
<module>${package}.resourcetab.SampleResourceTab</module>
<module>${package}.page.SamplePage</module>
</modules>
<webappDirectory>${project.build.directory}/classes</webappDirectory>
<!-- do not break the following property on two lines -->
<extraJvmArgs>-Xmx512m -Dgwt.jjs.permutationWorkerFactory=com.google.gwt.dev.ThreadedPermutationWorkerFactory</extraJvmArgs>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 40
- 0
archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/GwtSamplePlugin.java View File

@@ -0,0 +1,40 @@
package org.sonar.plugins.gwtsample;
import org.sonar.api.Plugin;
import org.sonar.plugins.gwtsample.page.GwtSamplePage;
import org.sonar.plugins.gwtsample.resourcetab.GwtSampleResourceTab;
import java.util.Arrays;
import java.util.List;
public class GwtSamplePlugin implements Plugin {
/**
* @deprecated this is not used anymore
*/
public String getKey() {
return "gwt-sample";
}
/**
* @deprecated this is not used anymore
*/
public String getName() {
return "GWT Sample";
}
/**
* @deprecated this is not used anymore
*/
public String getDescription() {
return "GWT Sample description";
}
public List getExtensions() {
return Arrays.asList(GwtSampleResourceTab.class, GwtSamplePage.class);
}
public String toString() {
return getKey();
}
}

+ 18
- 0
archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/GwtSamplePage.java View File

@@ -0,0 +1,18 @@
package org.sonar.plugins.gwtsample.page;

import org.sonar.api.web.GwtPage;
import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.UserRole;

@NavigationSection(NavigationSection.RESOURCE)
@UserRole(UserRole.USER)
public class GwtSamplePage extends GwtPage {

public String getGwtId() {
return "org.sonar.plugins.gwtsample.page.SamplePage";
}

public String getTitle() {
return "Sample";
}
}

+ 13
- 0
archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/SamplePage.gwt.xml View File

@@ -0,0 +1,13 @@
<module>

<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.json.JSON"/>
<inherits name="com.google.gwt.http.HTTP"/>
<inherits name="org.sonar.Sonar"/>

<entry-point class='org.sonar.plugins.gwtsample.page.client.SamplePage'/>

<extend-property name="locale" values="en"/>
<extend-property name="locale" values="fr"/>

</module>

+ 11
- 0
archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/client/I18nConstants.java View File

@@ -0,0 +1,11 @@
package org.sonar.plugins.gwtsample.page.client;

import com.google.gwt.core.client.GWT;

public interface I18nConstants extends com.google.gwt.i18n.client.Constants {

static I18nConstants INSTANCE = GWT.create(I18nConstants.class);

@DefaultStringValue("This is a sample")
String sample();
}

+ 2
- 0
archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/client/I18nConstants_fr.properties View File

@@ -0,0 +1,2 @@
# This file must use UTF-8 encoding
sample=Ceci est un exemple

+ 18
- 0
archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/client/SamplePage.java View File

@@ -0,0 +1,18 @@
package org.sonar.plugins.gwtsample.page.client;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import org.sonar.gwt.ui.Page;
import org.sonar.wsclient.services.Resource;

public class SamplePage extends Page {

@Override
protected Widget doOnResourceLoad(Resource resource) {
VerticalPanel panel = new VerticalPanel();
panel.add(new Label(resource.getName(true)));
panel.add(new Label(I18nConstants.INSTANCE.sample()));
return panel;
}
}

+ 32
- 0
archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/page/public/test.html View File

@@ -0,0 +1,32 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>GWT Smaple</title>
<link href="http://localhost:9000/dev/stylesheets/yui-2.6.0.css" media="all" rel="Stylesheet" type="text/css" />
<link href="http://localhost:9000/dev/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" />
<script src="http://localhost:9000/dev/javascripts/application.js" type="text/javascript"></script>
<script src="http://localhost:9000/dev/javascripts/prototype.js" type="text/javascript"></script>
<script src="http://localhost:9000/dev/javascripts/scriptaculous.js" type="text/javascript"></script>
</head>

<body>
<script type="text/javascript">
var config = {
"sonar_url": "http://localhost:9000/dev",
"resource_key" : "org.codehaus.sonar:sonar",
};
</script>

<div class="error" id="error" style="display:none"><span id="errormsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$('error').hide();return false;">hide</a>]</div>
<div class="warning" id="warning" style="display:none"><span id="warningmsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$('warning').hide();return false;">hide</a>]</div>
<div class="notice" id="info" style="display:none"><span id="infomsg"></span> &nbsp;&nbsp;[<a href="#" onclick="javascript:$('info').hide();return false;">hide</a>]</div>

<div id="gwtpage">
</div>

<script type="text/javascript" language="javascript" src="org.sonar.plugins.gwtsample.page.GwtSamplePage.nocache.js"></script>
</body>
</html>

+ 17
- 0
archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/resourcetab/GwtSampleResourceTab.java View File

@@ -0,0 +1,17 @@
package org.sonar.plugins.gwtsample.resourcetab;

import org.sonar.api.web.GwtPage;
import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.UserRole;

@NavigationSection(NavigationSection.RESOURCE_TAB)
@UserRole(UserRole.USER)
public class GwtSampleResourceTab extends GwtPage {
public String getTitle() {
return "Sample";
}

public String getGwtId() {
return "org.sonar.plugins.gwtsample.resourcetab.SampleResourceTab";
}
}

+ 10
- 0
archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/resourcetab/SampleResourceTab.gwt.xml View File

@@ -0,0 +1,10 @@
<module>

<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.json.JSON"/>
<inherits name="com.google.gwt.http.HTTP"/>
<inherits name="org.sonar.Sonar"/>

<entry-point class='org.sonar.plugins.gwtsample.resourcetab.client.SampleResourceTab'/>

</module>

+ 14
- 0
archetypes/sonar-gwt-plugin/project/src/main/java/org/sonar/plugins/gwtsample/resourcetab/client/SampleResourceTab.java View File

@@ -0,0 +1,14 @@
package org.sonar.plugins.gwtsample.resourcetab.client;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import org.sonar.gwt.ui.Page;
import org.sonar.wsclient.services.Resource;

public class SampleResourceTab extends Page {

@Override
protected Widget doOnResourceLoad(Resource resource) {
return new Label("This is a sample");
}
}

+ 13
- 0
archetypes/sonar-gwt-plugin/src/main/resources/META-INF/maven/archetype-metadata.xml View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?><archetype-descriptor name="sonar-gwt-plugin-archetype">
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.html</include>
<include>**/*.java</include>
<include>**/*.properties</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>

+ 15
- 0
archetypes/sonar-gwt-plugin/src/main/resources/META-INF/maven/archetype.xml View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?><archetype>
<id>sonar-gwt-plugin</id>
<sources>
<source>src/main/java/GwtSamplePlugin.java</source>
<source>src/main/java/page/client/I18nConstants.java</source>
<source>src/main/java/page/client/I18nConstants_fr.properties</source>
<source>src/main/java/page/client/SamplePage.java</source>
<source>src/main/java/page/GwtSamplePage.java</source>
<source>src/main/java/page/public/test.html</source>
<source>src/main/java/page/SamplePage.gwt.xml</source>
<source>src/main/java/resourcetab/client/SampleResourceTab.java</source>
<source>src/main/java/resourcetab/GwtSampleResourceTab.java</source>
<source>src/main/java/resourcetab/SampleResourceTab.gwt.xml</source>
</sources>
</archetype>

+ 123
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/pom.xml View File

@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>$groupId</groupId>
<artifactId>$artifactId</artifactId>
<packaging>sonar-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>My Sonar GWT plugin</name>
<description>GWT Sample description</description>
<!-- optional -->
<organization>
<name>My company</name>
<url>http://www.mycompany.com</url>
</organization>
<repositories>
<repository>
<!-- for gwt-incubator -->
<id>sonar</id>
<name>Sonar</name>
<url>http://repository.sonarsource.org/content/repositories/sonar</url>
<releases>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonarTargetVersion}</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-gwt-api</artifactId>
<version>${sonarTargetVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-incubator</artifactId>
<version>20100204-r1747</version>
<scope>provided</scope>
</dependency>
<!-- unit tests -->
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-testing-harness</artifactId>
<version>${sonarTargetVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>0.1</version>
<extensions>true</extensions>
<configuration>
<pluginKey>gwt-sample</pluginKey>
<pluginName>GWT Sample</pluginName>
<pluginClass>${package}.GwtSamplePlugin</pluginClass>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<configuration>
<modules>
<module>${package}.resourcetab.SampleResourceTab</module>
<module>${package}.page.SamplePage</module>
</modules>
<webappDirectory>target/classes</webappDirectory>
<!-- do not break the following property on two lines -->
<extraJvmArgs>-Xmx512m -Dgwt.jjs.permutationWorkerFactory=com.google.gwt.dev.ThreadedPermutationWorkerFactory</extraJvmArgs>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 43
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/GwtSamplePlugin.java View File

@@ -0,0 +1,43 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package};
import org.sonar.api.Plugin;
import ${package}.page.GwtSamplePage;
import ${package}.resourcetab.GwtSampleResourceTab;
import java.util.Arrays;
import java.util.List;
public class GwtSamplePlugin implements Plugin {
/**
* @deprecated this is not used anymore
*/
public String getKey() {
return "gwt-sample";
}
/**
* @deprecated this is not used anymore
*/
public String getName() {
return "GWT Sample";
}
/**
* @deprecated this is not used anymore
*/
public String getDescription() {
return "GWT Sample description";
}
public List getExtensions() {
return Arrays.asList(GwtSampleResourceTab.class, GwtSamplePage.class);
}
public String toString() {
return getKey();
}
}

+ 21
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/GwtSamplePage.java View File

@@ -0,0 +1,21 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.page;

import org.sonar.api.web.GwtPage;
import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.UserRole;

@NavigationSection(NavigationSection.RESOURCE)
@UserRole(UserRole.USER)
public class GwtSamplePage extends GwtPage {

public String getGwtId() {
return "${package}.page.SamplePage";
}

public String getTitle() {
return "Sample";
}
}

+ 16
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/SamplePage.gwt.xml View File

@@ -0,0 +1,16 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
<module>

<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.json.JSON"/>
<inherits name="com.google.gwt.http.HTTP"/>
<inherits name="org.sonar.Sonar"/>

<entry-point class='${package}.page.client.SamplePage'/>

<extend-property name="locale" values="en"/>
<extend-property name="locale" values="fr"/>

</module>

+ 14
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/client/I18nConstants.java View File

@@ -0,0 +1,14 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.page.client;

import com.google.gwt.core.client.GWT;

public interface I18nConstants extends com.google.gwt.i18n.client.Constants {

static I18nConstants INSTANCE = GWT.create(I18nConstants.class);

@DefaultStringValue("This is a sample")
String sample();
}

+ 5
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/client/I18nConstants_fr.properties View File

@@ -0,0 +1,5 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
${symbol_pound} This file must use UTF-8 encoding
sample=Ceci est un exemple

+ 21
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/client/SamplePage.java View File

@@ -0,0 +1,21 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.page.client;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import org.sonar.gwt.ui.Page;
import org.sonar.wsclient.services.Resource;

public class SamplePage extends Page {

@Override
protected Widget doOnResourceLoad(Resource resource) {
VerticalPanel panel = new VerticalPanel();
panel.add(new Label(resource.getName(true)));
panel.add(new Label(I18nConstants.INSTANCE.sample()));
return panel;
}
}

+ 35
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/page/public/test.html View File

@@ -0,0 +1,35 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>GWT Smaple</title>
<link href="http://localhost:9000/dev/stylesheets/yui-2.6.0.css" media="all" rel="Stylesheet" type="text/css" />
<link href="http://localhost:9000/dev/stylesheets/style.css" media="all" rel="Stylesheet" type="text/css" />
<script src="http://localhost:9000/dev/javascripts/application.js" type="text/javascript"></script>
<script src="http://localhost:9000/dev/javascripts/prototype.js" type="text/javascript"></script>
<script src="http://localhost:9000/dev/javascripts/scriptaculous.js" type="text/javascript"></script>
</head>

<body>
<script type="text/javascript">
var config = {
"sonar_url": "http://localhost:9000/dev",
"resource_key" : "org.codehaus.sonar:sonar",
};
</script>

<div class="error" id="error" style="display:none"><span id="errormsg"></span> &nbsp;&nbsp;[<a href="${symbol_pound}" onclick="javascript:${symbol_dollar}('error').hide();return false;">hide</a>]</div>
<div class="warning" id="warning" style="display:none"><span id="warningmsg"></span> &nbsp;&nbsp;[<a href="${symbol_pound}" onclick="javascript:${symbol_dollar}('warning').hide();return false;">hide</a>]</div>
<div class="notice" id="info" style="display:none"><span id="infomsg"></span> &nbsp;&nbsp;[<a href="${symbol_pound}" onclick="javascript:${symbol_dollar}('info').hide();return false;">hide</a>]</div>

<div id="gwtpage">
</div>

<script type="text/javascript" language="javascript" src="${package}.page.GwtSamplePage.nocache.js"></script>
</body>
</html>

+ 20
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/resourcetab/GwtSampleResourceTab.java View File

@@ -0,0 +1,20 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.resourcetab;

import org.sonar.api.web.GwtPage;
import org.sonar.api.web.NavigationSection;
import org.sonar.api.web.UserRole;

@NavigationSection(NavigationSection.RESOURCE_TAB)
@UserRole(UserRole.USER)
public class GwtSampleResourceTab extends GwtPage {
public String getTitle() {
return "Sample";
}

public String getGwtId() {
return "${package}.resourcetab.SampleResourceTab";
}
}

+ 13
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/resourcetab/SampleResourceTab.gwt.xml View File

@@ -0,0 +1,13 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
<module>

<inherits name='com.google.gwt.user.User'/>
<inherits name="com.google.gwt.json.JSON"/>
<inherits name="com.google.gwt.http.HTTP"/>
<inherits name="org.sonar.Sonar"/>

<entry-point class='${package}.resourcetab.client.SampleResourceTab'/>

</module>

+ 17
- 0
archetypes/sonar-gwt-plugin/src/main/resources/archetype-resources/src/main/java/resourcetab/client/SampleResourceTab.java View File

@@ -0,0 +1,17 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.resourcetab.client;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import org.sonar.gwt.ui.Page;
import org.sonar.wsclient.services.Resource;

public class SampleResourceTab extends Page {

@Override
protected Widget doOnResourceLoad(Resource resource) {
return new Label("This is a sample");
}
}

+ 9
- 0
deploy-docs.sh View File

@@ -0,0 +1,9 @@
#!/bin/sh

mvn clean javadoc:aggregate -Prelease

tar -cf docs.tar -C target/site/ .

scp -i ~/.ssh/id_rsa-sonar-keypair -C -r docs.tar root@ec2-75-101-133-159.compute-1.amazonaws.com:/tmp

ssh -i ~/.ssh/id_rsa-sonar-keypair root@ec2-75-101-133-159.compute-1.amazonaws.com 'tar -xf /tmp/docs.tar -C /vol/www/sonar.codehaus.org/docs'

+ 91
- 0
plugins/sonar-checkstyle-plugin/pom.xml View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar</artifactId>
<version>2.3-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<groupId>org.codehaus.sonar.plugins</groupId>
<artifactId>sonar-checkstyle-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<name>Sonar :: Plugins :: Checkstyle</name>
<description>Checkstyle is a code analyser to help programmers write Java code that adheres to a coding standard.</description>

<properties>
<checkstyle.version>5.1</checkstyle.version>
</properties>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
</dependency>
<dependency>
<groupId>checkstyle</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
<exclusion>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-testing-harness</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>${basedir}/src/main/resources</directory>
</testResource>
<testResource>
<directory>${basedir}/src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<pluginKey>checkstyle</pluginKey>
<pluginName>Checkstyle</pluginName>
<pluginClass>org.sonar.plugins.checkstyle.CheckstylePlugin</pluginClass>
<pluginDescription><![CDATA[Analyze Java code with <a href="http://checkstyle.sourceforge.net/">Checkstyle</a> ${checkstyle.version}.]]></pluginDescription>
</configuration>
</plugin>

<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 127
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java View File

@@ -0,0 +1,127 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import com.puppycrawl.tools.checkstyle.api.AuditEvent;
import com.puppycrawl.tools.checkstyle.api.AuditListener;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Violation;

/**
* @since 2.3
*/
public final class CheckstyleAuditListener implements AuditListener, BatchExtension {

private final SensorContext context;
private final Project project;
private final RulesProfile profile;
private Resource currentResource = null;

public CheckstyleAuditListener(SensorContext context, Project project, RulesProfile profile) {
this.context = context;
this.project = project;
this.profile = profile;
}

public void auditStarted(AuditEvent event) {

}

public void auditFinished(AuditEvent event) {

}

public void fileStarted(AuditEvent event) {

}

public void fileFinished(AuditEvent event) {
currentResource = null;
}

public void addError(AuditEvent event) {
String ruleKey = getRuleKey(event);
if (ruleKey != null) {
ActiveRule activeRule = profile.getActiveRule(CheckstyleConstants.REPOSITORY_KEY, ruleKey);
if (activeRule != null) {
initResource(event);
Violation violation = new Violation(activeRule.getRule(), currentResource)
.setLineId(getLineId(event))
.setMessage(getMessage(event));
context.saveViolation(violation);
}
}
}

private void initResource(AuditEvent event) {
if (currentResource == null) {
String absoluteFilename = event.getFileName();
currentResource = JavaFile.fromAbsolutePath(absoluteFilename, project.getFileSystem().getSourceDirs(), false);
}
}

private String getRuleKey(AuditEvent event) {
String key = null;
try {
key = event.getModuleId();
} catch (Exception e) {
// checkstyle throws a NullPointer if the message is not set
}
if (StringUtils.isBlank(key)) {
try {
key = event.getSourceName();
} catch (Exception e) {
// checkstyle can throw a NullPointer if the message is not set
}
}
return key;
}

private String getMessage(AuditEvent event) {
try {
return event.getMessage();

} catch (Exception e) {
// checkstyle can throw a NullPointer if the message is not set
return null;
}
}

private int getLineId(AuditEvent event) {
try {
return event.getLine();

} catch (Exception e) {
// checkstyle can throw a NullPointer if the message is not set
return 0;
}
}

public void addException(AuditEvent event, Throwable throwable) {
// TODO waiting for sonar technical events ?
}
}

+ 138
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java View File

@@ -0,0 +1,138 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.PropertiesExpander;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import com.puppycrawl.tools.checkstyle.api.Configuration;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.CharEncoding;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchExtension;
import org.sonar.api.batch.maven.MavenPlugin;
import org.sonar.api.batch.maven.MavenUtils;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.SonarException;

import java.io.*;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Properties;

public class CheckstyleConfiguration implements BatchExtension {

private static Logger LOG = LoggerFactory.getLogger(CheckstyleConfiguration.class);

private CheckstyleProfileExporter confExporter;
private RulesProfile profile;
private Project project;

public CheckstyleConfiguration(CheckstyleProfileExporter confExporter, RulesProfile profile, Project project) {
this.confExporter = confExporter;
this.profile = profile;
this.project = project;
}

public File getXMLDefinitionFile() {
if (project.getReuseExistingRulesConfig()) {
return findExistingXML();
}

Writer writer = null;
File xmlFile = new File(project.getFileSystem().getSonarWorkingDirectory(), "checkstyle.xml");
try {
writer = new OutputStreamWriter(new FileOutputStream(xmlFile, false), CharEncoding.UTF_8);
confExporter.exportProfile(profile, writer);
writer.flush();
return xmlFile;

} catch (IOException e) {
throw new SonarException("Fail to save the Checkstyle configuration to " + xmlFile.getPath(), e);

} finally {
IOUtils.closeQuietly(writer);
}
}

private File findExistingXML() {
File file = null;
MavenPlugin mavenPlugin = MavenPlugin.getPlugin(project.getPom(), MavenUtils.GROUP_ID_APACHE_MAVEN, "maven-checkstyle-plugin");
if (mavenPlugin != null) {
String location = mavenPlugin.getParameter("configLocation");
if (location != null) {
file = new File(location);
if (!file.exists()) {
file = new File(project.getFileSystem().getBasedir(), location);
}
}
}
if (file == null || !file.isFile() || !file.exists()) {
throw new SonarException("The checkstyle configuration file does not exist: " + file);
}
return file;
}

public List<File> getSourceFiles() {
return project.getFileSystem().getSourceFiles(Java.INSTANCE);
}

public File getTargetXMLReport() {
if (project.getConfiguration().getBoolean(CheckstyleConstants.GENERATE_XML_KEY, CheckstyleConstants.GENERATE_XML_DEFAULT_VALUE)) {
return new File(project.getFileSystem().getSonarWorkingDirectory(), "checkstyle-result.xml");
}
return null;
}

public Configuration getCheckstyleConfiguration() throws IOException, CheckstyleException {
File xmlConfig = getXMLDefinitionFile();

LOG.info("Checkstyle configuration: " + xmlConfig.getAbsolutePath());
Configuration configuration = ConfigurationLoader.loadConfiguration(xmlConfig.getAbsolutePath(), new PropertiesExpander(new Properties()));
defineCharset(configuration);
return configuration;
}


private void defineCharset(Configuration configuration) {
Configuration[] modules = configuration.getChildren();
for (Configuration module : modules) {
if ("Checker".equals(module.getName()) || "com.puppycrawl.tools.checkstyle.Checker".equals(module.getName())) {
if (module instanceof DefaultConfiguration) {
Charset charset = getCharset();
LOG.info("Checkstyle charset: " + charset.name());
((DefaultConfiguration) module).addAttribute("charset", charset.name());
}
}
}
}

public Charset getCharset() {
Charset charset = project.getFileSystem().getSourceCharset();
if (charset == null) {
charset = Charset.forName(System.getProperty("file.encoding", CharEncoding.UTF_8));
}
return charset;
}
}

+ 35
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConstants.java View File

@@ -0,0 +1,35 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.sonar.api.CoreProperties;

public final class CheckstyleConstants {

public static final String REPOSITORY_KEY = CoreProperties.CHECKSTYLE_PLUGIN;
public static final String REPOSITORY_NAME = "Checkstyle";
public static final String PLUGIN_NAME = "Checkstyle";

public static final String FILTERS_KEY = "sonar.checkstyle.filters";

public static final String FILTERS_DEFAULT_VALUE = "<module name=\"SuppressionCommentFilter\"/>";
public static final String GENERATE_XML_KEY = "sonar.checkstyle.generateXml";
public static final boolean GENERATE_XML_DEFAULT_VALUE = false;
}

+ 100
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleExecutor.java View File

@@ -0,0 +1,100 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import com.puppycrawl.tools.checkstyle.Checker;
import com.puppycrawl.tools.checkstyle.PackageNamesLoader;
import com.puppycrawl.tools.checkstyle.XMLLogger;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchExtension;
import org.sonar.api.batch.ProjectClasspath;
import org.sonar.api.utils.TimeProfiler;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.URLClassLoader;

public class CheckstyleExecutor implements BatchExtension {
private static Logger LOG = LoggerFactory.getLogger(CheckstyleExecutor.class);

private CheckstyleConfiguration configuration;
private URLClassLoader projectClassloader;
private CheckstyleAuditListener listener;

public CheckstyleExecutor(CheckstyleConfiguration configuration, CheckstyleAuditListener listener, ProjectClasspath classpath) {
this.configuration = configuration;
this.listener = listener;
this.projectClassloader = classpath.getClassloader();
}


CheckstyleExecutor(CheckstyleConfiguration configuration, CheckstyleAuditListener listener, URLClassLoader projectClassloader) {
this.configuration = configuration;
this.listener = listener;
this.projectClassloader = projectClassloader;
}

/**
* Execute Checkstyle and return the generated XML report.
*/
public void execute() {
TimeProfiler profiler = new TimeProfiler().start("Execute Checkstyle " + CheckstyleVersion.getVersion());
ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(PackageNamesLoader.class.getClassLoader());

Checker checker = null;
OutputStream xmlOutput = null;
try {

checker = new Checker();
checker.setClassloader(projectClassloader);
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.addListener(listener);

File xmlReport = configuration.getTargetXMLReport();
if (xmlReport != null) {
LOG.info("Checkstyle output report: " + xmlReport.getAbsolutePath());
xmlOutput = new FileOutputStream(xmlReport);
checker.addListener(new XMLLogger(xmlOutput, true));
}

checker.setCharset(configuration.getCharset().name());
checker.configure(configuration.getCheckstyleConfiguration());
checker.process(configuration.getSourceFiles());

profiler.stop();

} catch (Exception e) {
throw new RuntimeException("Can not execute Checkstyle", e);

} finally {
if (checker != null) {
checker.destroy();
}
IOUtils.closeQuietly(xmlOutput);
Thread.currentThread().setContextClassLoader(initialClassLoader);
}
}


}

+ 68
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java View File

@@ -0,0 +1,68 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.sonar.api.CoreProperties;
import org.sonar.api.Plugin;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.profiles.XMLProfileDefinition;
import org.sonar.api.resources.Java;

import java.util.Arrays;
import java.util.List;

@Properties( {
@Property(key = CheckstyleConstants.FILTERS_KEY,
defaultValue = CheckstyleConstants.FILTERS_DEFAULT_VALUE,
name = "Filters",
description = "Checkstyle support three error filtering mechanisms : SuppressionCommentFilter, SuppressWithNearbyCommentFilter and SuppressionFilter."
+ "This property allows to configure all those filters with a native XML format."
+ " See <a href='http://checkstyle.sourceforge.net/config.html'>Checkstyle configuration page</a> to get more information on those filters.",
project = false, global = true) })
public class CheckstylePlugin implements Plugin {

public String getKey() {
return CoreProperties.CHECKSTYLE_PLUGIN;
}

public String getName() {
return CheckstyleConstants.PLUGIN_NAME;
}

public String getDescription() {
return "Checkstyle is a rule engine that helps programmers writing Java code that adheres to a coding standard. " +
"You can find more by going to the <a href='http://checkstyle.sourceforge.net'>Checkstyle web site</a>.";
}

public List getExtensions() {
return Arrays.asList(
CheckstyleSensor.class,
CheckstyleConfiguration.class,
CheckstyleExecutor.class,
CheckstyleAuditListener.class,
CheckstyleProfileExporter.class,
CheckstyleRuleRepository.class,
SonarWayProfile.class,
SunConventionsProfile.class,
SonarWayWithFindbugsProfile.class);
}
}

+ 178
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporter.java View File

@@ -0,0 +1,178 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.profiles.ProfileExporter;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.ActiveRuleParam;
import org.sonar.api.rules.RuleParam;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.utils.SonarException;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

public class CheckstyleProfileExporter extends ProfileExporter {

private Configuration conf;

public CheckstyleProfileExporter(Configuration conf) {
this.conf = conf;
setSupportedRepositories(CheckstyleConstants.REPOSITORY_KEY);
}

/**
* for unit tests
*/
CheckstyleProfileExporter() {
this(new BaseConfiguration());
}

public void exportProfile(RulesProfile profile, Writer writer) {
try {
ListMultimap<String, ActiveRule> activeRulesByConfigKey = arrangeByConfigKey(profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY));
generateXML(writer, activeRulesByConfigKey);

} catch (IOException e) {
throw new SonarException("Fail to export the profile " + profile, e);
}

}

private void generateXML(Writer writer, ListMultimap<String, ActiveRule> activeRulesByConfigKey) throws IOException {
appendXmlHeader(writer);
appendCustomFilters(writer);
appendCheckerModules(writer, activeRulesByConfigKey);
appendTreeWalker(writer, activeRulesByConfigKey);
appendXmlFooter(writer);
}

private void appendXmlHeader(Writer writer) throws IOException {
writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<!DOCTYPE module PUBLIC \"-//Puppy Crawl//DTD Check Configuration 1.2//EN\" \"http://www.puppycrawl.com/dtds/configuration_1_2.dtd\">"
+ "<!-- Generated by Sonar -->"
+ "<module name=\"Checker\">");
}

private void appendCustomFilters(Writer writer) throws IOException {
String filtersXML = conf.getString(CheckstyleConstants.FILTERS_KEY, CheckstyleConstants.FILTERS_DEFAULT_VALUE);
if (StringUtils.isNotBlank(filtersXML)) {
writer.append(filtersXML);
}
}

private void appendCheckerModules(Writer writer, ListMultimap<String, ActiveRule> activeRulesByConfigKey) throws IOException {
for (String configKey : activeRulesByConfigKey.keySet()) {
if (!isInTreeWalker(configKey)) {
List<ActiveRule> activeRules = activeRulesByConfigKey.get(configKey);
for (ActiveRule activeRule : activeRules) {
appendModule(writer, activeRule, activeRules.size() > 1);
}
}
}
}

private void appendTreeWalker(Writer writer, ListMultimap<String, ActiveRule> activeRulesByConfigKey) throws IOException {
writer.append("<module name=\"TreeWalker\">");
writer.append("<module name=\"FileContentsHolder\"/> ");
for (String configKey : activeRulesByConfigKey.keySet()) {
if (isInTreeWalker(configKey)) {
List<ActiveRule> activeRules = activeRulesByConfigKey.get(configKey);
for (ActiveRule activeRule : activeRules) {
appendModule(writer, activeRule, activeRules.size() > 1);
}
}
}
writer.append("</module>");
}

private void appendXmlFooter(Writer writer) throws IOException {
writer.append("</module>");
}

static boolean isInTreeWalker(String configKey) {
return StringUtils.startsWithIgnoreCase(configKey, "Checker/TreeWalker/");
}

private static ListMultimap<String, ActiveRule> arrangeByConfigKey(List<ActiveRule> activeRules) {
ListMultimap<String, ActiveRule> result = ArrayListMultimap.create();
if (activeRules != null) {
for (ActiveRule activeRule : activeRules) {
result.put(activeRule.getConfigKey(), activeRule);
}
}
return result;
}

private void appendModule(Writer writer, ActiveRule activeRule, boolean manyInstances) throws IOException {
String moduleName = StringUtils.substringAfterLast(activeRule.getConfigKey(), "/");
writer.append("<module name=\"");
StringEscapeUtils.escapeXml(writer, moduleName);
writer.append("\">");
if (manyInstances) {
appendModuleProperty(writer, "id", activeRule.getRuleKey());
}
appendModuleProperty(writer, "severity", toCheckstyleSeverity(activeRule.getPriority()));
for (RuleParam ruleParam : activeRule.getRule().getParams()) {
ActiveRuleParam activeParam = activeRule.getParameter(ruleParam.getKey());
String value = null;
if (activeParam == null) {
value = ruleParam.getDefaultValue();
} else {
value = activeParam.getValue(true);
}
if (value != null) {
appendModuleProperty(writer, ruleParam.getKey(), value);
}
}
writer.append("</module>");
}

private void appendModuleProperty(Writer writer, String propertyKey, String propertyValue) throws IOException {
if (StringUtils.isNotBlank(propertyValue)) {
writer.append("<property name=\"");
StringEscapeUtils.escapeXml(writer, propertyKey);
writer.append("\" value=\"");
StringEscapeUtils.escapeXml(writer, propertyValue);
writer.append("\"/>");
}
}

static String toCheckstyleSeverity(RulePriority priority) {
if (RulePriority.BLOCKER.equals(priority) || RulePriority.CRITICAL.equals(priority)) {
return "error";
}
if (RulePriority.MAJOR.equals(priority)) {
return "warning";
}
if (RulePriority.MINOR.equals(priority) || RulePriority.INFO.equals(priority)) {
return "info";
}
throw new IllegalArgumentException("Priority not supported: " + priority);
}
}

+ 52
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepository.java View File

@@ -0,0 +1,52 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.sonar.api.platform.ServerFileSystem;
import org.sonar.api.resources.Java;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.rules.StandardRuleXmlFormat;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public final class CheckstyleRuleRepository extends RuleRepository {

// for user extensions
private ServerFileSystem fileSystem;

public CheckstyleRuleRepository(ServerFileSystem fileSystem) {
super(CheckstyleConstants.REPOSITORY_KEY, Java.KEY);
setName(CheckstyleConstants.REPOSITORY_NAME);
this.fileSystem = fileSystem;
}

@Override
public List<Rule> createRules() {
List<Rule> rules = new ArrayList<Rule>();
rules.addAll(StandardRuleXmlFormat.parseXml(getClass().getResourceAsStream("/org/sonar/plugins/checkstyle/rules.xml")));
for (File userExtensionXml : fileSystem.getExtensions(CheckstyleConstants.REPOSITORY_KEY, "xml")) {
rules.addAll(StandardRuleXmlFormat.parseXml(userExtensionXml));
}
return rules;
}
}

+ 51
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleSensor.java View File

@@ -0,0 +1,51 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.sonar.api.batch.GeneratesViolations;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;

public class CheckstyleSensor implements Sensor, GeneratesViolations {

private RulesProfile profile;
private CheckstyleExecutor executor;

public CheckstyleSensor(RulesProfile profile, CheckstyleExecutor executor) {
this.profile = profile;
this.executor = executor;
}

public boolean shouldExecuteOnProject(Project project) {
return project.getFileSystem().hasJavaSourceFiles() &&
(!profile.getActiveRulesByPlugin(CheckstyleConstants.REPOSITORY_KEY).isEmpty() || project.getReuseExistingRulesConfig());
}

public void analyse(Project project, SensorContext context) {
executor.execute();
}

@Override
public String toString() {
return getClass().getSimpleName();
}
}

+ 54
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleVersion.java View File

@@ -0,0 +1,54 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.apache.commons.io.IOUtils;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public enum CheckstyleVersion {
INSTANCE;

private static final String PROPERTIES_PATH = "/org/sonar/plugins/checkstyle/checkstyle-plugin.properties";
private String version;

public static String getVersion() {
return INSTANCE.version;
}

private CheckstyleVersion() {
InputStream input = getClass().getResourceAsStream(PROPERTIES_PATH);
try {
Properties properties = new Properties();
properties.load(input);
this.version = properties.getProperty("checkstyle.version");

} catch (IOException e) {
LoggerFactory.getLogger(getClass()).warn("Can not load the Checkstyle version from the file " + PROPERTIES_PATH);
this.version = "";

} finally {
IOUtils.closeQuietly(input);
}
}
}

+ 31
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayProfile.java View File

@@ -0,0 +1,31 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.profiles.XMLProfileDefinition;
import org.sonar.api.resources.Java;

public final class SonarWayProfile extends XMLProfileDefinition {

public SonarWayProfile() {
super(RulesProfile.SONAR_WAY_NAME, Java.KEY, SunConventionsProfile.class.getClassLoader(), "org/sonar/plugins/checkstyle/profile-sonar-way.xml");
}
}

+ 32
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfile.java View File

@@ -0,0 +1,32 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.profiles.XMLProfileDefinition;
import org.sonar.api.resources.Java;

public class SonarWayWithFindbugsProfile extends XMLProfileDefinition {

public SonarWayWithFindbugsProfile() {
super(RulesProfile.SONAR_WAY_NAME, Java.KEY, SunConventionsProfile.class.getClassLoader(), "org/sonar/plugins/checkstyle/profile-sonar-way.xml");
}
}


+ 31
- 0
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/SunConventionsProfile.java View File

@@ -0,0 +1,31 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.profiles.XMLProfileDefinition;
import org.sonar.api.resources.Java;

public final class SunConventionsProfile extends XMLProfileDefinition {

public SunConventionsProfile() {
super(RulesProfile.SUN_CONVENTIONS_NAME, Java.KEY, SunConventionsProfile.class.getClassLoader(), "org/sonar/plugins/checkstyle/profile-sun-conventions.xml");
}
}

+ 1
- 0
plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/checkstyle-plugin.properties View File

@@ -0,0 +1 @@
checkstyle.version=${checkstyle.version}

+ 152
- 0
plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sonar-way.xml View File

@@ -0,0 +1,152 @@
<profile>
<rules>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.ParameterAssignmentCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.SimplifyBooleanExpressionCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.StaticVariableNameCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.EmptyStatementCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.InnerAssignmentCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.DoubleCheckedLockingCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.StringLiteralEqualityCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.modifier.RedundantModifierCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.RedundantThrowsCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.IllegalThrowsCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.sizes.AnonInnerLengthCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.PackageNameCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.DefaultComesLastCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.EqualsHashCodeCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.SimplifyBooleanReturnCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>VARIABLE_DEF</value>
</parameter>
<parameter>
<key>ignoreConstructorParameter</key>
<value>true</value>
</parameter>
<parameter>
<key>ignoreSetter</key>
<value>true</value>
</parameter>
<parameter>
<key>ignoreAbstractMethods</key>
<value>true</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.LocalFinalVariableNameCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.ParameterNameCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.metrics.BooleanExpressionComplexityCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck</key>
<parameters>
<parameter>
<key>max</key>
<value>10</value>
</parameter>
</parameters>
</rule>
</rules>
</profile>

+ 637
- 0
plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/profile-sun-conventions.xml View File

@@ -0,0 +1,637 @@
<profile>
<rules>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck</key>
<parameters>
<parameter>
<key>lineSeparator</key>
<value>system</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>COMMA,SEMI,TYPECAST</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>COMMA,SEMI,TYPECAST</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.MissingSwitchDefaultCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyForIteratorPadCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.SimplifyBooleanExpressionCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.modifier.ModifierOrderCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.IllegalInstantiationCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.UpperEllCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.EmptyStatementCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>CTOR_CALL,LPAREN,METHOD_CALL,RPAREN,SUPER_CTOR_CALL</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.blocks.NeedBracesCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>LITERAL_DO,LITERAL_ELSE,LITERAL_IF,LITERAL_FOR,LITERAL_WHILE</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.StaticVariableNameCheck</key>
<parameters>
<parameter>
<key>format</key>
<value>^[a-z][a-zA-Z0-9]*$</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck</key>
<parameters>
<parameter>
<key>format</key>
<value>^[a-z][a-zA-Z0-9]*$</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck</key>
<parameters>
<parameter>
<key>allowUndeclaredRTE</key>
<value>false</value>
</parameter>
<parameter>
<key>allowThrowsTagsForSubclasses</key>
<value>false</value>
</parameter>
<parameter>
<key>allowMissingParamTags</key>
<value>false</value>
</parameter>
<parameter>
<key>allowMissingThrowsTags</key>
<value>false</value>
</parameter>
<parameter>
<key>allowMissingReturnTag</key>
<value>false</value>
</parameter>
<parameter>
<key>allowMissingJavadoc</key>
<value>false</value>
</parameter>
<parameter>
<key>allowMissingPropertyJavadoc</key>
<value>false</value>
</parameter>
<parameter>
<key>tokens</key>
<value>METHOD_DEF,CTOR_DEF</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>METHOD_DEF,CTOR_DEF</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.SimplifyBooleanReturnCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.blocks.EmptyBlockCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>
LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_IF,LITERAL_FOR,LITERAL_TRY,LITERAL_WHILE,INSTANCE_INIT,STATIC_INIT
</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck</key>
<parameters>
<parameter>
<key>format</key>
<value>TODO:</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.DoubleCheckedLockingCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.EqualsHashCodeCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.sizes.FileLengthCheck</key>
<parameters>
<parameter>
<key>max</key>
<value>2000</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck</key>
<parameters>
<parameter>
<key>max</key>
<value>7</value>
</parameter>
<parameter>
<key>tokens</key>
<value>METHOD_DEF,CTOR_DEF</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.modifier.RedundantModifierCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>METHOD_DEF,VARIABLE_DEF,ANNOTATION_FIELD_DEF</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.RedundantThrowsCheck</key>
<parameters>
<parameter>
<key>allowUnchecked</key>
<value>false</value>
</parameter>
<parameter>
<key>allowSubclasses</key>
<value>false</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.TypecastParenPadCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>TYPECAST,RPAREN</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck</key>
<parameters>
<parameter>
<key>ignorePattern</key>
<value>^$</value>
</parameter>
<parameter>
<key>max</key>
<value>80</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.InnerAssignmentCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>
ASSIGN,BAND_ASSIGN,BOR_ASSIGN,BSR_ASSIGN,BXOR_ASSIGN,DIV_ASSIGN,MINUS_ASSIGN,MOD_ASSIGN,PLUS_ASSIGN,SL_ASSIGN,SR_ASSIGN,STAR_ASSIGN
</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck</key>
<parameters>
<parameter>
<key>option</key>
<value>nl</value>
</parameter>
<parameter>
<key>tokens</key>
<value>
BAND,BOR,BSR,BXOR,COLON,DIV,EQUAL,GE,GT,LAND,LE,LITERAL_INSTANCEOF,LOR,LT,MINUS,MOD,NOT_EQUAL,PLUS,QUESTION,SL,SR,STAR
</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck</key>
<parameters>
<parameter>
<key>format</key>
<value>^[a-z][a-zA-Z0-9]*$</value>
</parameter>
<parameter>
<key>applyToPublic</key>
<value>true</value>
</parameter>
<parameter>
<key>applyToProtected</key>
<value>true</value>
</parameter>
<parameter>
<key>applyToPackage</key>
<value>true</value>
</parameter>
<parameter>
<key>applyToPrivate</key>
<value>true</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>LITERAL_TRY,LITERAL_CATCH,LITERAL_FINALLY,LITERAL_IF,LITERAL_ELSE</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.PackageNameCheck</key>
<parameters>
<parameter>
<key>format</key>
<value>^[a-z]+(\.[a-zA-Z_][a-zA-Z0-9_]*)*$</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck</key>
<parameters>
<parameter>
<key>format</key>
<value>^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.TypeNameCheck</key>
<parameters>
<parameter>
<key>format</key>
<value>^[A-Z][a-zA-Z0-9]*$</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.sizes.MethodLengthCheck</key>
<parameters>
<parameter>
<key>max</key>
<value>150</value>
</parameter>
<parameter>
<key>countEmpty</key>
<value>true</value>
</parameter>
<parameter>
<key>tokens</key>
<value>METHOD_DEF,CTOR_DEF</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.LocalFinalVariableNameCheck</key>
<parameters>
<parameter>
<key>format</key>
<value>^[a-z][a-zA-Z0-9]*$</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck</key>
<parameters>
<parameter>
<key>allowMissingParamTags</key>
<value>false</value>
</parameter>
<parameter>
<key>tokens</key>
<value>INTERFACE_DEF,CLASS_DEF</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck</key>
<parameters>
<parameter>
<key>checkFirstSentence</key>
<value>true</value>
</parameter>
<parameter>
<key>checkEmptyJavadoc</key>
<value>false</value>
</parameter>
<parameter>
<key>checkHtml</key>
<value>true</value>
</parameter>
<parameter>
<key>tokens</key>
<value>INTERFACE_DEF,CLASS_DEF,METHOD_DEF,CTOR_DEF,VARIABLE_DEF</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.design.InterfaceIsTypeCheck</key>
<parameters>
<parameter>
<key>allowMarkerInterfaces</key>
<value>true</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>PARAMETER_DEF,VARIABLE_DEF</value>
</parameter>
<parameter>
<key>ignoreConstructorParameter</key>
<value>false</value>
</parameter>
<parameter>
<key>ignoreSetter</key>
<value>false</value>
</parameter>
<parameter>
<key>ignoreAbstractMethods</key>
<value>false</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.AvoidInlineConditionalsCheck</key>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck</key>
<parameters>
<parameter>
<key>allowLineBreaks</key>
<value>true</value>
</parameter>
<parameter>
<key>tokens</key>
<value>ARRAY_INIT,BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck</key>
<parameters>
<parameter>
<key>option</key>
<value>eol</value>
</parameter>
<parameter>
<key>maxLineLength</key>
<value>80</value>
</parameter>
<parameter>
<key>tokens</key>
<value>
CLASS_DEF,CTOR_DEF,INTERFACE_DEF,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,METHOD_DEF
</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.design.VisibilityModifierCheck</key>
<parameters>
<parameter>
<key>packageAllowed</key>
<value>false</value>
</parameter>
<parameter>
<key>protectedAllowed</key>
<value>false</value>
</parameter>
<parameter>
<key>publicMemberPattern</key>
<value>^serialVersionUID$</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.ParameterNameCheck</key>
<parameters>
<parameter>
<key>format</key>
<value>^[a-z][a-zA-Z0-9]*$</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceBeforeCheck</key>
<parameters>
<parameter>
<key>allowLineBreaks</key>
<value>false</value>
</parameter>
<parameter>
<key>tokens</key>
<value>SEMI,POST_DEC,POST_INC</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCheck</key>
<parameters>
<parameter>
<key>allowLineBreaks</key>
<value>false</value>
</parameter>
<parameter>
<key>tokens</key>
<value>CTOR_DEF,LITERAL_NEW,METHOD_CALL,METHOD_DEF,SUPER_CTOR_CALL</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG</value>
</parameter>
<parameter>
<key>ignoreNumbers</key>
<value>-1,0,1,2</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.naming.LocalVariableNameCheck</key>
<parameters>
<parameter>
<key>format</key>
<value>^[a-z][a-zA-Z0-9]*$</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.blocks.AvoidNestedBlocksCheck</key>
<parameters>
<parameter>
<key>allowInSwitchCase</key>
<value>false</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck</key>
<parameters>
<parameter>
<key>tokens</key>
<value>
ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LCURLY,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,GENERIC_START,GENERIC_END,TYPE_EXTENSION_AND,WILDCARD_TYPE
</value>
</parameter>
<parameter>
<key>allowEmptyConstructors</key>
<value>false</value>
</parameter>
<parameter>
<key>allowEmptyMethods</key>
<value>false</value>
</parameter>
</parameters>
</rule>
<rule>
<repositoryKey>checkstyle</repositoryKey>
<key>com.puppycrawl.tools.checkstyle.checks.ArrayTypeStyleCheck</key>
<parameters>
<parameter>
<key>javaStyle</key>
<value>true</value>
</parameter>
</parameters>
</rule>
</rules>
</profile>

+ 1682
- 0
plugins/sonar-checkstyle-plugin/src/main/resources/org/sonar/plugins/checkstyle/rules.xml
File diff suppressed because it is too large
View File


+ 86
- 0
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java View File

@@ -0,0 +1,86 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.mockito.Mockito;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
import org.sonar.api.test.MavenTestUtils;

import java.io.File;
import java.io.IOException;
import java.io.Writer;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.mock;

public class CheckstyleConfigurationTest {

@Test
public void writeConfigurationToWorkingDir() throws IOException {
Project project = MavenTestUtils.loadProjectFromPom(getClass(), "writeConfigurationToWorkingDir/pom.xml");

CheckstyleProfileExporter exporter = new FakeExporter();
CheckstyleConfiguration configuration = new CheckstyleConfiguration(exporter, null, project);
File xmlFile = configuration.getXMLDefinitionFile();

assertThat(xmlFile.exists(), is(true));
assertThat(FileUtils.readFileToString(xmlFile), is("<conf/>"));
}

@Test
public void findConfigurationToReuse() throws IOException {
Project project = MavenTestUtils.loadProjectFromPom(getClass(), "findConfigurationToReuse/pom.xml");

CheckstyleProfileExporter exporter = mock(CheckstyleProfileExporter.class);
Mockito.doThrow(new RuntimeException()).when(exporter).exportProfile((RulesProfile)anyObject(), (Writer)anyObject());
CheckstyleConfiguration configuration = new CheckstyleConfiguration(exporter, null, project);

File xmlFile = configuration.getXMLDefinitionFile();
assertThat(xmlFile.exists(), is(true));
assertThat(FileUtils.readFileToString(xmlFile), is("<ondisk/>"));
}

@Test(expected=RuntimeException.class)
public void failIfConfigurationToReuseDoesNotExist() throws IOException {
Project project = MavenTestUtils.loadProjectFromPom(getClass(), "failIfConfigurationToReuseDoesNotExist/pom.xml");

CheckstyleProfileExporter exporter = mock(CheckstyleProfileExporter.class);
Mockito.doThrow(new RuntimeException()).when(exporter).exportProfile((RulesProfile)anyObject(), (Writer)anyObject());
CheckstyleConfiguration configuration = new CheckstyleConfiguration(exporter, null, project);
configuration.getXMLDefinitionFile();
}

public class FakeExporter extends CheckstyleProfileExporter {
@Override
public void exportProfile(RulesProfile profile, Writer writer) {
try {
writer.write("<conf/>");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

}

+ 35
- 0
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstylePluginTest.java View File

@@ -0,0 +1,35 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.junit.Test;

import static org.hamcrest.number.OrderingComparisons.greaterThan;
import static org.junit.Assert.assertThat;

public class CheckstylePluginTest {

@Test
public void getSonarWayProfileDefinition() {
CheckstylePlugin plugin = new CheckstylePlugin();
assertThat(plugin.getExtensions().size(), greaterThan(1));
}

}

+ 142
- 0
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest.java View File

@@ -0,0 +1,142 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
import org.junit.Test;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.test.TestUtils;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.StringWriter;

public class CheckstyleProfileExporterTest {

@Test
public void alwaysSetFileContentsHolderAndSuppressionCommentFilter() throws IOException, SAXException {
RulesProfile profile = RulesProfile.create("sonar way", "java");

StringWriter writer = new StringWriter();
new CheckstyleProfileExporter().exportProfile(profile, writer);

TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/alwaysSetFileContentsHolderAndSuppressionCommentFilter.xml"),
writer.toString());
}
@Test
public void noCheckstyleRulesToExport() throws IOException, SAXException {
RulesProfile profile = RulesProfile.create("sonar way", "java");

// this is a PMD rule
profile.activateRule(Rule.create("pmd", "PmdRule1", "PMD rule one"), null);

StringWriter writer = new StringWriter();
new CheckstyleProfileExporter().exportProfile(profile, writer);

TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/noCheckstyleRulesToExport.xml"),
writer.toString());
}

@Test
public void singleCheckstyleRulesToExport() throws IOException, SAXException {
RulesProfile profile = RulesProfile.create("sonar way", "java");
profile.activateRule(Rule.create("pmd", "PmdRule1", "PMD rule one"), null);
profile.activateRule(
Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck", "Javadoc").setConfigKey("Checker/JavadocPackage"),
RulePriority.MAJOR
);
profile.activateRule(Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck", "Line Length").setConfigKey("Checker/TreeWalker/LineLength"),
RulePriority.CRITICAL);
profile.activateRule(Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.naming.LocalFinalVariableNameCheck", "Local Variable").setConfigKey("Checker/TreeWalker/Checker/TreeWalker/LocalFinalVariableName"),
RulePriority.MINOR);

StringWriter writer = new StringWriter();
new CheckstyleProfileExporter().exportProfile(profile, writer);

TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/singleCheckstyleRulesToExport.xml"),
writer.toString());
}

@Test
public void addTheIdPropertyWhenManyInstancesWithTheSameConfigKey() throws IOException, SAXException {
RulesProfile profile = RulesProfile.create("sonar way", "java");
Rule rule1 = Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck", "Javadoc").setConfigKey("Checker/JavadocPackage");
Rule rule2 = Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345", "Javadoc").setConfigKey("Checker/JavadocPackage");

profile.activateRule(rule1, RulePriority.MAJOR);
profile.activateRule(rule2, RulePriority.CRITICAL);

StringWriter writer = new StringWriter();
new CheckstyleProfileExporter().exportProfile(profile, writer);

TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addTheIdPropertyWhenManyInstancesWithTheSameConfigKey.xml"),
writer.toString());
}

@Test
public void exportParameters() throws IOException, SAXException {
RulesProfile profile = RulesProfile.create("sonar way", "java");
Rule rule = Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck", "Javadoc")
.setConfigKey("Checker/JavadocPackage");
rule.createParameter("format");
rule.createParameter("message"); // not set in the profile and no default value => not exported in checkstyle
rule.createParameter("ignore").setDefaultValue("true");

profile.activateRule(rule, RulePriority.MAJOR)
.setParameter("format", "abcde");

StringWriter writer = new StringWriter();
new CheckstyleProfileExporter().exportProfile(profile, writer);

TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/exportParameters.xml"),
writer.toString());
}


@Test
public void addCustomFilters() throws IOException, SAXException {
Configuration conf = new BaseConfiguration();
conf.addProperty(CheckstyleConstants.FILTERS_KEY,
"<module name=\"SuppressionCommentFilter\">"
+ "<property name=\"offCommentFormat\" value=\"BEGIN GENERATED CODE\"/>"
+ "<property name=\"onCommentFormat\" value=\"END GENERATED CODE\"/>" + "</module>"
+"<module name=\"SuppressWithNearbyCommentFilter\">"
+ "<property name=\"commentFormat\" value=\"CHECKSTYLE IGNORE (\\w+) FOR NEXT (\\d+) LINES\"/>"
+ "<property name=\"checkFormat\" value=\"$1\"/>"
+ "<property name=\"messageFormat\" value=\"$2\"/>"
+ "</module>");

RulesProfile profile = RulesProfile.create("sonar way", "java");
StringWriter writer = new StringWriter();
new CheckstyleProfileExporter(conf).exportProfile(profile, writer);

TestUtils.assertSimilarXml(
TestUtils.getResourceContent("/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addCustomFilters.xml"),
writer.toString());
}
}

+ 41
- 0
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleRuleRepositoryTest.java View File

@@ -0,0 +1,41 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.junit.Test;
import org.sonar.api.platform.ServerFileSystem;
import org.sonar.api.rules.Rule;

import java.util.List;

import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;

public class CheckstyleRuleRepositoryTest {

@Test
public void loadRepositoryFromXml() {
ServerFileSystem fileSystem = mock(ServerFileSystem.class);
CheckstyleRuleRepository repository = new CheckstyleRuleRepository(fileSystem);
List<Rule> rules = repository.createRules();
assertThat(rules.size(), greaterThan(100));
}
}

+ 35
- 0
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleVersionTest.java View File

@@ -0,0 +1,35 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.junit.Test;

import static org.hamcrest.number.OrderingComparisons.greaterThan;
import static org.junit.Assert.assertThat;

public class CheckstyleVersionTest {

@Test
public void getCheckstyleVersion() {
assertThat(CheckstyleVersion.getVersion().length(), greaterThan(1));
}


}

+ 38
- 0
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayProfileTest.java View File

@@ -0,0 +1,38 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.junit.Test;
import org.sonar.api.profiles.ProfileDefinition;
import org.sonar.api.profiles.ProfilePrototype;

import static org.hamcrest.number.OrderingComparisons.greaterThan;
import static org.junit.Assert.assertThat;

public class SonarWayProfileTest {

@Test
public void create() {
ProfileDefinition sonarWay = new SonarWayProfile();
ProfilePrototype prototype = sonarWay.createPrototype();
assertThat(prototype.getRulesByRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).size(), greaterThan(1));
}

}

+ 36
- 0
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SonarWayWithFindbugsProfileTest.java View File

@@ -0,0 +1,36 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.junit.Test;
import org.sonar.api.profiles.ProfilePrototype;

import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;

public class SonarWayWithFindbugsProfileTest {

@Test
public void sameAsSonarWay() {
ProfilePrototype withFindbugs = new SonarWayWithFindbugsProfile().createPrototype();
ProfilePrototype withoutFindbugs = new SonarWayProfile().createPrototype();
assertThat(withFindbugs.getRules().size(), is(withoutFindbugs.getRules().size()));
}
}

+ 40
- 0
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/SunConventionsProfileTest.java View File

@@ -0,0 +1,40 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.checkstyle;

import org.junit.Test;
import org.sonar.api.profiles.ProfileDefinition;
import org.sonar.api.profiles.ProfilePrototype;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.number.OrderingComparisons.greaterThan;
import static org.junit.Assert.assertThat;

public class SunConventionsProfileTest {
@Test
public void create() {
ProfileDefinition sunConventionsProfile = new SunConventionsProfile();
ProfilePrototype prototype = sunConventionsProfile.createPrototype();
assertThat(prototype.getRulesByRepositoryKey(CheckstyleConstants.REPOSITORY_KEY).size(), greaterThan(1));
assertThat(
prototype.getRule(CheckstyleConstants.REPOSITORY_KEY, "com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck").getParameter("lineSeparator"),
is("system"));
}
}

+ 24
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/failIfConfigurationToReuseDoesNotExist/pom.xml View File

@@ -0,0 +1,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fake.group</groupId>
<artifactId>fake.artifactId</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>

<properties>
<sonar.reuseExistingRulesConfiguration>true</sonar.reuseExistingRulesConfiguration>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>does/not/exist/checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 1
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/checkstyle.xml View File

@@ -0,0 +1 @@
<ondisk/>

+ 25
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/pom.xml View File

@@ -0,0 +1,25 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fake.group</groupId>
<artifactId>fake.artifactId</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>

<properties>
<sonar.reuseExistingRulesConfiguration>true</sonar.reuseExistingRulesConfiguration>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<!-- ugly workaround for unit tests : ${basedir} is not replaced by the real path -->
<configLocation>src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/findConfigurationToReuse/checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 8
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest/writeConfigurationToWorkingDir/pom.xml View File

@@ -0,0 +1,8 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fake.group</groupId>
<artifactId>fake.artifactId</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
</project>

+ 17
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addCustomFilters.xml View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Sonar -->
<module name="Checker">
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="BEGIN GENERATED CODE"/>
<property name="onCommentFormat" value="END GENERATED CODE"/>
</module>
<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat" value="CHECKSTYLE IGNORE (\w+) FOR NEXT (\d+) LINES"/>
<property name="checkFormat" value="$1"/>
<property name="messageFormat" value="$2"/>
</module>

<module name="TreeWalker">
<module name="FileContentsHolder"/>
</module>
</module>

+ 16
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/addTheIdPropertyWhenManyInstancesWithTheSameConfigKey.xml View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Sonar -->
<module name="Checker">
<module name="SuppressionCommentFilter"/>
<module name="JavadocPackage">
<property name="id" value="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck" />
<property name="severity" value="warning" />
</module>
<module name="JavadocPackage">
<property name="id" value="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck_12345" />
<property name="severity" value="error" />
</module>
<module name="TreeWalker">
<module name="FileContentsHolder"/>
</module>
</module>

+ 8
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/alwaysSetFileContentsHolderAndSuppressionCommentFilter.xml View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Sonar -->
<module name="Checker">
<module name="SuppressionCommentFilter"/>
<module name="TreeWalker">
<module name="FileContentsHolder"/>
</module>
</module>

+ 13
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/exportParameters.xml View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Sonar -->
<module name="Checker">
<module name="SuppressionCommentFilter"/>
<module name="JavadocPackage">
<property name="severity" value="warning" />
<property name="format" value="abcde" />
<property name="ignore" value="true" />
</module>
<module name="TreeWalker">
<module name="FileContentsHolder"/>
</module>
</module>

+ 8
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/noCheckstyleRulesToExport.xml View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Sonar -->
<module name="Checker">
<module name="SuppressionCommentFilter"/>
<module name="TreeWalker">
<module name="FileContentsHolder"/>
</module>
</module>

+ 17
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/CheckstyleProfileExporterTest/singleCheckstyleRulesToExport.xml View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Sonar -->
<module name="Checker">
<module name="SuppressionCommentFilter"/>
<module name="JavadocPackage">
<property name="severity" value="warning"/>
</module>
<module name="TreeWalker">
<module name="FileContentsHolder"/>
<module name="LocalFinalVariableName">
<property name="severity" value="info"/>
</module>
<module name="LineLength">
<property name="severity" value="error"/>
</module>
</module>
</module>

+ 15
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/checkstyle-class-without-package.xml View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="4.1">
<file name="\test\src\main\java\ClassWithoutPackage.java">
<error line="2" column="1" severity="warning" message="Line contains a tab character." source="com.puppycrawl.tools.checkstyle.checks.whitespace.TabCharacterCheck"/>
<error line="3" column="1" severity="warning" message="Line contains a tab character." source="com.puppycrawl.tools.checkstyle.checks.whitespace.TabCharacterCheck"/>
<error line="4" column="1" severity="warning" message="Line contains a tab character." source="com.puppycrawl.tools.checkstyle.checks.whitespace.TabCharacterCheck"/>
<error line="4" column="26" severity="error" message="Assignment of parameter &apos;i&apos; is not allowed."
source="com.puppycrawl.tools.checkstyle.checks.coding.ParameterAssignmentCheck"/>
<error line="5" column="1" severity="warning" message="Line contains a tab character." source="com.puppycrawl.tools.checkstyle.checks.whitespace.TabCharacterCheck"/>
<error line="6" column="1" severity="warning" message="Line contains a tab character." source="com.puppycrawl.tools.checkstyle.checks.whitespace.TabCharacterCheck"/>
<error line="7" column="1" severity="warning" message="Line contains a tab character." source="com.puppycrawl.tools.checkstyle.checks.whitespace.TabCharacterCheck"/>
<error line="8" column="1" severity="warning" message="Line contains a tab character." source="com.puppycrawl.tools.checkstyle.checks.whitespace.TabCharacterCheck"/>
<error line="9" column="1" severity="warning" message="Line contains a tab character." source="com.puppycrawl.tools.checkstyle.checks.whitespace.TabCharacterCheck"/>
</file>
</checkstyle>

+ 34
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/checkstyle-result.xml View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="4.1">
<file name="\test\src\main\java\ch\hortis\sonar\mvn\mc\package.html">
<error line="0" severity="warning" message="Missing package documentation file." source="com.puppycrawl.tools.checkstyle.checks.javadoc.PackageHtmlCheck"/>
</file>
<file name="\test\src\main\java\ch\hortis\sonar\mvn\mc\MetricsCollectorRegistry.java">
<error line="0" severity="error" message="File does not end with a newline." source="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>
</file>
<file name="\test\src\main\java\ch\hortis\sonar\mvn\SetupMojo.java">
<error line="0" severity="error" message="File does not end with a newline." source="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>
</file>
<file name="\test\src\main\java\ch\hortis\sonar\mvn\BaseSonarMojo.java">
<error line="6" severity="warning" message="Missing a Javadoc comment." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck"/>
<error line="7" column="10" severity="error" message="Line has trailing spaces." source="com.puppycrawl.tools.checkstyle.checks.GenericIllegalRegexpCheck"/>
<error line="8" column="5" severity="error" message="Missing a Javadoc comment." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocVariableCheck"/>
<error line="9" severity="error" message="Line has trailing spaces." source="com.puppycrawl.tools.checkstyle.checks.GenericIllegalRegexpCheck"/>
<error line="10" severity="info" message="First sentence should end with a period." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck"/>
<error line="15" severity="error" message="Line has trailing spaces." source="com.puppycrawl.tools.checkstyle.checks.GenericIllegalRegexpCheck"/>
<error line="16" severity="info" message="First sentence should end with a period." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck"/>
<error line="21" severity="info" message="Line has trailing spaces." source="com.puppycrawl.tools.checkstyle.checks.GenericIllegalRegexpCheck"/>
<error line="22" severity="error" message="First sentence should end with a period." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck"/>
<error line="27" severity="error" message="Line has trailing spaces." source="com.puppycrawl.tools.checkstyle.checks.GenericIllegalRegexpCheck"/>
<error line="28" severity="error" message="First sentence should end with a period." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck"/>
<error line="33" severity="error" message="Line has trailing spaces." source="com.puppycrawl.tools.checkstyle.checks.GenericIllegalRegexpCheck"/>
<error line="34" column="5" severity="error" message="Method &apos;getLog&apos; is not designed for extension - needs to be abstract, final or empty." source="com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck"/>
<error line="34" column="5" severity="error" message="Missing a Javadoc comment." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck"/>
<error line="37" severity="error" message="Line has trailing spaces." source="com.puppycrawl.tools.checkstyle.checks.GenericIllegalRegexpCheck"/>
<error line="38" column="5" severity="error" message="Method &apos;setLog&apos; is not designed for extension - needs to be abstract, final or empty." source="com.puppycrawl.tools.checkstyle.checks.design.DesignForExtensionCheck"/>
<error line="38" column="5" severity="error" message="Missing a Javadoc comment." source="com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck"/>
<error line="38" column="24" severity="error" message="&apos;(&apos; is followed by whitespace." source="com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck"/>
<error line="38" column="25" severity="error" message="Parameter log should be final." source="com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck"/>
<error line="38" column="29" severity="error" message="&apos;log&apos; hides a field." source="com.puppycrawl.tools.checkstyle.checks.coding.HiddenFieldCheck"/>
</file>
</checkstyle>

+ 3
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/test_header.xml View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Sonar Checkstyle rules generated configuration -->
<module/>

+ 14
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/test_module_tree.xml View File

@@ -0,0 +1,14 @@
<module name="Checker">
<module name="Translation">
<property name="severity" value="error"/>
<property name="fileExtensions" value="properties"/>
</module>
<module name="TreeWalker">
<module name="AnonInnerLength">
<property name="max" value="15"/>
</module>
<module name="TypeName">
<property name="severity" value="warning"/>
</module>
</module>
</module>

+ 7
- 0
plugins/sonar-checkstyle-plugin/src/test/resources/org/sonar/plugins/checkstyle/test_xml_with_param_value_id.xml View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Sonar Checkstyle rules generated configuration -->
<module name="Checker">
<module name="Test">
<property name="id" value="[QP-COD-0000]"/>
</module>
</module>

+ 57
- 0
plugins/sonar-clover-plugin/pom.xml View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar</artifactId>
<version>2.3-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<groupId>org.codehaus.sonar.plugins</groupId>
<artifactId>sonar-clover-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<name>Sonar :: Plugins :: Clover</name>
<description>Get code coverage with Atlassian Clover</description>

<build>
<testResources>
<testResource>
<directory>${basedir}/src/main/resources</directory>
</testResource>
<testResource>
<directory>${basedir}/src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<pluginKey>clover</pluginKey>
<pluginName>Clover</pluginName>
<pluginClass>org.sonar.plugins.clover.CloverPlugin</pluginClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-testing-harness</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

+ 31
- 0
plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverConstants.java View File

@@ -0,0 +1,31 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.clover;

public interface CloverConstants {

String LICENSE_PROPERTY = "sonar.clover.license.secured";
String VERSION_PROPERTY = "sonar.clover.version";
String DEFAULT_VERSION = "2.6.3";
String REPORT_PATH_PROPERTY = "sonar.clover.reportPath";

String MAVEN_GROUP_ID = "com.atlassian.maven.plugins";
String MAVEN_ARTIFACT_ID = "maven-clover2-plugin";
}

+ 130
- 0
plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverMavenPluginHandler.java View File

@@ -0,0 +1,130 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.clover;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.maven.MavenPlugin;
import org.sonar.api.batch.maven.MavenPluginHandler;
import org.sonar.api.batch.maven.MavenSurefireUtils;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.ProjectUtils;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

public class CloverMavenPluginHandler implements MavenPluginHandler {

private Configuration conf;

public CloverMavenPluginHandler(Configuration conf) {
this.conf = conf;
}

public String getGroupId() {
return CloverConstants.MAVEN_GROUP_ID;
}

public String getArtifactId() {
return CloverConstants.MAVEN_ARTIFACT_ID;
}

public String getVersion() {
return conf.getString(CloverConstants.VERSION_PROPERTY, CloverConstants.DEFAULT_VERSION);
}

public boolean isFixedVersion() {
return false;
}

public String[] getGoals() {
return new String[]{"instrument", "clover"};
}

public void configure(Project project, MavenPlugin cloverPlugin) {
configureParameters(project, cloverPlugin);
configureLicense(project, cloverPlugin);
configureSurefire(project, cloverPlugin);
}

private void configureSurefire(Project project, MavenPlugin cloverPlugin) {
MavenSurefireUtils.configure(project);
boolean skipCloverLaunch = project.getConfiguration().getBoolean("maven.clover.skip", false);
if (!skipCloverLaunch) {
String skipInPomConfig = cloverPlugin.getParameter("skip");
skipCloverLaunch = StringUtils.isNotBlank(skipInPomConfig) ? Boolean.parseBoolean(skipInPomConfig) : false;
}
if (!project.getConfiguration().containsKey(CoreProperties.SUREFIRE_REPORTS_PATH_PROPERTY) && !skipCloverLaunch) {
project.getConfiguration().setProperty(CoreProperties.SUREFIRE_REPORTS_PATH_PROPERTY, new File(project.getFileSystem().getBuildDir(), "clover/surefire-reports").getAbsolutePath());
}
}

protected void configureParameters(Project project, MavenPlugin cloverPlugin) {
cloverPlugin.setParameter("generateXml", "true");
String javaVersion = ProjectUtils.getJavaVersion(project);
if (javaVersion != null) {
cloverPlugin.setParameter("jdk", javaVersion);
}
if (project.getExclusionPatterns() != null) {
for (String pattern : project.getExclusionPatterns()) {
cloverPlugin.addParameter("excludes/exclude", pattern);
}
}
}

protected void configureLicense(Project project, MavenPlugin cloverPlugin) {
if (!hasLicense(cloverPlugin) && getGlobalLicense(project) != null) {
String license = getGlobalLicense(project);
File licenseFile = writeLicenseToDisk(project, license);
cloverPlugin.setParameter("licenseLocation", licenseFile.getAbsolutePath());
}
}

private boolean hasLicense(MavenPlugin cloverPlugin) {
return StringUtils.isNotBlank(cloverPlugin.getParameter("license")) || StringUtils.isNotBlank(cloverPlugin.getParameter("licenseLocation"));
}

private File writeLicenseToDisk(Project project, String license) {
try {
File file = new File(project.getFileSystem().getSonarWorkingDirectory(), "clover.license");
FileUtils.writeStringToFile(file, license);
return file;
} catch (IOException e) {
throw new RuntimeException("can not write the clover license", e);
}
}

private String getGlobalLicense(Project project) {
Object value = project.getProperty(CloverConstants.LICENSE_PROPERTY);
if (value != null) {
if (value instanceof String) {
return (String) value;

} else if (value instanceof Collection) {
return StringUtils.join(((Collection) value), "");
}
}
return null;
}

}

+ 63
- 0
plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverPlugin.java View File

@@ -0,0 +1,63 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.clover;

import org.sonar.api.Plugin;
import org.sonar.api.Properties;
import org.sonar.api.Property;

import java.util.Arrays;
import java.util.List;

@Properties({
@Property(
key = CloverConstants.LICENSE_PROPERTY,
name = "License",
description = "You can obtain a free 30 day evaluation license or purchase a commercial license at <a href='http://my.atlassian.com'>http://my.atlassian.com</a>.",
project = true, global = true),
@Property(
key = CloverConstants.REPORT_PATH_PROPERTY,
name = "Report path",
description = "Absolute or relative path to XML report file.",
project = true, global = true),
@Property(
key = CloverConstants.VERSION_PROPERTY,
name = "Clover version",
description = "Override the Clover version to use. Default value is read from pom, else " + CloverConstants.DEFAULT_VERSION,
project = true, global = true)
})
public class CloverPlugin implements Plugin {

public String getKey() {
return "clover";
}

public String getName() {
return "Clover";
}

public String getDescription() {
return "Clover measures code coverage generated by system tests, functional tests or unit tests, allowing to improve test quality and find bugs sooner. You can find more by going to the <a href='http://www.atlassian.com/software/clover'>Atlassian Clover web site</a>.";
}

public List getExtensions() {
return Arrays.asList(CloverMavenPluginHandler.class, CloverSensor.class);
}
}

+ 102
- 0
plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/CloverSensor.java View File

@@ -0,0 +1,102 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.clover;

import org.slf4j.LoggerFactory;
import org.sonar.api.Plugins;
import org.sonar.api.batch.AbstractCoverageExtension;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.maven.DependsUponMavenPlugin;
import org.sonar.api.batch.maven.MavenPlugin;
import org.sonar.api.batch.maven.MavenPluginHandler;
import org.sonar.api.resources.Project;

import java.io.File;

public class CloverSensor extends AbstractCoverageExtension implements Sensor, DependsUponMavenPlugin {

private CloverMavenPluginHandler handler;

public CloverSensor(Plugins plugins, CloverMavenPluginHandler handler) {
super(plugins);
this.handler = handler;
}

public MavenPluginHandler getMavenPluginHandler(Project project) {
if (project.getAnalysisType().equals(Project.AnalysisType.DYNAMIC)) {
return handler;
}
return null;
}

public void analyse(Project project, SensorContext context) {
File report = getReport(project);
if (reportExists(report)) {
new XmlReportParser(context).collect(report);
} else {
LoggerFactory.getLogger(getClass()).info("Clover XML report not found");
}
}

@Override
public boolean shouldExecuteOnProject(Project project) {
return super.shouldExecuteOnProject(project) &&
project.getFileSystem().hasJavaSourceFiles();
}

protected File getReport(Project pom) {
File report = getReportFromProperty(pom);
if (report == null) {
report = getReportFromPluginConfiguration(pom);
}
if (report == null) {
report = getReportFromDefaultPath(pom);
}
return report;
}

private File getReportFromProperty(Project pom) {
String path = (String) pom.getProperty(CloverConstants.REPORT_PATH_PROPERTY);
if (path != null) {
return pom.getFileSystem().resolvePath(path);
}
return null;
}

private File getReportFromPluginConfiguration(Project pom) {
MavenPlugin plugin = MavenPlugin.getPlugin(pom.getPom(), CloverConstants.MAVEN_GROUP_ID, CloverConstants.MAVEN_ARTIFACT_ID);
if (plugin != null) {
String path = plugin.getParameter("outputDirectory");
if (path != null) {
return new File(pom.getFileSystem().resolvePath(path), "clover.xml");
}
}
return null;
}

private File getReportFromDefaultPath(Project pom) {
return new File(pom.getFileSystem().getReportOutputDir(), "clover/clover.xml");
}

private boolean reportExists(File report) {
return report != null && report.exists() && report.isFile();
}
}

+ 207
- 0
plugins/sonar-clover-plugin/src/main/java/org/sonar/plugins/clover/XmlReportParser.java View File

@@ -0,0 +1,207 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.clover;
import org.apache.commons.lang.StringUtils;
import org.codehaus.staxmate.in.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.PropertiesBuilder;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.ParsingUtils;
import static org.sonar.api.utils.ParsingUtils.scaleValue;
import org.sonar.api.utils.StaxParser;
import org.sonar.api.utils.XmlParserException;
import java.io.File;
import java.text.ParseException;
import javax.xml.stream.XMLStreamException;
public class XmlReportParser {
private static final Logger LOG = LoggerFactory.getLogger(XmlReportParser.class);
private SensorContext context;
final PropertiesBuilder<String, Integer> lineHitsBuilder = new PropertiesBuilder<String, Integer>(CoreMetrics.COVERAGE_LINE_HITS_DATA);
final PropertiesBuilder<String, String> branchHitsBuilder = new PropertiesBuilder<String, String>(CoreMetrics.BRANCH_COVERAGE_HITS_DATA);
public XmlReportParser(SensorContext context) {
this.context = context;
}
private boolean reportExists(File report) {
return report != null && report.exists() && report.isFile();
}
protected void collect(File xmlFile) {
try {
if (reportExists(xmlFile)) {
LOG.info("Parsing " + xmlFile.getCanonicalPath());
StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
try {
collectProjectMeasures(rootCursor.advance());
} catch (ParseException e) {
throw new XMLStreamException(e);
}
}
});
parser.parse(xmlFile);
}
} catch (Exception e) {
throw new XmlParserException(e);
}
}
private void collectProjectMeasures(SMInputCursor rootCursor) throws ParseException, XMLStreamException {
SMInputCursor projectCursor = rootCursor.descendantElementCursor("project");
SMInputCursor projectChildrenCursor = projectCursor.advance().childElementCursor();
projectChildrenCursor.setFilter(new SimpleFilter(SMEvent.START_ELEMENT));
SMInputCursor metricsCursor = projectChildrenCursor.advance();
analyseMetricsNode(null, metricsCursor);
collectPackageMeasures(projectChildrenCursor);
}
private void analyseMetricsNode(Resource resource, SMInputCursor metricsCursor) throws ParseException, XMLStreamException {
int elements = (int) ParsingUtils.parseNumber(metricsCursor.getAttrValue("elements"));
if (elements == 0) {
return;
}
int statements = (int) ParsingUtils.parseNumber(metricsCursor.getAttrValue("statements"));
int methods = (int) ParsingUtils.parseNumber(metricsCursor.getAttrValue("methods"));
int conditionals = (int) ParsingUtils.parseNumber(metricsCursor.getAttrValue("conditionals"));
int coveredElements = (int) ParsingUtils.parseNumber(metricsCursor.getAttrValue("coveredelements"));
int coveredStatements = (int) ParsingUtils.parseNumber(metricsCursor.getAttrValue("coveredstatements"));
int coveredMethods = (int) ParsingUtils.parseNumber(metricsCursor.getAttrValue("coveredmethods"));
int coveredConditionals = (int) ParsingUtils.parseNumber(metricsCursor.getAttrValue("coveredconditionals"));
context.saveMeasure(resource, CoreMetrics.COVERAGE, calculateCoverage(coveredElements, elements));
context.saveMeasure(resource, CoreMetrics.LINE_COVERAGE, calculateCoverage(coveredMethods + coveredStatements, methods + statements));
context.saveMeasure(resource, CoreMetrics.LINES_TO_COVER, (double) (statements + methods));
context.saveMeasure(resource, CoreMetrics.UNCOVERED_LINES, (double) (statements + methods - coveredStatements - coveredMethods));
if (conditionals > 0) {
context.saveMeasure(resource, CoreMetrics.BRANCH_COVERAGE, calculateCoverage(coveredConditionals, conditionals));
context.saveMeasure(resource, CoreMetrics.CONDITIONS_TO_COVER, (double) (conditionals));
context.saveMeasure(resource, CoreMetrics.UNCOVERED_CONDITIONS, (double) (conditionals - coveredConditionals));
}
}
private double calculateCoverage(int coveredElements, int elements) {
if (elements > 0) {
return scaleValue(100.0 * ((double) coveredElements / (double) elements));
}
return 0.0;
}
private void collectPackageMeasures(SMInputCursor packCursor) throws ParseException, XMLStreamException {
while (packCursor.getNext() != null) {
JavaPackage pack = new JavaPackage(packCursor.getAttrValue("name"));
SMInputCursor packChildrenCursor = packCursor.descendantElementCursor();
packChildrenCursor.setFilter(new SimpleFilter(SMEvent.START_ELEMENT));
SMInputCursor metricsCursor = packChildrenCursor.advance();
analyseMetricsNode(pack, metricsCursor);
collectFileMeasures(packChildrenCursor, pack);
}
}
private void collectFileMeasures(SMInputCursor fileCursor, JavaPackage pack) throws ParseException, XMLStreamException {
fileCursor.setFilter(SMFilterFactory.getElementOnlyFilter("file"));
while (fileCursor.getNext() != null) {
if (fileCursor.asEvent().isStartElement()) {
String classKey = extractClassName(fileCursor.getAttrValue("name"));
if (classKey != null) {
SMInputCursor fileChildrenCursor = fileCursor.childCursor(new SimpleFilter(SMEvent.START_ELEMENT));
// cursor should be on the metrics element
if (canBeIncludedInFileMetrics(fileChildrenCursor)) {
JavaFile resource = new JavaFile(pack.getKey(), classKey, false);
analyseMetricsNode(resource, fileChildrenCursor);
// cursor should be now on the line cursor
saveHitsData(resource, fileChildrenCursor);
}
}
}
}
}
private void saveHitsData(Resource resource, SMInputCursor lineCursor) throws ParseException, XMLStreamException {
lineHitsBuilder.clear();
branchHitsBuilder.clear();
boolean hasBranches = false;
while (lineCursor.getNext() != null) {
// skip class elements on format 2_3_2
if (lineCursor.getLocalName().equals("class")) {
continue;
}
final String lineId = lineCursor.getAttrValue("num");
int hits;
String count = lineCursor.getAttrValue("count");
if (StringUtils.isBlank(count)) {
int trueCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("truecount"));
int falseCount = (int) ParsingUtils.parseNumber(lineCursor.getAttrValue("falsecount"));
hits = trueCount + falseCount;
String branchHits;
if (trueCount > 0 && falseCount > 0) {
branchHits = "100%";
} else if (trueCount == 0 && falseCount == 0) {
branchHits = "0%";
} else {
branchHits = "50%";
}
branchHitsBuilder.add(lineId, branchHits);
hasBranches = true;
} else {
hits = (int) ParsingUtils.parseNumber(count);
}
lineHitsBuilder.add(lineId, hits);
}
context.saveMeasure(resource, lineHitsBuilder.build());
if (hasBranches) {
context.saveMeasure(resource, branchHitsBuilder.build());
}
}
private boolean canBeIncludedInFileMetrics(SMInputCursor metricsCursor) throws ParseException, XMLStreamException {
// skip class elements on 1.x xml format
while (metricsCursor.getNext() != null && metricsCursor.getLocalName().equals("class")) {
}
return ParsingUtils.parseNumber(metricsCursor.getAttrValue("elements")) > 0;
}
protected String extractClassName(String filename) {
if (filename != null) {
filename = StringUtils.replaceChars(filename, '\\', '/');
filename = StringUtils.substringBeforeLast(filename, ".java");
if (filename.indexOf('/') >= 0) {
filename = StringUtils.substringAfterLast(filename, "/");
}
}
return filename;
}
}

+ 76
- 0
plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverMavenPluginHandlerTest.java View File

@@ -0,0 +1,76 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.clover;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.maven.MavenPlugin;
import org.sonar.api.resources.Project;
import org.sonar.api.test.MavenTestUtils;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class CloverMavenPluginHandlerTest {

private CloverMavenPluginHandler handler;
private Project project;
private MavenPlugin plugin;

@Before
public void init() {
handler = new CloverMavenPluginHandler(new PropertiesConfiguration());
}

private void configurePluginHandler(String pom) {
project = MavenTestUtils.loadProjectFromPom(getClass(), pom);
plugin = MavenPlugin.getPlugin(project.getPom(), handler.getGroupId(), handler.getArtifactId());
handler.configure(project, plugin);
}

@Test
public void overrideConfiguration() throws Exception {
configurePluginHandler("overrideConfiguration.xml");

assertThat(plugin.getParameter("generateXml"), is("true"));
assertThat(plugin.getParameter("foo"), is("bar"));
String configuredReportPath = project.getConfiguration().getString(CoreProperties.SUREFIRE_REPORTS_PATH_PROPERTY);
assertThat(configuredReportPath, notNullValue());
configuredReportPath = configuredReportPath.replace('\\', '/');
assertThat(configuredReportPath, endsWith("clover/surefire-reports"));
}

@Test
public void shouldSkipCloverWithPomConfig() throws Exception {
configurePluginHandler("shouldSkipCloverWithPomConfig.xml");

assertThat(project.getConfiguration().getString(CoreProperties.SUREFIRE_REPORTS_PATH_PROPERTY), nullValue());
}

@Test
public void shouldSkipCloverWithPomProperty() throws Exception {
configurePluginHandler("shouldSkipCloverWithPomProperty.xml");

assertThat(project.getConfiguration().getString(CoreProperties.SUREFIRE_REPORTS_PATH_PROPERTY), nullValue());
}

}

+ 33
- 0
plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverPluginTest.java View File

@@ -0,0 +1,33 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.clover;

import org.junit.Test;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class CloverPluginTest {

@Test
public void someExtensions() {
assertThat(new CloverPlugin().getExtensions().size(), is(2));
}
}

+ 54
- 0
plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/CloverSensorTest.java View File

@@ -0,0 +1,54 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.clover;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
import org.sonar.api.resources.Project;

import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class CloverSensorTest {

@Test
public void doNotExecuteMavenPluginIfReuseReports() {
Project project = mock(Project.class);
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.REUSE_REPORTS);
assertThat(new CloverSensor(null, new CloverMavenPluginHandler(new PropertiesConfiguration())).getMavenPluginHandler(project), nullValue());
}

@Test
public void doNotExecuteMavenPluginIfStaticAnalysis() {
Project project = mock(Project.class);
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
assertThat(new CloverSensor(null, new CloverMavenPluginHandler(new PropertiesConfiguration())).getMavenPluginHandler(project), nullValue());
}

@Test
public void executeMavenPluginIfDynamicAnalysis() {
Project project = mock(Project.class);
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.DYNAMIC);
assertThat(new CloverSensor(null, new CloverMavenPluginHandler(new PropertiesConfiguration())).getMavenPluginHandler(project), not(nullValue()));
}
}

+ 150
- 0
plugins/sonar-clover-plugin/src/test/java/org/sonar/plugins/clover/XmlReportParserTest.java View File

@@ -0,0 +1,150 @@
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* 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.clover;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Resource;
import org.sonar.api.test.IsMeasure;
import org.sonar.test.TestUtils;
import java.io.File;
import java.net.URISyntaxException;
import java.text.ParseException;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
public class XmlReportParserTest {
private XmlReportParser reportParser;
private SensorContext context;
private File xmlFile;
@Before
public void before() throws URISyntaxException {
xmlFile = TestUtils.getResource(getClass(), "clover.xml");
context = mock(SensorContext.class);
reportParser = new XmlReportParser(context);
}
@Test
public void collectProjectMeasures() throws Exception {
reportParser.collect(xmlFile);
verify(context).saveMeasure(null, CoreMetrics.COVERAGE, 5.0); // coveredelements / elements
verify(context).saveMeasure(null, CoreMetrics.LINE_COVERAGE, 6.63); // covered methods + covered statements / methods + statements
verify(context).saveMeasure(null, CoreMetrics.LINES_TO_COVER, 196.0);
verify(context).saveMeasure(null, CoreMetrics.UNCOVERED_LINES, 183.0); // covered methods + covered statements
verify(context).saveMeasure(null, CoreMetrics.BRANCH_COVERAGE, 0.0); // covered conditionals / conditionals
verify(context).saveMeasure(null, CoreMetrics.CONDITIONS_TO_COVER, 64.0); // covered_conditionals
verify(context).saveMeasure(null, CoreMetrics.UNCOVERED_CONDITIONS, 64.0);
}
@Test
public void collectPackageMeasures() throws ParseException {
reportParser.collect(xmlFile);
final JavaPackage pac = new JavaPackage("org.sonar.samples");
verify(context).saveMeasure(pac, CoreMetrics.COVERAGE, 28.89);
// lines
verify(context).saveMeasure(pac, CoreMetrics.LINE_COVERAGE, 28.89);
verify(context).saveMeasure(pac, CoreMetrics.LINES_TO_COVER, 45.0);
verify(context).saveMeasure(pac, CoreMetrics.UNCOVERED_LINES, 32.0);
// no conditions
verify(context, never()).saveMeasure(eq(pac), eq(CoreMetrics.BRANCH_COVERAGE), anyDouble());
verify(context, never()).saveMeasure(eq(pac), eq(CoreMetrics.CONDITIONS_TO_COVER), anyDouble());
verify(context, never()).saveMeasure(eq(pac), eq(CoreMetrics.UNCOVERED_CONDITIONS), anyDouble());
}
@Test
public void parseClaver232Format() throws ParseException, URISyntaxException {
reportParser.collect(TestUtils.getResource(getClass(), "clover_2_3_2.xml"));
verify(context).saveMeasure(new JavaPackage("org.sonar.squid.sensors"), CoreMetrics.COVERAGE, 94.87);
}
// @Test
// public void doNotSaveInnerClassMeasures() throws ParseException, URISyntaxException {
// collector.collect(xmlFile);
//
// verify(context, never()).saveMeasure(
// eq(new JavaFile("ch.hortis.sonar.model.MetricMetaInf.Classes")), eq(CoreMetrics.COVERAGE), anyDouble());
// verify(context).saveMeasure(
// eq(new JavaFile("ch.hortis.sonar.model.MetricMetaInf")), eq(CoreMetrics.COVERAGE), anyDouble());
// }
@Test
public void collectFileMeasures() throws Exception {
reportParser.collect(xmlFile);
final JavaFile file = new JavaFile("org.sonar.samples.ClassUnderTest");
verify(context).saveMeasure(file, CoreMetrics.COVERAGE, 100.0);
verify(context).saveMeasure(file, CoreMetrics.LINE_COVERAGE, 100.0);
verify(context).saveMeasure(file, CoreMetrics.LINES_TO_COVER, 5.0);
verify(context).saveMeasure(file, CoreMetrics.UNCOVERED_LINES, 0.0);
// no conditions
verify(context, never()).saveMeasure(eq(file), eq(CoreMetrics.BRANCH_COVERAGE), anyDouble());
verify(context, never()).saveMeasure(eq(file), eq(CoreMetrics.CONDITIONS_TO_COVER), anyDouble());
verify(context, never()).saveMeasure(eq(file), eq(CoreMetrics.UNCOVERED_CONDITIONS), anyDouble());
}
@Test
public void collectFileHitsData() throws Exception {
reportParser.collect(xmlFile);
verify(context).saveMeasure(eq(new JavaFile("org.sonar.samples.ClassUnderTest")), argThat(new IsMeasure(CoreMetrics.COVERAGE_LINE_HITS_DATA, "4=1;5=1;6=1;8=1;9=1")));
}
@Test
public void clover1FileNameContainsPath() {
XmlReportParser reportParser = new XmlReportParser(context);
assertEquals("SampleClass", reportParser.extractClassName("C:\\src\\main\\java\\org\\sonar\\samples\\SampleClass.java"));
assertEquals("SampleClass", reportParser.extractClassName("/src/main/java/org/sonar/samples/SampleClass.java"));
}
@Test
public void clover2FileNameDoesNotContainPath() {
XmlReportParser reportParser = new XmlReportParser(context);
assertEquals("SampleClass", reportParser.extractClassName("SampleClass.java"));
}
@Test
public void coverageShouldBeZeroWhenNoElements() throws URISyntaxException {
File xmlFile = TestUtils.getResource(getClass(), "coverageShouldBeZeroWhenNoElements/clover.xml");
context = mock(SensorContext.class);
XmlReportParser reportParser = new XmlReportParser(context);
reportParser.collect(xmlFile);
verify(context, never()).saveMeasure((Resource) anyObject(), eq(CoreMetrics.COVERAGE), anyDouble());
verify(context, never()).saveMeasure((Resource) anyObject(), eq(CoreMetrics.LINE_COVERAGE), anyDouble());
verify(context, never()).saveMeasure((Resource) anyObject(), eq(CoreMetrics.BRANCH_COVERAGE), anyDouble());
}
}

+ 30
- 0
plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/CloverMavenPluginHandlerTest/overrideConfiguration.xml View File

@@ -0,0 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<configuration>
<outputDirectory>/foo</outputDirectory>
<generateHistorical>true</generateHistorical>
<generateXml>false</generateXml>
<generatePdf>true</generatePdf>
<foo>bar</foo>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 30
- 0
plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/CloverMavenPluginHandlerTest/shouldSkipCloverWithPomConfig.xml View File

@@ -0,0 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<configuration>
<outputDirectory>/foo</outputDirectory>
<generateHistorical>true</generateHistorical>
<generateXml>false</generateXml>
<generatePdf>true</generatePdf>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

+ 32
- 0
plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/CloverMavenPluginHandlerTest/shouldSkipCloverWithPomProperty.xml View File

@@ -0,0 +1,32 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<configuration>
<outputDirectory>/foo</outputDirectory>
<generateHistorical>true</generateHistorical>
<generateXml>false</generateXml>
<generatePdf>true</generatePdf>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.clover.skip>true</maven.clover.skip>
</properties>
</project>

+ 458
- 0
plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/XmlReportParserTest/clover.xml View File

@@ -0,0 +1,458 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1253282369681" clover="2.6.0">
<project timestamp="1253282365324" name="Sonar tests - reference 1.0-SNAPSHOT">
<metrics coveredelements="13" packages="5" coveredconditionals="0" ncloc="322" statements="165" loc="528"
complexity="63" files="14" conditionals="64" coveredstatements="6" coveredmethods="7" methods="31"
classes="16" elements="260"/>
<package name="org.sonar.samples.duplicated_lines_with_other_package2">
<metrics coveredelements="0" coveredconditionals="0" ncloc="36" statements="30" loc="60" complexity="2" files="1"
conditionals="0" coveredstatements="0" coveredmethods="0" methods="2" classes="1" elements="32"/>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/duplicated_lines_with_other_package2/DuplicatedLinesWithOtherPackage.java"
name="DuplicatedLinesWithOtherPackage.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" ncloc="36" statements="30"
coveredmethods="0" coveredstatements="0" loc="60" methods="2" classes="1" complexity="2"
elements="32"/>
<class name="DuplicatedLinesWithOtherPackage">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" statements="30" coveredmethods="0"
coveredstatements="0" methods="2" complexity="2" elements="32"/>
</class>
<line num="24" signature="DuplicatedLinesWithOtherPackage()" type="method" complexity="1" count="0"/>
<line num="27" signature="duplicatedMethodWithOtherPackage() : void" type="method" complexity="1" count="0"/>
<line num="28" type="stmt" count="0"/>
<line num="29" type="stmt" count="0"/>
<line num="30" type="stmt" count="0"/>
<line num="31" type="stmt" count="0"/>
<line num="32" type="stmt" count="0"/>
<line num="33" type="stmt" count="0"/>
<line num="34" type="stmt" count="0"/>
<line num="35" type="stmt" count="0"/>
<line num="36" type="stmt" count="0"/>
<line num="37" type="stmt" count="0"/>
<line num="38" type="stmt" count="0"/>
<line num="39" type="stmt" count="0"/>
<line num="40" type="stmt" count="0"/>
<line num="41" type="stmt" count="0"/>
<line num="42" type="stmt" count="0"/>
<line num="43" type="stmt" count="0"/>
<line num="44" type="stmt" count="0"/>
<line num="45" type="stmt" count="0"/>
<line num="46" type="stmt" count="0"/>
<line num="47" type="stmt" count="0"/>
<line num="48" type="stmt" count="0"/>
<line num="49" type="stmt" count="0"/>
<line num="50" type="stmt" count="0"/>
<line num="51" type="stmt" count="0"/>
<line num="52" type="stmt" count="0"/>
<line num="53" type="stmt" count="0"/>
<line num="54" type="stmt" count="0"/>
<line num="55" type="stmt" count="0"/>
<line num="56" type="stmt" count="0"/>
<line num="57" type="stmt" count="0"/>
</file>
</package>
<package name="org.sonar.samples.duplicated_lines_with_other_package1">
<metrics coveredelements="0" coveredconditionals="0" ncloc="36" statements="30" loc="60" complexity="2" files="1"
conditionals="0" coveredstatements="0" coveredmethods="0" methods="2" classes="1" elements="32"/>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/duplicated_lines_with_other_package1/DuplicatedLinesWithOtherPackage.java"
name="DuplicatedLinesWithOtherPackage.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" ncloc="36" statements="30"
coveredmethods="0" coveredstatements="0" loc="60" methods="2" classes="1" complexity="2"
elements="32"/>
<class name="DuplicatedLinesWithOtherPackage">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" statements="30" coveredmethods="0"
coveredstatements="0" methods="2" complexity="2" elements="32"/>
</class>
<line num="24" signature="DuplicatedLinesWithOtherPackage()" type="method" complexity="1" count="0"/>
<line num="27" signature="duplicatedMethodWithOtherPackage() : void" type="method" complexity="1" count="0"/>
<line num="28" type="stmt" count="0"/>
<line num="29" type="stmt" count="0"/>
<line num="30" type="stmt" count="0"/>
<line num="31" type="stmt" count="0"/>
<line num="32" type="stmt" count="0"/>
<line num="33" type="stmt" count="0"/>
<line num="34" type="stmt" count="0"/>
<line num="35" type="stmt" count="0"/>
<line num="36" type="stmt" count="0"/>
<line num="37" type="stmt" count="0"/>
<line num="38" type="stmt" count="0"/>
<line num="39" type="stmt" count="0"/>
<line num="40" type="stmt" count="0"/>
<line num="41" type="stmt" count="0"/>
<line num="42" type="stmt" count="0"/>
<line num="43" type="stmt" count="0"/>
<line num="44" type="stmt" count="0"/>
<line num="45" type="stmt" count="0"/>
<line num="46" type="stmt" count="0"/>
<line num="47" type="stmt" count="0"/>
<line num="48" type="stmt" count="0"/>
<line num="49" type="stmt" count="0"/>
<line num="50" type="stmt" count="0"/>
<line num="51" type="stmt" count="0"/>
<line num="52" type="stmt" count="0"/>
<line num="53" type="stmt" count="0"/>
<line num="54" type="stmt" count="0"/>
<line num="55" type="stmt" count="0"/>
<line num="56" type="stmt" count="0"/>
<line num="57" type="stmt" count="0"/>
</file>
</package>
<package name="org.sonar.samples">
<metrics coveredelements="13" coveredconditionals="0" ncloc="117" statements="25" loc="191" complexity="20"
files="9" conditionals="0" coveredstatements="6" coveredmethods="7" methods="20" classes="11"
elements="45"/>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/ClassUnderTest.java"
name="ClassUnderTest.java">
<metrics coveredelements="5" coveredconditionals="0" conditionals="0" ncloc="10" statements="3"
coveredmethods="2" coveredstatements="3" loc="11" methods="2" classes="1" complexity="2" elements="5"/>
<class name="ClassUnderTest">
<metrics coveredelements="5" coveredconditionals="0" conditionals="0" statements="3" coveredmethods="2"
coveredstatements="3" methods="2" complexity="2" elements="5"/>
</class>
<line num="4" signature="toto() : void" type="method" complexity="1" count="1"/>
<line num="5" type="stmt" count="1"/>
<line num="6" type="stmt" count="1"/>
<line num="8" signature="hello() : String" type="method" complexity="1" count="1"/>
<line num="9" type="stmt" count="1"/>
</file>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/ClassWithComments.java"
name="ClassWithComments.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" ncloc="10" statements="3"
coveredmethods="0" coveredstatements="0" loc="25" methods="2" classes="1" complexity="2" elements="5"/>
<class name="ClassWithComments">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" statements="3" coveredmethods="0"
coveredstatements="0" methods="2" complexity="2" elements="5"/>
</class>
<line num="10" signature="ClassWithComments(int)" type="method" complexity="1" count="0"/>
<line num="12" type="stmt" count="0"/>
<line num="15" signature="myMethod() : String" type="method" complexity="1" count="0"/>
<line num="22" type="stmt" count="0"/>
<line num="23" type="stmt" count="0"/>
</file>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/EmptyClass.java"
name="EmptyClass.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" ncloc="3" statements="0"
coveredmethods="0" coveredstatements="0" loc="4" methods="0" classes="1" complexity="0" elements="0"/>
<class name="EmptyClass">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" statements="0" coveredmethods="0"
coveredstatements="0" methods="0" complexity="0" elements="0"/>
</class>
</file>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/HibernateModel.java"
name="HibernateModel.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" ncloc="18" statements="1"
coveredmethods="0" coveredstatements="0" loc="24" methods="2" classes="1" complexity="2" elements="3"/>
<class name="HibernateModel">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" statements="1" coveredmethods="0"
coveredstatements="0" methods="2" complexity="2" elements="3"/>
</class>
<line num="18" signature="HibernateModel()" type="method" complexity="1" count="0"/>
<line num="21" signature="HibernateModel(String)" type="method" complexity="1" count="0"/>
<line num="22" type="stmt" count="0"/>
</file>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/InnerClass.java"
name="InnerClass.java">
<metrics coveredelements="8" coveredconditionals="0" conditionals="0" ncloc="49" statements="15"
coveredmethods="5" coveredstatements="3" loc="87" methods="13" classes="3" complexity="13"
elements="28"/>
<class name="InnerClass">
<metrics coveredelements="2" coveredconditionals="0" conditionals="0" statements="5" coveredmethods="1"
coveredstatements="1" methods="3" complexity="3" elements="8"/>
</class>
<class name="InnerClass.InnerClassInside">
<metrics coveredelements="3" coveredconditionals="0" conditionals="0" statements="3" coveredmethods="2"
coveredstatements="1" methods="4" complexity="4" elements="7"/>
</class>
<class name="PrivateClass">
<metrics coveredelements="3" coveredconditionals="0" conditionals="0" statements="7" coveredmethods="2"
coveredstatements="1" methods="6" complexity="6" elements="13"/>
</class>
<line num="24" signature="methodOne() : void" type="method" complexity="1" count="0"/>
<line num="25" type="stmt" count="0"/>
<line num="26" type="stmt" count="0"/>
<line num="29" signature="methodTwo() : void" type="method" complexity="1" count="0"/>
<line num="30" type="stmt" count="0"/>
<line num="31" type="stmt" count="0"/>
<line num="34" signature="methodReturnThree() : int" type="method" complexity="1" count="1"/>
<line num="35" type="stmt" count="1"/>
<line num="40" signature="InnerClassInside()" type="method" complexity="1" count="1"/>
<line num="43" signature="innerMethodOne() : void" type="method" complexity="1" count="0"/>
<line num="44" type="stmt" count="0"/>
<line num="47" signature="innerMethodTwo() : void" type="method" complexity="1" count="0"/>
<line num="48" type="stmt" count="0"/>
<line num="51" signature="methodReturnFour() : int" type="method" complexity="1" count="1"/>
<line num="52" type="stmt" count="1"/>
<line num="59" signature="PrivateClass()" type="method" complexity="1" count="1"/>
<line num="63" signature="innerMethodThree() : void" type="method" complexity="1" count="0"/>
<line num="64" type="stmt" count="0"/>
<line num="67" signature="innerMethodFour() : void" type="method" complexity="1" count="0"/>
<line num="68" type="stmt" count="0"/>
<line num="71" signature="innerMethodFive() : void" type="method" complexity="1" count="0"/>
<line num="72" type="stmt" count="0"/>
<line num="73" type="stmt" count="0"/>
<line num="77" signature="innerMethodSix() : void" type="method" complexity="1" count="0"/>
<line num="78" type="stmt" count="0"/>
<line num="79" type="stmt" count="0"/>
<line num="83" signature="methodReturnfive() : int" type="method" complexity="1" count="1"/>
<line num="84" type="stmt" count="1"/>
</file>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/InterfaceWithConstants.java"
name="InterfaceWithConstants.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" ncloc="7" statements="0"
coveredmethods="0" coveredstatements="0" loc="11" methods="0" classes="1" complexity="0" elements="0"/>
<class name="InterfaceWithConstants">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" statements="0" coveredmethods="0"
coveredstatements="0" methods="0" complexity="0" elements="0"/>
</class>
</file>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/PureAbstractClass.java"
name="PureAbstractClass.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" ncloc="4" statements="0"
coveredmethods="0" coveredstatements="0" loc="7" methods="0" classes="1" complexity="0" elements="0"/>
<class name="PureAbstractClass">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" statements="0" coveredmethods="0"
coveredstatements="0" methods="0" complexity="0" elements="0"/>
</class>
</file>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/PureInterface.java"
name="PureInterface.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" ncloc="5" statements="0"
coveredmethods="0" coveredstatements="0" loc="9" methods="0" classes="1" complexity="0" elements="0"/>
<class name="PureInterface">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" statements="0" coveredmethods="0"
coveredstatements="0" methods="0" complexity="0" elements="0"/>
</class>
</file>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/Utf8Characters.java"
name="Utf8Characters.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" ncloc="11" statements="3"
coveredmethods="0" coveredstatements="0" loc="13" methods="1" classes="1" complexity="1" elements="4"/>
<class name="Utf8Characters">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" statements="3" coveredmethods="0"
coveredstatements="0" methods="1" complexity="1" elements="4"/>
</class>
<line num="8" signature="Utf8Characters()" type="method" complexity="1" count="0"/>
<line num="9" type="stmt" count="0"/>
<line num="10" type="stmt" count="0"/>
<line num="11" type="stmt" count="0"/>
</file>
</package>
<package name="org.sonar.samples.duplicated_lines_within_same_class">
<metrics coveredelements="0" coveredconditionals="0" ncloc="65" statements="38" loc="89" complexity="21" files="1"
conditionals="36" coveredstatements="0" coveredmethods="0" methods="3" classes="1" elements="77"/>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/duplicated_lines_within_same_class/DuplicatedLinesInSameClass.java"
name="DuplicatedLinesInSameClass.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="36" ncloc="65" statements="38"
coveredmethods="0" coveredstatements="0" loc="89" methods="3" classes="1" complexity="21"
elements="77"/>
<class name="DuplicatedLinesInSameClass">
<metrics coveredelements="0" coveredconditionals="0" conditionals="36" statements="38" coveredmethods="0"
coveredstatements="0" methods="3" complexity="21" elements="77"/>
</class>
<line num="24" signature="DuplicatedLinesInSameClass()" type="method" complexity="1" count="0"/>
<line num="27" signature="duplicatedMethodInSameClass1() : void" type="method" complexity="10" count="0"/>
<line num="28" type="stmt" count="0"/>
<line num="29" type="stmt" count="0"/>
<line falsecount="0" num="29" type="cond" truecount="0"/>
<line num="30" type="stmt" count="0"/>
<line num="32" type="stmt" count="0"/>
<line falsecount="0" num="32" type="cond" truecount="0"/>
<line num="33" type="stmt" count="0"/>
<line num="35" type="stmt" count="0"/>
<line falsecount="0" num="35" type="cond" truecount="0"/>
<line num="36" type="stmt" count="0"/>
<line num="38" type="stmt" count="0"/>
<line falsecount="0" num="38" type="cond" truecount="0"/>
<line num="39" type="stmt" count="0"/>
<line num="41" type="stmt" count="0"/>
<line falsecount="0" num="41" type="cond" truecount="0"/>
<line num="42" type="stmt" count="0"/>
<line num="44" type="stmt" count="0"/>
<line falsecount="0" num="44" type="cond" truecount="0"/>
<line num="45" type="stmt" count="0"/>
<line num="47" type="stmt" count="0"/>
<line falsecount="0" num="47" type="cond" truecount="0"/>
<line num="48" type="stmt" count="0"/>
<line num="50" type="stmt" count="0"/>
<line falsecount="0" num="50" type="cond" truecount="0"/>
<line num="51" type="stmt" count="0"/>
<line num="53" type="stmt" count="0"/>
<line falsecount="0" num="53" type="cond" truecount="0"/>
<line num="54" type="stmt" count="0"/>
<line num="58" signature="duplicatedMethodInSameClass2() : void" type="method" complexity="10" count="0"/>
<line num="59" type="stmt" count="0"/>
<line num="60" type="stmt" count="0"/>
<line falsecount="0" num="60" type="cond" truecount="0"/>
<line num="61" type="stmt" count="0"/>
<line num="63" type="stmt" count="0"/>
<line falsecount="0" num="63" type="cond" truecount="0"/>
<line num="64" type="stmt" count="0"/>
<line num="66" type="stmt" count="0"/>
<line falsecount="0" num="66" type="cond" truecount="0"/>
<line num="67" type="stmt" count="0"/>
<line num="69" type="stmt" count="0"/>
<line falsecount="0" num="69" type="cond" truecount="0"/>
<line num="70" type="stmt" count="0"/>
<line num="72" type="stmt" count="0"/>
<line falsecount="0" num="72" type="cond" truecount="0"/>
<line num="73" type="stmt" count="0"/>
<line num="75" type="stmt" count="0"/>
<line falsecount="0" num="75" type="cond" truecount="0"/>
<line num="76" type="stmt" count="0"/>
<line num="78" type="stmt" count="0"/>
<line falsecount="0" num="78" type="cond" truecount="0"/>
<line num="79" type="stmt" count="0"/>
<line num="81" type="stmt" count="0"/>
<line falsecount="0" num="81" type="cond" truecount="0"/>
<line num="82" type="stmt" count="0"/>
<line num="84" type="stmt" count="0"/>
<line falsecount="0" num="84" type="cond" truecount="0"/>
<line num="85" type="stmt" count="0"/>
</file>
</package>
<package name="org.sonar.samples.duplicated_lines_within_package">
<metrics coveredelements="0" coveredconditionals="0" ncloc="68" statements="42" loc="128" complexity="18"
files="2" conditionals="28" coveredstatements="0" coveredmethods="0" methods="4" classes="2"
elements="74"/>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/duplicated_lines_within_package/DuplicatedLinesInSamePackage1.java"
name="DuplicatedLinesInSamePackage1.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="14" ncloc="34" statements="21"
coveredmethods="0" coveredstatements="0" loc="63" methods="2" classes="1" complexity="9"
elements="37"/>
<class name="DuplicatedLinesInSamePackage1">
<metrics coveredelements="0" coveredconditionals="0" conditionals="14" statements="21" coveredmethods="0"
coveredstatements="0" methods="2" complexity="9" elements="37"/>
</class>
<line num="24" signature="DuplicatedLinesInSamePackage1()" type="method" complexity="1" count="0"/>
<line num="30" signature="duplicatedMethodInSameClass1() : void" type="method" complexity="8" count="0"/>
<line num="31" type="stmt" count="0"/>
<line num="32" type="stmt" count="0"/>
<line falsecount="0" num="32" type="cond" truecount="0"/>
<line num="33" type="stmt" count="0"/>
<line num="35" type="stmt" count="0"/>
<line num="36" type="stmt" count="0"/>
<line falsecount="0" num="36" type="cond" truecount="0"/>
<line num="37" type="stmt" count="0"/>
<line num="40" type="stmt" count="0"/>
<line num="41" type="stmt" count="0"/>
<line falsecount="0" num="41" type="cond" truecount="0"/>
<line num="42" type="stmt" count="0"/>
<line num="44" type="stmt" count="0"/>
<line num="45" type="stmt" count="0"/>
<line falsecount="0" num="45" type="cond" truecount="0"/>
<line num="46" type="stmt" count="0"/>
<line num="48" type="stmt" count="0"/>
<line num="49" type="stmt" count="0"/>
<line falsecount="0" num="49" type="cond" truecount="0"/>
<line num="50" type="stmt" count="0"/>
<line num="52" type="stmt" count="0"/>
<line num="53" type="stmt" count="0"/>
<line falsecount="0" num="53" type="cond" truecount="0"/>
<line num="54" type="stmt" count="0"/>
<line num="56" type="stmt" count="0"/>
<line num="57" type="stmt" count="0"/>
<line falsecount="0" num="57" type="cond" truecount="0"/>
<line num="58" type="stmt" count="0"/>
</file>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/main/java/org/sonar/samples/duplicated_lines_within_package/DuplicatedLinesInSamePackage2.java"
name="DuplicatedLinesInSamePackage2.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="14" ncloc="34" statements="21"
coveredmethods="0" coveredstatements="0" loc="65" methods="2" classes="1" complexity="9"
elements="37"/>
<class name="DuplicatedLinesInSamePackage2">
<metrics coveredelements="0" coveredconditionals="0" conditionals="14" statements="21" coveredmethods="0"
coveredstatements="0" methods="2" complexity="9" elements="37"/>
</class>
<line num="24" signature="DuplicatedLinesInSamePackage2()" type="method" complexity="1" count="0"/>
<line num="30" signature="duplicatedMethodInSameClass1() : void" type="method" complexity="8" count="0"/>
<line num="31" type="stmt" count="0"/>
<line num="32" type="stmt" count="0"/>
<line falsecount="0" num="32" type="cond" truecount="0"/>
<line num="33" type="stmt" count="0"/>
<line num="35" type="stmt" count="0"/>
<line num="36" type="stmt" count="0"/>
<line falsecount="0" num="36" type="cond" truecount="0"/>
<line num="37" type="stmt" count="0"/>
<line num="40" type="stmt" count="0"/>
<line num="41" type="stmt" count="0"/>
<line falsecount="0" num="41" type="cond" truecount="0"/>
<line num="42" type="stmt" count="0"/>
<line num="44" type="stmt" count="0"/>
<line num="45" type="stmt" count="0"/>
<line falsecount="0" num="45" type="cond" truecount="0"/>
<line num="46" type="stmt" count="0"/>
<line num="48" type="stmt" count="0"/>
<line num="49" type="stmt" count="0"/>
<line falsecount="0" num="49" type="cond" truecount="0"/>
<line num="50" type="stmt" count="0"/>
<line num="54" type="stmt" count="0"/>
<line num="55" type="stmt" count="0"/>
<line falsecount="0" num="55" type="cond" truecount="0"/>
<line num="56" type="stmt" count="0"/>
<line num="58" type="stmt" count="0"/>
<line num="59" type="stmt" count="0"/>
<line falsecount="0" num="59" type="cond" truecount="0"/>
<line num="60" type="stmt" count="0"/>
</file>
</package>
</project>
<testproject timestamp="1253282365324" name="Sonar tests - reference 1.0-SNAPSHOT">
<metrics coveredelements="16" packages="1" coveredconditionals="0" ncloc="33" statements="11" loc="61"
complexity="5" files="2" conditionals="0" coveredstatements="11" coveredmethods="5" methods="5" classes="2"
elements="16"/>
<package name="org.sonar.samples">
<metrics coveredelements="16" coveredconditionals="0" ncloc="33" statements="11" loc="61" complexity="5" files="2"
conditionals="0" coveredstatements="11" coveredmethods="5" methods="5" classes="2" elements="16"/>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/test/java/org/sonar/samples/ClassUnderTestTest.java"
name="ClassUnderTestTest.java">
<metrics coveredelements="6" coveredconditionals="0" conditionals="0" ncloc="12" statements="4"
coveredmethods="2" coveredstatements="4" loc="16" methods="2" classes="1" complexity="2" elements="6"/>
<class name="ClassUnderTestTest">
<metrics coveredelements="6" coveredconditionals="0" conditionals="0" statements="4" coveredmethods="2"
coveredstatements="4" methods="2" complexity="2" elements="6"/>
</class>
<line num="7" signature="testHello() : void" type="method" complexity="1" count="1"/>
<line num="8" type="stmt" count="1"/>
<line num="9" type="stmt" count="1"/>
<line num="12" signature="testToto() : void" type="method" complexity="1" count="1"/>
<line num="13" type="stmt" count="1"/>
<line num="14" type="stmt" count="1"/>
</file>
<file
path="/Users/simon/projects/sonar/trunk/tests/integration/reference-projects/reference/src/test/java/org/sonar/samples/InnerClassTest.java"
name="InnerClassTest.java">
<metrics coveredelements="10" coveredconditionals="0" conditionals="0" ncloc="21" statements="7"
coveredmethods="3" coveredstatements="7" loc="45" methods="3" classes="1" complexity="3"
elements="10"/>
<class name="InnerClassTest">
<metrics coveredelements="10" coveredconditionals="0" conditionals="0" statements="7" coveredmethods="3"
coveredstatements="7" methods="3" complexity="3" elements="10"/>
</class>
<line num="27" signature="shouldTestMethodToTest() : void" type="method" complexity="1" count="1"/>
<line num="29" type="stmt" count="1"/>
<line num="30" type="stmt" count="1"/>
<line num="33" signature="shouldTestInnerClassInside() : void" type="method" complexity="1" count="1"/>
<line num="35" type="stmt" count="1"/>
<line num="36" type="stmt" count="1"/>
<line num="37" type="stmt" count="1"/>
<line num="40" signature="shouldTestPrivateClass() : void" type="method" complexity="1" count="1"/>
<line num="42" type="stmt" count="1"/>
<line num="43" type="stmt" count="1"/>
</file>
</package>
</testproject>
</coverage>

+ 1793
- 0
plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/XmlReportParserTest/clover_2_3_2.xml
File diff suppressed because it is too large
View File


+ 12
- 0
plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/XmlReportParserTest/coverageShouldBeZeroWhenNoElements/clover.xml View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1171026251154" clover="1.3.12">
<project timestamp="1171026228045" name="Sample">
<metrics coveredelements="0" packages="2" coveredconditionals="0" ncloc="531" statements="138" loc="780" files="13" conditionals="12" coveredmethods="21" coveredstatements="49" methods="90" classes="14" elements="0"/>
<package name="ch.hortis.sonar.model">
<metrics coveredelements="0" files="6" coveredconditionals="0" conditionals="0" ncloc="126" statements="28" coveredstatements="0" coveredmethods="0" loc="203" methods="28" classes="7" elements="0"/>
<file name="/sonar/sonar-commons/src/main/java/ch/hortis/sonar/model/MetricsClassType.java">
<metrics coveredelements="0" coveredconditionals="0" conditionals="0" ncloc="11" statements="2" coveredstatements="0" coveredmethods="0" loc="20" methods="2" classes="1" elements="0"/>
</file>
</package>
</project>
</coverage>

+ 0
- 0
plugins/sonar-clover-plugin/src/test/resources/org/sonar/plugins/clover/clover.license View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save