Skip to content

Commit

Permalink
Fixes #478. Introduce checkstyle checking, and reformat some code
Browse files Browse the repository at this point in the history
  • Loading branch information
philsttr committed Jan 10, 2021
1 parent 3fdc998 commit bb42b6b
Show file tree
Hide file tree
Showing 63 changed files with 929 additions and 813 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ Source Code Style

Please follow the style used by the existing code in the repository.

4-space indents (no tabs)
Rules are enforced by [checkstyle](src/checkstyle/checkstyle.xml).


License
-------
Expand Down
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<animal-sniffer-maven-plugin.version>1.19</animal-sniffer-maven-plugin.version>
<lifecycle-mapping.version>1.0.0</lifecycle-mapping.version>
<maven-bundle-plugin.version>5.1.1</maven-bundle-plugin.version>
<maven-checkstyle-plugin.version>3.1.1</maven-checkstyle-plugin.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-enforcer-plugin.version>1.4.1</maven-enforcer-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
Expand Down Expand Up @@ -359,6 +360,23 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<configuration>
<configLocation>src/checkstyle/checkstyle.xml</configLocation>
<logViolationsToConsole>true</logViolationsToConsole>
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
Expand Down
90 changes: 90 additions & 0 deletions src/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>

<!-- Checks whether files end with a new line. -->
<!-- See https://checkstyle.org/config_misc.html#NewlineAtEndOfFile -->
<module name="NewlineAtEndOfFile"/>

<!-- Checks for white space at the end of the line -->
<!-- See http://checkstyle.sourceforge.net/config_regexp.html -->
<!-- Updated to ignore whitespace following '*' in javadoc comments -->
<!-- http://stackoverflow.com/questions/9100059/checkstyle-trailing-spaces-regexp-issue -->
<module name="RegexpSingleline">
<property name="format" value="(?&lt;!\A[ \t]*\*?)[ \t]$"/>
<property name="message" value="Line has trailing spaces."/>
<property name="fileExtensions" value="java"/>
</module>

<module name="TreeWalker">
<!--
Exceptions
See https://checkstyle.sourceforge.io/config_filters.html
-->
<module name="SuppressionCommentFilter" />
<module name="SuppressWithNearbyCommentFilter"/>

<!-- Checks for Javadoc comments. -->
<!-- See https://checkstyle.org/config_javadoc.html -->
<module name="InvalidJavadocPosition"/>

<!-- Checks for imports -->
<!-- See https://checkstyle.org/config_imports.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>

<!-- Checks for whitespace -->
<!-- See https://checkstyle.org/config_whitespace.html -->
<module name="EmptyForIteratorPad"/>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>

<!-- Modifier Checks -->
<!-- See https://checkstyle.org/config_modifiers.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<!-- Checks for blocks. You know, those {}'s -->
<!-- See https://checkstyle.org/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>

<!-- Checks for common coding problems -->
<!-- See https://checkstyle.org/config_coding.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MissingSwitchDefault"/>
<module name="MultipleVariableDeclarations"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>

<!-- Checks for class design -->
<!-- See https://checkstyle.org/config_design.html -->
<module name="InterfaceIsType"/>

<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/config_misc.html -->
<module name="ArrayTypeStyle"/>
<module name="TodoComment"/>
<module name="UpperEll"/>
</module>
<module name="RegexpHeader">
<property name="header" value="^/\*\*\n^ \* Licensed under the Apache License, Version 2\.0 \(the &quot;License&quot;\);"/>
</module>
</module>
12 changes: 7 additions & 5 deletions src/main/java/net/logstash/logback/LogstashAccessFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*/
package net.logstash.logback;

import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.core.joran.spi.DefaultClass;
import ch.qos.logback.core.spi.ContextAware;
import net.logstash.logback.composite.ContextJsonProvider;
import net.logstash.logback.composite.FieldNamesAware;
import net.logstash.logback.composite.GlobalCustomFieldsJsonProvider;
Expand All @@ -37,9 +40,6 @@
import net.logstash.logback.composite.accessevent.ResponseHeadersJsonProvider;
import net.logstash.logback.composite.accessevent.StatusCodeJsonProvider;
import net.logstash.logback.fieldnames.LogstashAccessFieldNames;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.core.joran.spi.DefaultClass;
import ch.qos.logback.core.spi.ContextAware;

import com.fasterxml.jackson.databind.JsonNode;

Expand Down Expand Up @@ -159,7 +159,8 @@ public void setCustomFieldsFromString(String customFields) {
globalCustomFieldsProvider = null;
} else {
if (globalCustomFieldsProvider == null) {
getProviders().addGlobalCustomFields(globalCustomFieldsProvider = new GlobalCustomFieldsJsonProvider<IAccessEvent>());
globalCustomFieldsProvider = new GlobalCustomFieldsJsonProvider<>();
getProviders().addGlobalCustomFields(globalCustomFieldsProvider);
}
globalCustomFieldsProvider.setCustomFields(customFields);
}
Expand All @@ -171,7 +172,8 @@ public void setCustomFields(JsonNode customFields) {
globalCustomFieldsProvider = null;
} else {
if (globalCustomFieldsProvider == null) {
getProviders().addGlobalCustomFields(globalCustomFieldsProvider = new GlobalCustomFieldsJsonProvider<IAccessEvent>());
globalCustomFieldsProvider = new GlobalCustomFieldsJsonProvider<>();
getProviders().addGlobalCustomFields(globalCustomFieldsProvider);
}
globalCustomFieldsProvider.setCustomFieldsNode(customFields);
}
Expand Down
Loading

0 comments on commit bb42b6b

Please sign in to comment.