You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by eo...@apache.org on 2020/01/03 09:55:29 UTC

[maven-checkstyle-plugin] branch MCHECKSTYLE-385 created (now 556444f)

This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a change to branch MCHECKSTYLE-385
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git.


      at 556444f  [[MCHECKSTYLE-385] Removed useless list for counting violations.

This branch includes the following new commits:

     new 98b6122  [MCHECKSTYLE-385] rework code to use a Violation.java class. This enables further optimizations.
     new f76a9b4  [MCHECKSTYLE-385] Implementing reviews and comments.
     new 1611c07  [MCHECKSTYLE-385] Removing @Nullable annotation.
     new a58a96f  [MCHECKSTYLE-385] added javadoc.
     new ff0b375  [[MCHECKSTYLE-385]] apply existing code conventions
     new 556444f  [[MCHECKSTYLE-385] Removed useless list for counting violations.

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-checkstyle-plugin] 02/06: [MCHECKSTYLE-385] Implementing reviews and comments.

Posted by eo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch MCHECKSTYLE-385
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git

commit f76a9b4a05a6c8d5fdad6c01db2058b3d9eaf827
Author: Benjamin Marwell <bm...@gmail.com>
AuthorDate: Wed Dec 11 22:51:48 2019 +0100

    [MCHECKSTYLE-385] Implementing reviews and comments.
    
    Signed-off-by: Benjamin Marwell <bm...@gmail.com>
---
 .../checkstyle/CheckstyleViolationCheckMojo.java   | 61 +++++++++++-----------
 .../apache/maven/plugins/checkstyle/Violation.java | 54 ++++++++++++++-----
 2 files changed, 72 insertions(+), 43 deletions(-)

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 1f3decc..4afeea6 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
@@ -31,8 +31,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.atomic.LongAdder;
-import java.util.stream.Collectors;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.model.Dependency;
@@ -573,15 +571,16 @@ public class CheckstyleViolationCheckMojo
             xpp.setInput( reader );
 
             final List<Violation> violationsList = getViolations( xpp );
-            long violations = countViolations( violationsList );
+            long violationCount = countViolations( violationsList );
             printViolations( violationsList );
 
-            if ( violations > maxAllowedViolations )
+            if ( violationCount > maxAllowedViolations )
             {
                 if ( failOnViolation )
                 {
                     String msg =
-                        "You have " + violations + " Checkstyle violation" + ( ( violations > 1 ) ? "s" : "" ) + ".";
+                        "You have " + violationCount
+                            + " Checkstyle violation" + ( ( violationCount > 1 ) ? "s" : "" ) + ".";
                     if ( maxAllowedViolations > 0 )
                     {
                         msg += " The maximum number of allowed violations is " + maxAllowedViolations + ".";
@@ -624,14 +623,12 @@ public class CheckstyleViolationCheckMojo
             {
                 continue;
             }
-
-            if ( "file".equals( xpp.getName() ) )
+            else if ( "file".equals( xpp.getName() ) )
             {
                 file = PathTool.getRelativeFilePath( basedir, xpp.getAttributeValue( "", "name" ) );
                 continue;
             }
-
-            if ( !"error".equals( xpp.getName() ) )
+            else if ( ! "error".equals( xpp.getName() ) )
             {
                 continue;
             }
@@ -647,7 +644,7 @@ public class CheckstyleViolationCheckMojo
             Violation violation = new Violation(
                 source,
                 file,
-                Integer.parseInt( line, 10 ),
+                line,
                 severity,
                 message,
                 rule,
@@ -655,7 +652,7 @@ public class CheckstyleViolationCheckMojo
             );
             if ( column != null )
             {
-                violation.setColumn( Integer.parseInt( column, 10 ) );
+                violation.setColumn( column );
             }
 
             violations.add( violation );
@@ -664,32 +661,36 @@ public class CheckstyleViolationCheckMojo
         return Collections.unmodifiableList( violations );
     }
 
-    private long countViolations( List<Violation> violations )
+    private int countViolations( List<Violation> violations )
     {
         List<RuleUtil.Matcher> ignores = violationIgnore == null ? Collections.<RuleUtil.Matcher>emptyList()
             : RuleUtil.parseMatchers( violationIgnore.split( "," ) );
 
-        LongAdder ignored = new LongAdder();
+        int ignored = 0;
 
-        final List<Violation> violationStream = violations.stream()
-            .filter( violation -> isViolation( violation.getSeverity() ) )
-            .filter( violation ->
+        List<Violation> actualViolations = new ArrayList<>();
+
+        for ( Violation violation : violations )
+        {
+            if ( ! isViolation( violation.getSeverity() ) )
             {
-                final boolean isIgnore = !ignore( ignores, violation.getSource() );
-                if ( isIgnore )
-                {
-                    ignored.increment();
-                }
-                return isIgnore;
-            } )
-            .collect( Collectors.toList() );
+                continue;
+            }
+
+            if ( ignore( ignores, violation.getSource() ) )
+            {
+                ignored++;
+                continue;
+            }
+
+            actualViolations.add( violation );
+        }
 
-        final int count = violationStream.size();
-        final long ignoreCount = ignored.sum();
+        final int count = actualViolations.size();
 
-        if ( ignoreCount > 0 )
+        if ( ignored > 0 )
         {
-            getLog().info( "Ignored " + ignoreCount + " error" + ( ( ignoreCount > 1L ) ? "s" : "" ) + ", " + count
+            getLog().info( "Ignored " + ignored + " error" + ( ( ignored > 1L ) ? "s" : "" ) + ", " + count
                 + " violation" + ( ( count > 1 ) ? "s" : "" ) + " remaining." );
         }
 
@@ -711,10 +712,10 @@ public class CheckstyleViolationCheckMojo
             .filter( violation -> !ignore( ignores, violation.getSource() ) )
             .forEach( violation ->
             {
-                final String message = String.format( "%s:[%d%s] (%s) %s: %s",
+                final String message = String.format( "%s:[%s%s] (%s) %s: %s",
                     violation.getFile(),
                     violation.getLine(),
-                    ( violation.getColumn() == null ) ? "" : ( ',' + violation.getColumn() ),
+                    ( Violation.NO_COLUMN.equals( violation.getColumn() ) ) ? "" : ( ',' + violation.getColumn() ),
                     violation.getCategory(),
                     violation.getRuleName(),
                     violation.getMessage() );
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java b/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
index 5d0cb84..90d0ed9 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
@@ -29,13 +29,16 @@ import java.util.StringJoiner;
  */
 public class Violation
 {
+
+  public static final String NO_COLUMN = "-1";
+
   private final String source;
 
   private final String file;
 
-  private final int line;
+  private final String line;
 
-  private @Nullable Integer column;
+  private String column = NO_COLUMN;
 
   private final String severity;
 
@@ -46,9 +49,28 @@ public class Violation
   private final String category;
 
   // Leaving out column, because there is no CHECKSTYLE:OFF support.
+
+  /**
+   * Creates a violation instance without a column set.
+   *
+   * @param source
+   *     the source, to be defined.
+   * @param file
+   *     the file in which the violation occurred.
+   * @param line
+   *     the line in the file on which the violation occurred.
+   * @param severity
+   *     the severity of the violation.
+   * @param message
+   *     the message from checkstyle for this violation.
+   * @param ruleName
+   *     the rule name from which this violation was created.
+   * @param category
+   *     the category of the checkstyle violation.
+   */
   public Violation( String source,
                     String file,
-                    int line,
+                    String line,
                     String severity,
                     String message,
                     String ruleName,
@@ -63,47 +85,53 @@ public class Violation
     this.category = Objects.requireNonNull( category );
   }
 
-  public String getSource()
+  protected String getSource( )
   {
     return source;
   }
 
-  public String getFile()
+  protected String getFile( )
   {
     return file;
   }
 
-  public long getLine()
+  protected String getLine( )
   {
     return line;
   }
 
-  public @Nullable Integer getColumn()
+  protected String getColumn( )
   {
     return column;
   }
 
-  public void setColumn( @Nullable Integer column )
+  protected void setColumn( @Nullable String column )
   {
+    if ( null == column || column.length() < 1 )
+    {
+      this.column = NO_COLUMN;
+      return;
+    }
+
     this.column = column;
   }
 
-  public String getSeverity()
+  protected String getSeverity( )
   {
     return severity;
   }
 
-  public String getMessage()
+  protected String getMessage( )
   {
     return message;
   }
 
-  public String getRuleName()
+  protected String getRuleName( )
   {
     return ruleName;
   }
 
-  public String getCategory()
+  protected String getCategory( )
   {
     return category;
   }
@@ -120,7 +148,7 @@ public class Violation
       return false;
     }
     Violation violation = ( Violation ) other;
-    return line == violation.line
+    return line.equals( violation.line )
         && Objects.equals( column, violation.column )
         && source.equals( violation.source )
         && file.equals( violation.file )


[maven-checkstyle-plugin] 03/06: [MCHECKSTYLE-385] Removing @Nullable annotation.

Posted by eo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch MCHECKSTYLE-385
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git

commit 1611c07a2c062576390006190a264be7699258cf
Author: Benjamin Marwell <bm...@gmail.com>
AuthorDate: Wed Dec 11 22:51:48 2019 +0100

    [MCHECKSTYLE-385] Removing @Nullable annotation.
    
    Signed-off-by: Benjamin Marwell <bm...@gmail.com>
---
 .../apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java | 4 ++--
 src/main/java/org/apache/maven/plugins/checkstyle/Violation.java      | 4 +---
 2 files changed, 3 insertions(+), 5 deletions(-)

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 4afeea6..531a108 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
@@ -50,7 +50,6 @@ import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutor;
 import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException;
 import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
 import org.apache.maven.project.MavenProject;
-import org.checkerframework.checker.nullness.qual.Nullable;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.PathTool;
@@ -636,7 +635,8 @@ public class CheckstyleViolationCheckMojo
             String severity = xpp.getAttributeValue( "", "severity" );
             String source = xpp.getAttributeValue( "", "source" );
             String line = xpp.getAttributeValue( "", "line" );
-            @Nullable String column = xpp.getAttributeValue( "", "column" );
+            /* Nullable */
+            String column = xpp.getAttributeValue( "", "column" );
             String message = xpp.getAttributeValue( "", "message" );
             String rule = RuleUtil.getName( source );
             String category = RuleUtil.getCategory( source );
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java b/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
index 90d0ed9..ded621e 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
@@ -19,8 +19,6 @@ package org.apache.maven.plugins.checkstyle;
  * under the License.
  */
 
-import org.checkerframework.checker.nullness.qual.Nullable;
-
 import java.util.Objects;
 import java.util.StringJoiner;
 
@@ -105,7 +103,7 @@ public class Violation
     return column;
   }
 
-  protected void setColumn( @Nullable String column )
+  protected void setColumn( /* Nullable */ String column )
   {
     if ( null == column || column.length() < 1 )
     {


[maven-checkstyle-plugin] 01/06: [MCHECKSTYLE-385] rework code to use a Violation.java class. This enables further optimizations.

Posted by eo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch MCHECKSTYLE-385
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git

commit 98b612248511ef3956fd7575c17a8487dcb98b08
Author: Benjamin Marwell <bm...@gmail.com>
AuthorDate: Wed Dec 11 22:51:48 2019 +0100

    [MCHECKSTYLE-385] rework code to use a Violation.java class. This enables further optimizations.
---
 .../checkstyle/CheckstyleViolationCheckMojo.java   | 125 ++++++++++++-----
 .../apache/maven/plugins/checkstyle/Violation.java | 153 +++++++++++++++++++++
 2 files changed, 242 insertions(+), 36 deletions(-)

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 404cce7..1f3decc 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
@@ -31,6 +31,8 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.LongAdder;
+import java.util.stream.Collectors;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.model.Dependency;
@@ -50,6 +52,7 @@ import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutor;
 import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException;
 import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
 import org.apache.maven.project.MavenProject;
+import org.checkerframework.checker.nullness.qual.Nullable;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.PathTool;
@@ -569,7 +572,9 @@ public class CheckstyleViolationCheckMojo
             XmlPullParser xpp = new MXParser();
             xpp.setInput( reader );
 
-            int violations = countViolations( xpp );
+            final List<Violation> violationsList = getViolations( xpp );
+            long violations = countViolations( violationsList );
+            printViolations( violationsList );
 
             if ( violations > maxAllowedViolations )
             {
@@ -605,70 +610,118 @@ public class CheckstyleViolationCheckMojo
         }
     }
 
-    private int countViolations( XmlPullParser xpp )
+    private List<Violation> getViolations( XmlPullParser xpp )
         throws XmlPullParserException, IOException
     {
-        int count = 0;
-        int ignoreCount = 0;
-        List<RuleUtil.Matcher> ignores = violationIgnore == null ? Collections.<RuleUtil.Matcher>emptyList()
-                        : RuleUtil.parseMatchers( violationIgnore.split( "," ) );
+        List<Violation> violations = new ArrayList<>();
 
         String basedir = project.getBasedir().getAbsolutePath();
         String file = "";
+
         for ( int eventType = xpp.getEventType(); eventType != XmlPullParser.END_DOCUMENT; eventType = xpp.next() )
         {
             if ( eventType != XmlPullParser.START_TAG )
             {
                 continue;
             }
-            else if ( "file".equals( xpp.getName() ) )
+
+            if ( "file".equals( xpp.getName() ) )
             {
                 file = PathTool.getRelativeFilePath( basedir, xpp.getAttributeValue( "", "name" ) );
-                //file = file.substring( file.lastIndexOf( File.separatorChar ) + 1 );
+                continue;
             }
-            else if ( "error".equals( xpp.getName() ) )
+
+            if ( !"error".equals( xpp.getName() ) )
             {
-                String severity = xpp.getAttributeValue( "", "severity" );
+                continue;
+            }
 
-                if ( !isViolation( severity ) )
-                {
-                    continue;
-                }
+            String severity = xpp.getAttributeValue( "", "severity" );
+            String source = xpp.getAttributeValue( "", "source" );
+            String line = xpp.getAttributeValue( "", "line" );
+            @Nullable String column = xpp.getAttributeValue( "", "column" );
+            String message = xpp.getAttributeValue( "", "message" );
+            String rule = RuleUtil.getName( source );
+            String category = RuleUtil.getCategory( source );
+
+            Violation violation = new Violation(
+                source,
+                file,
+                Integer.parseInt( line, 10 ),
+                severity,
+                message,
+                rule,
+                category
+            );
+            if ( column != null )
+            {
+                violation.setColumn( Integer.parseInt( column, 10 ) );
+            }
+
+            violations.add( violation );
+        }
+
+        return Collections.unmodifiableList( violations );
+    }
+
+    private long countViolations( List<Violation> violations )
+    {
+        List<RuleUtil.Matcher> ignores = violationIgnore == null ? Collections.<RuleUtil.Matcher>emptyList()
+            : RuleUtil.parseMatchers( violationIgnore.split( "," ) );
 
-                String source = xpp.getAttributeValue( "", "source" );
+        LongAdder ignored = new LongAdder();
 
-                if ( ignore( ignores, source ) )
+        final List<Violation> violationStream = violations.stream()
+            .filter( violation -> isViolation( violation.getSeverity() ) )
+            .filter( violation ->
+            {
+                final boolean isIgnore = !ignore( ignores, violation.getSource() );
+                if ( isIgnore )
                 {
-                    ignoreCount++;
+                    ignored.increment();
                 }
-                else
-                {
-                    count++;
+                return isIgnore;
+            } )
+            .collect( Collectors.toList() );
 
-                    if ( logViolationsToConsole )
-                    {
-                        String line = xpp.getAttributeValue( "", "line" );
-                        String column = xpp.getAttributeValue( "", "column" );
-                        String message = xpp.getAttributeValue( "", "message" );
-                        String rule = RuleUtil.getName( source );
-                        String category = RuleUtil.getCategory( source );
-
-                        log( severity, file + ":[" + line + ( ( column == null ) ? "" : ( ',' + column ) ) + "] ("
-                            + category + ") " + rule + ": " + message );
-                    }
-                }
-            }
-        }
+        final int count = violationStream.size();
+        final long ignoreCount = ignored.sum();
 
         if ( ignoreCount > 0 )
         {
-            getLog().info( "Ignored " + ignoreCount + " error" + ( ( ignoreCount > 1 ) ? "s" : "" ) + ", " + count
-                               + " violation" + ( ( count > 1 ) ? "s" : "" ) + " remaining." );
+            getLog().info( "Ignored " + ignoreCount + " error" + ( ( ignoreCount > 1L ) ? "s" : "" ) + ", " + count
+                + " violation" + ( ( count > 1 ) ? "s" : "" ) + " remaining." );
         }
 
         return count;
     }
 
+    private void printViolations( List<Violation> violations )
+    {
+        if ( ! logViolationsToConsole )
+        {
+            return;
+        }
+
+        List<RuleUtil.Matcher> ignores = violationIgnore == null ? Collections.<RuleUtil.Matcher>emptyList()
+            : RuleUtil.parseMatchers( violationIgnore.split( "," ) );
+
+        violations.stream()
+            .filter( violation -> isViolation( violation.getSeverity() ) )
+            .filter( violation -> !ignore( ignores, violation.getSource() ) )
+            .forEach( violation ->
+            {
+                final String message = String.format( "%s:[%d%s] (%s) %s: %s",
+                    violation.getFile(),
+                    violation.getLine(),
+                    ( violation.getColumn() == null ) ? "" : ( ',' + violation.getColumn() ),
+                    violation.getCategory(),
+                    violation.getRuleName(),
+                    violation.getMessage() );
+                log( violation.getSeverity(), message );
+            } );
+    }
+
     private void log( String severity, String message )
     {
         if ( "info".equals( severity ) )
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java b/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
new file mode 100644
index 0000000..5d0cb84
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
@@ -0,0 +1,153 @@
+package org.apache.maven.plugins.checkstyle;
+
+/*
+ * 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.
+ */
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.Objects;
+import java.util.StringJoiner;
+
+/**
+ * Holds data about a single violation and represents the violation itself.
+ */
+public class Violation
+{
+  private final String source;
+
+  private final String file;
+
+  private final int line;
+
+  private @Nullable Integer column;
+
+  private final String severity;
+
+  private final String message;
+
+  private final String ruleName;
+
+  private final String category;
+
+  // Leaving out column, because there is no CHECKSTYLE:OFF support.
+  public Violation( String source,
+                    String file,
+                    int line,
+                    String severity,
+                    String message,
+                    String ruleName,
+                    String category )
+  {
+    this.source = Objects.requireNonNull( source );
+    this.file = file;
+    this.line = line;
+    this.severity = Objects.requireNonNull( severity );
+    this.message = Objects.requireNonNull( message );
+    this.ruleName = Objects.requireNonNull( ruleName );
+    this.category = Objects.requireNonNull( category );
+  }
+
+  public String getSource()
+  {
+    return source;
+  }
+
+  public String getFile()
+  {
+    return file;
+  }
+
+  public long getLine()
+  {
+    return line;
+  }
+
+  public @Nullable Integer getColumn()
+  {
+    return column;
+  }
+
+  public void setColumn( @Nullable Integer column )
+  {
+    this.column = column;
+  }
+
+  public String getSeverity()
+  {
+    return severity;
+  }
+
+  public String getMessage()
+  {
+    return message;
+  }
+
+  public String getRuleName()
+  {
+    return ruleName;
+  }
+
+  public String getCategory()
+  {
+    return category;
+  }
+
+  @Override
+  public boolean equals( Object other )
+  {
+    if ( this == other )
+    {
+      return true;
+    }
+    if ( !( other instanceof Violation ) )
+    {
+      return false;
+    }
+    Violation violation = ( Violation ) other;
+    return line == violation.line
+        && Objects.equals( column, violation.column )
+        && source.equals( violation.source )
+        && file.equals( violation.file )
+        && severity.equals( violation.severity )
+        && message.equals( violation.message )
+        && ruleName.equals( violation.ruleName )
+        && category.equals( violation.category );
+  }
+
+  @Override
+  public int hashCode()
+  {
+    return Objects.hash( source, file, line, column, severity, message, ruleName, category );
+  }
+
+  @Override
+  public String toString()
+  {
+    return new StringJoiner( ", ", Violation.class.getSimpleName() + "[", "]" )
+        .add( "source='" + source + "'" )
+        .add( "file='" + file + "'" )
+        .add( "line=" + line )
+        .add( "column=" + column )
+        .add( "severity='" + severity + "'" )
+        .add( "message='" + message + "'" )
+        .add( "ruleName='" + ruleName + "'" )
+        .add( "category='" + category + "'" )
+        .toString();
+  }
+}


[maven-checkstyle-plugin] 06/06: [[MCHECKSTYLE-385] Removed useless list for counting violations.

Posted by eo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch MCHECKSTYLE-385
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git

commit 556444febb8f6731f5a408fd655ece9a43494871
Author: Benjamin Marwell <bm...@gmail.com>
AuthorDate: Fri Dec 13 21:12:55 2019 +0100

    [[MCHECKSTYLE-385] Removed useless list for counting violations.
---
 .../plugins/checkstyle/CheckstyleViolationCheckMojo.java    | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

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 9a0c4ba..993992d 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
@@ -667,8 +667,7 @@ public class CheckstyleViolationCheckMojo
             : RuleUtil.parseMatchers( violationIgnore.split( "," ) );
 
         int ignored = 0;
-
-        List<Violation> actualViolations = new ArrayList<>();
+        int countedViolations = 0;
 
         for ( Violation violation : violations )
         {
@@ -683,18 +682,16 @@ public class CheckstyleViolationCheckMojo
                 continue;
             }
 
-            actualViolations.add( violation );
+            countedViolations++;
         }
 
-        final int count = actualViolations.size();
-
         if ( ignored > 0 )
         {
-            getLog().info( "Ignored " + ignored + " error" + ( ( ignored > 1L ) ? "s" : "" ) + ", " + count
-                + " violation" + ( ( count > 1 ) ? "s" : "" ) + " remaining." );
+            getLog().info( "Ignored " + ignored + " error" + ( ( ignored > 1L ) ? "s" : "" ) + ", " + countedViolations
+                + " violation" + ( ( countedViolations > 1 ) ? "s" : "" ) + " remaining." );
         }
 
-        return count;
+        return countedViolations;
     }
 
     private void printViolations( List<Violation> violations )


[maven-checkstyle-plugin] 05/06: [[MCHECKSTYLE-385]] apply existing code conventions

Posted by eo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch MCHECKSTYLE-385
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git

commit ff0b3759c19dcbbba3774bb8014670ea160d77b8
Author: Benjamin Marwell <bm...@gmail.com>
AuthorDate: Fri Dec 13 20:51:51 2019 +0100

    [[MCHECKSTYLE-385]] apply existing code conventions
    
      - change collections to remain modifiable.
      - Use 'else' instead of guard statements in Violation.java.
---
 .../plugins/checkstyle/CheckstyleViolationCheckMojo.java  |  2 +-
 .../org/apache/maven/plugins/checkstyle/Violation.java    | 15 ++++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

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 531a108..9a0c4ba 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
@@ -658,7 +658,7 @@ public class CheckstyleViolationCheckMojo
             violations.add( violation );
         }
 
-        return Collections.unmodifiableList( violations );
+        return violations;
     }
 
     private int countViolations( List<Violation> violations )
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java b/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
index 0590b95..91f1343 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
@@ -121,22 +121,27 @@ public class Violation
   /**
    * Returns the column in which the violation occurred, if available.
    *
-   * @return the column in which the violation occurred, if available. Otherwise returns {@code "-1"}.
+   * @return the column in which the violation occurred, if available. Otherwise returns {@link #NO_COLUMN}.
    */
   protected String getColumn( )
   {
     return column;
   }
 
+  /**
+   * Sets the column value for this violation to the given string value.
+   * @param column the column value to set. May be {@code null}, which will set it to the {@link #NO_COLUMN} value.
+   */
   protected void setColumn( /* Nullable */ String column )
   {
-    if ( null == column || column.length() < 1 )
+    if ( column == null || column.length() < 1 )
     {
       this.column = NO_COLUMN;
-      return;
     }
-
-    this.column = column;
+    else
+    {
+      this.column = column;
+    }
   }
 
   /**


[maven-checkstyle-plugin] 04/06: [MCHECKSTYLE-385] added javadoc.

Posted by eo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch MCHECKSTYLE-385
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git

commit a58a96f9603bffbbbb926de8de523e1677ce8064
Author: Benjamin Marwell <bm...@gmail.com>
AuthorDate: Thu Dec 12 16:36:24 2019 +0100

    [MCHECKSTYLE-385] added javadoc.
    
    Signed-off-by: Benjamin Marwell <bm...@gmail.com>
---
 .../apache/maven/plugins/checkstyle/Violation.java | 51 ++++++++++++++++++++--
 1 file changed, 48 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java b/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
index ded621e..0590b95 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
@@ -28,10 +28,15 @@ import java.util.StringJoiner;
 public class Violation
 {
 
-  public static final String NO_COLUMN = "-1";
+  /**
+   * Indicates that a column is not set.
+   */
+  protected static final String NO_COLUMN = "-1";
 
+  /** The source file name relative to the project's root. */
   private final String source;
 
+  /** File is the absolute file name to the checked file. */
   private final String file;
 
   private final String line;
@@ -52,9 +57,9 @@ public class Violation
    * Creates a violation instance without a column set.
    *
    * @param source
-   *     the source, to be defined.
+   *     the source file name, relative to the project's root.
    * @param file
-   *     the file in which the violation occurred.
+   *     the absolute file name in which the violation occurred.
    * @param line
    *     the line in the file on which the violation occurred.
    * @param severity
@@ -83,21 +88,41 @@ public class Violation
     this.category = Objects.requireNonNull( category );
   }
 
+  /**
+   * Returns the source file name relative to the project's root.
+   *
+   * @return the source file name relative to the project's root.
+   */
   protected String getSource( )
   {
     return source;
   }
 
+  /**
+   * Returns the absolute file name to the checked file.
+   *
+   * @return the absolute file name to the checked file.
+   */
   protected String getFile( )
   {
     return file;
   }
 
+  /**
+   * Returns the line of in the checked file on which the violation occurred.
+   *
+   * @return the line of in the checked file on which the violation occurred.
+   */
   protected String getLine( )
   {
     return line;
   }
 
+  /**
+   * Returns the column in which the violation occurred, if available.
+   *
+   * @return the column in which the violation occurred, if available. Otherwise returns {@code "-1"}.
+   */
   protected String getColumn( )
   {
     return column;
@@ -114,21 +139,41 @@ public class Violation
     this.column = column;
   }
 
+  /**
+   * Returns the severity of the current violation.
+   *
+   * @return the severity of the current violation.
+   */
   protected String getSeverity( )
   {
     return severity;
   }
 
+  /**
+   * Returns the message produced by checkstyle for the current violation.
+   *
+   * @return the message produced by checkstyle for the current violation.
+   */
   protected String getMessage( )
   {
     return message;
   }
 
+  /**
+   * Returns the name of the rule which led to the current violation.
+   *
+   * @return the name of the rule which led to the current violation.
+   */
   protected String getRuleName( )
   {
     return ruleName;
   }
 
+  /**
+   * Returns the category of the current violation.
+   *
+   * @return the category of the current violation.
+   */
   protected String getCategory( )
   {
     return category;