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 2020/01/03 11:00:51 UTC

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

bmhm 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_r362772237
 
 

 ##########
 File path: src/main/java/org/apache/maven/plugins/checkstyle/Violation.java
 ##########
 @@ -0,0 +1,229 @@
+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 java.util.Objects;
+import java.util.StringJoiner;
+
+/**
+ * Holds data about a single violation and represents the violation itself.
+ */
+public class Violation
+{
+
+  /**
+   * 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;
+
+  private String column = NO_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.
+
+  /**
+   * Creates a violation instance without a column set.
+   *
+   * @param source
+   *     the source file name, relative to the project's root.
+   * @param file
+   *     the absolute file name 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,
+                    String 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 );
+  }
+
+  /**
+   * 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 {@link #NO_COLUMN}.
+   */
+  protected String getColumn( )
 
 Review comment:
   Because  either @rfscholte  or @eolivelli asked me not to use Integer.parseInt() on the XML input. I think this should stay a string for now, because we are not using any comparison against this field at the moment.

----------------------------------------------------------------
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