Author: dennisl
Date: Sun Feb 3 07:29:23 2008
New Revision: 617999
URL: http://svn.apache.org/viewvc?rev=617999&view=rev
Log:
[MCHECKSTYLE-45] It should be possible to configure checkstyle:check to fail on
"warnings".
Submitted by: Fabian Bauschulte
Reviewed by: Dennis Lundberg
o I renamed the new parameter and method.
Modified:
maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java
Modified:
maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java?rev=617999&r1=617998&r2=617999&view=diff
==============================================================================
---
maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java
(original)
+++
maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java
Sun Feb 3 07:29:23 2008
@@ -73,6 +73,15 @@
private boolean failOnViolation;
/**
+ * The lowest severity level that is considered a violation.
+ * Valid values are "error", "warning" and "info".
+ *
+ * @parameter expression="${checkstyle.violationSeverity}"
default-value="error"
+ * @since 2.2
+ */
+ private String violationSeverity = "error";
+
+ /**
* Skip entire check.
*
* @parameter expression="${checkstyle.skip}" default-value="false"
@@ -144,7 +153,7 @@
while ( eventType != XmlPullParser.END_DOCUMENT )
{
if ( eventType == XmlPullParser.START_TAG && "error".equals(
xpp.getName() )
- && "error".equals( xpp.getAttributeValue( "", "severity" ) ) )
+ && isViolation( xpp.getAttributeValue( "", "severity" ) ) )
{
count++;
}
@@ -153,4 +162,31 @@
return count;
}
-}
+
+ /**
+ * Checks if the given severity is considered a violation.
+ *
+ * @param severity The severity to check
+ * @return <code>true</code> if the given severity is a violation,
otherwise <code>false</code>
+ */
+ private boolean isViolation( String severity )
+ {
+ if ( "error".equals( severity ) )
+ {
+ return "error".equals( violationSeverity ) || "warning".equals(
violationSeverity )
+ || "info".equals( violationSeverity );
+ }
+ else if ( "warning".equals( severity ) )
+ {
+ return "warning".equals( violationSeverity ) || "info".equals(
violationSeverity );
+ }
+ else if ( "info".equals( severity ) )
+ {
+ return "info".equals( violationSeverity );
+ }
+ else
+ {
+ return false;
+ }
+ }
+}
\ No newline at end of file