diff --git a/src/it/MCHECKSTYLE-371/invoker.properties b/src/it/MCHECKSTYLE-371/invoker.properties new file mode 100644 index 00000000..2825fc53 --- /dev/null +++ b/src/it/MCHECKSTYLE-371/invoker.properties @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals=verify +# checkstyleRules requires Maven 3+ +invoker.maven.version = 3.0+ diff --git a/src/it/MCHECKSTYLE-371/pom.xml b/src/it/MCHECKSTYLE-371/pom.xml new file mode 100644 index 00000000..3eab6d7c --- /dev/null +++ b/src/it/MCHECKSTYLE-371/pom.xml @@ -0,0 +1,72 @@ + + + + + 4.0.0 + + org.apache.maven.plugins.checkstyle.its + MCHECKSTYLE-371 + 1.0-SNAPSHOT + + https://issues.apache.org/jira/browse/MCHECKSTYLE-371 + + + UTF-8 + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + @project.version@ + + + **\/*.java + + + + + + + + + + + + + true + 10 + warning + + + + check + + check + + + + + + + diff --git a/src/it/MCHECKSTYLE-371/src/test/resources/MyClass.java b/src/it/MCHECKSTYLE-371/src/test/resources/MyClass.java new file mode 100644 index 00000000..666efd9e --- /dev/null +++ b/src/it/MCHECKSTYLE-371/src/test/resources/MyClass.java @@ -0,0 +1,27 @@ +package org; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * My class. + */ +public class MyClass +{ +} diff --git a/src/it/MCHECKSTYLE-371/verify.groovy b/src/it/MCHECKSTYLE-371/verify.groovy new file mode 100644 index 00000000..5250b24f --- /dev/null +++ b/src/it/MCHECKSTYLE-371/verify.groovy @@ -0,0 +1,22 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +def buildLog = new File( basedir, 'build.log' ) + +assert buildLog.text.contains( "[INFO] You have 1 Checkstyle violation." ) diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java index 8c500014..04d6e188 100644 --- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java +++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java @@ -155,6 +155,14 @@ public class CheckstyleViolationCheckMojo */ @Parameter( property = "checkstyle.console", defaultValue = "true" ) private boolean logViolationsToConsole; + + /** + * Output the detected violation count to the console. + * + * @since 3.0.1 + */ + @Parameter( property = "checkstyle.logViolationCount", defaultValue = "true" ) + private boolean logViolationCountToConsole; /** * Specifies the location of the resources to be used for Checkstyle. @@ -570,21 +578,25 @@ public void execute() int violations = countViolations( xpp ); + String msg = "You have " + violations + " Checkstyle violation" + + ( ( violations > 1 || violations == 0 ) ? "s" : "" ) + "."; if ( violations > maxAllowedViolations ) { if ( failOnViolation ) { - String msg = - "You have " + violations + " Checkstyle violation" + ( ( violations > 1 ) ? "s" : "" ) + "."; if ( maxAllowedViolations > 0 ) { msg += " The maximum number of allowed violations is " + maxAllowedViolations + "."; } throw new MojoFailureException( msg ); } - + getLog().warn( "checkstyle:check violations detected but failOnViolation set to false" ); } + if ( logViolationCountToConsole ) + { + getLog().info( msg ); + } } catch ( IOException | XmlPullParserException e ) {