Skip to content

Commit bb42b6b

Browse files
committed
Fixes #478. Introduce checkstyle checking, and reformat some code
1 parent 3fdc998 commit bb42b6b

File tree

63 files changed

+929
-813
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+929
-813
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ Source Code Style
9999

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

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

104105
License
105106
-------

pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<animal-sniffer-maven-plugin.version>1.19</animal-sniffer-maven-plugin.version>
3939
<lifecycle-mapping.version>1.0.0</lifecycle-mapping.version>
4040
<maven-bundle-plugin.version>5.1.1</maven-bundle-plugin.version>
41+
<maven-checkstyle-plugin.version>3.1.1</maven-checkstyle-plugin.version>
4142
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
4243
<maven-enforcer-plugin.version>1.4.1</maven-enforcer-plugin.version>
4344
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
@@ -359,6 +360,23 @@
359360
</instructions>
360361
</configuration>
361362
</plugin>
363+
<plugin>
364+
<groupId>org.apache.maven.plugins</groupId>
365+
<artifactId>maven-checkstyle-plugin</artifactId>
366+
<version>${maven-checkstyle-plugin.version}</version>
367+
<configuration>
368+
<configLocation>src/checkstyle/checkstyle.xml</configLocation>
369+
<logViolationsToConsole>true</logViolationsToConsole>
370+
<failOnViolation>true</failOnViolation>
371+
</configuration>
372+
<executions>
373+
<execution>
374+
<goals>
375+
<goal>check</goal>
376+
</goals>
377+
</execution>
378+
</executions>
379+
</plugin>
362380
</plugins>
363381
<pluginManagement>
364382
<plugins>

src/checkstyle/checkstyle.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
3+
<module name="Checker">
4+
<module name="FileTabCharacter">
5+
<property name="eachLine" value="true"/>
6+
</module>
7+
8+
<!-- Checks whether files end with a new line. -->
9+
<!-- See https://checkstyle.org/config_misc.html#NewlineAtEndOfFile -->
10+
<module name="NewlineAtEndOfFile"/>
11+
12+
<!-- Checks for white space at the end of the line -->
13+
<!-- See http://checkstyle.sourceforge.net/config_regexp.html -->
14+
<!-- Updated to ignore whitespace following '*' in javadoc comments -->
15+
<!-- http://stackoverflow.com/questions/9100059/checkstyle-trailing-spaces-regexp-issue -->
16+
<module name="RegexpSingleline">
17+
<property name="format" value="(?&lt;!\A[ \t]*\*?)[ \t]$"/>
18+
<property name="message" value="Line has trailing spaces."/>
19+
<property name="fileExtensions" value="java"/>
20+
</module>
21+
22+
<module name="TreeWalker">
23+
<!--
24+
Exceptions
25+
See https://checkstyle.sourceforge.io/config_filters.html
26+
-->
27+
<module name="SuppressionCommentFilter" />
28+
<module name="SuppressWithNearbyCommentFilter"/>
29+
30+
<!-- Checks for Javadoc comments. -->
31+
<!-- See https://checkstyle.org/config_javadoc.html -->
32+
<module name="InvalidJavadocPosition"/>
33+
34+
<!-- Checks for imports -->
35+
<!-- See https://checkstyle.org/config_imports.html -->
36+
<module name="AvoidStarImport"/>
37+
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
38+
<module name="RedundantImport"/>
39+
40+
<!-- Checks for whitespace -->
41+
<!-- See https://checkstyle.org/config_whitespace.html -->
42+
<module name="EmptyForIteratorPad"/>
43+
<module name="GenericWhitespace"/>
44+
<module name="MethodParamPad"/>
45+
<module name="NoWhitespaceAfter"/>
46+
<module name="NoWhitespaceBefore"/>
47+
<module name="OperatorWrap"/>
48+
<module name="ParenPad"/>
49+
<module name="TypecastParenPad"/>
50+
<module name="WhitespaceAfter"/>
51+
<module name="WhitespaceAround"/>
52+
53+
<!-- Modifier Checks -->
54+
<!-- See https://checkstyle.org/config_modifiers.html -->
55+
<module name="ModifierOrder"/>
56+
<module name="RedundantModifier"/>
57+
58+
<!-- Checks for blocks. You know, those {}'s -->
59+
<!-- See https://checkstyle.org/config_blocks.html -->
60+
<module name="AvoidNestedBlocks"/>
61+
<module name="EmptyBlock"/>
62+
<module name="LeftCurly"/>
63+
<module name="NeedBraces"/>
64+
<module name="RightCurly"/>
65+
66+
<!-- Checks for common coding problems -->
67+
<!-- See https://checkstyle.org/config_coding.html -->
68+
<module name="EmptyStatement"/>
69+
<module name="EqualsHashCode"/>
70+
<module name="IllegalInstantiation"/>
71+
<module name="InnerAssignment"/>
72+
<module name="MissingSwitchDefault"/>
73+
<module name="MultipleVariableDeclarations"/>
74+
<module name="SimplifyBooleanExpression"/>
75+
<module name="SimplifyBooleanReturn"/>
76+
77+
<!-- Checks for class design -->
78+
<!-- See https://checkstyle.org/config_design.html -->
79+
<module name="InterfaceIsType"/>
80+
81+
<!-- Miscellaneous other checks. -->
82+
<!-- See https://checkstyle.org/config_misc.html -->
83+
<module name="ArrayTypeStyle"/>
84+
<module name="TodoComment"/>
85+
<module name="UpperEll"/>
86+
</module>
87+
<module name="RegexpHeader">
88+
<property name="header" value="^/\*\*\n^ \* Licensed under the Apache License, Version 2\.0 \(the &quot;License&quot;\);"/>
89+
</module>
90+
</module>

