You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2019/12/12 11:44:07 UTC

[GitHub] [maven-checkstyle-plugin] elharo commented on a change in pull request #17: [MCHECKSTYLE-385] rework code to use a Violation.java class.

elharo commented on a change in pull request #17: [MCHECKSTYLE-385] rework code to use a Violation.java class.
URL: https://github.com/apache/maven-checkstyle-plugin/pull/17#discussion_r357097941
 
 

 ##########
 File path: src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
 ##########
 @@ -605,70 +610,118 @@ private void checkDeprecatedParameterUsage( Object parameter, String name, Strin
         }
     }
 
-    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()
 
 Review comment:
   This would be much easier to follow without lambdas. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services