src/main/java/net/logstash/logback/LogstashAccessFormatter.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
*/
1414
package net.logstash.logback;
1515

16+
import ch.qos.logback.access.spi.IAccessEvent;
17+
import ch.qos.logback.core.joran.spi.DefaultClass;
18+
import ch.qos.logback.core.spi.ContextAware;
1619
import net.logstash.logback.composite.ContextJsonProvider;
1720
import net.logstash.logback.composite.FieldNamesAware;
1821
import net.logstash.logback.composite.GlobalCustomFieldsJsonProvider;
@@ -37,9 +40,6 @@
3740
import net.logstash.logback.composite.accessevent.ResponseHeadersJsonProvider;
3841
import net.logstash.logback.composite.accessevent.StatusCodeJsonProvider;
3942
import net.logstash.logback.fieldnames.LogstashAccessFieldNames;
40-
import ch.qos.logback.access.spi.IAccessEvent;
41-
import ch.qos.logback.core.joran.spi.DefaultClass;
42-
import ch.qos.logback.core.spi.ContextAware;
4343

4444
import com.fasterxml.jackson.databind.JsonNode;
4545

@@ -159,7 +159,8 @@ public void setCustomFieldsFromString(String customFields) {
159159
globalCustomFieldsProvider = null;
160160
} else {
161161
if (globalCustomFieldsProvider == null) {
162-
getProviders().addGlobalCustomFields(globalCustomFieldsProvider = new GlobalCustomFieldsJsonProvider<IAccessEvent>());
162+
globalCustomFieldsProvider = new GlobalCustomFieldsJsonProvider<>();
163+
getProviders().addGlobalCustomFields(globalCustomFieldsProvider);
163164
}
164165
globalCustomFieldsProvider.setCustomFields(customFields);
165166
}
@@ -171,7 +172,8 @@ public void setCustomFields(JsonNode customFields) {
171172
globalCustomFieldsProvider = null;
172173
} else {
173174
if (globalCustomFieldsProvider == null) {
174-
getProviders().addGlobalCustomFields(globalCustomFieldsProvider = new GlobalCustomFieldsJsonProvider<IAccessEvent>());
175+
globalCustomFieldsProvider = new GlobalCustomFieldsJsonProvider<>();
176+
getProviders().addGlobalCustomFields(globalCustomFieldsProvider);
175177
}
176178
globalCustomFieldsProvider.setCustomFieldsNode(customFields);
177179
}

0 commit comments

Comments
 (0)