Skip to content

Commit 4dbaff6

Browse files
committed
Fix pmd setup and various code style issues
1 parent 6bca577 commit 4dbaff6

38 files changed

Lines changed: 355 additions & 62 deletions
File renamed without changes.
File renamed without changes.

config/pmd/pmd-rulesets.xml

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
<?xml version="1.0"?>
2+
3+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
name="Proxer"
5+
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
6+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
7+
8+
<description>
9+
The Proxer ruleset.
10+
</description>
11+
12+
<!-- Basic -->
13+
14+
<rule ref="category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop"/>
15+
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor"/>
16+
<rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators"/>
17+
<rule ref="category/java/errorprone.xml/AvoidUsingOctalValues"/>
18+
<rule ref="category/java/errorprone.xml/BrokenNullCheck"/>
19+
<rule ref="category/java/errorprone.xml/CheckSkipResult"/>
20+
<rule ref="category/java/errorprone.xml/ClassCastExceptionWithToArray"/>
21+
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices"/>
22+
<rule ref="category/java/errorprone.xml/JumbledIncrementer"/>
23+
<rule ref="category/java/errorprone.xml/MisplacedNullCheck"/>
24+
<rule ref="category/java/errorprone.xml/OverrideBothEqualsAndHashcode"/>
25+
<rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock"/>
26+
<rule ref="category/java/errorprone.xml/UnconditionalIfStatement"/>
27+
<rule ref="category/java/multithreading.xml/AvoidThreadGroup"/>
28+
<rule ref="category/java/multithreading.xml/DontCallThreadRun"/>
29+
<rule ref="category/java/multithreading.xml/DoubleCheckedLocking"/>
30+
<rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP"/>
31+
<rule ref="category/java/bestpractices.xml/CheckResultSet"/>
32+
<rule ref="category/java/codestyle.xml/ExtendsObject"/>
33+
<rule ref="category/java/codestyle.xml/ForLoopShouldBeWhileLoop"/>
34+
<rule ref="category/java/performance.xml/BigIntegerInstantiation"/>
35+
<rule ref="category/java/performance.xml/BooleanInstantiation"/>
36+
<rule ref="category/java/design.xml/CollapsibleIfStatements"/>
37+
<rule ref="category/java/design.xml/SimplifiedTernary"/>
38+
39+
<!-- Braces -->
40+
41+
<rule ref="category/java/codestyle.xml/ForLoopsMustUseBraces"/>
42+
<rule ref="category/java/codestyle.xml/IfElseStmtsMustUseBraces"/>
43+
<rule ref="category/java/codestyle.xml/IfStmtsMustUseBraces"/>
44+
<rule ref="category/java/codestyle.xml/WhileLoopsMustUseBraces"/>
45+
46+
<!-- Clone -->
47+
48+
<rule ref="category/java/errorprone.xml/CloneMethodMustBePublic"/>
49+
<rule ref="category/java/errorprone.xml/CloneMethodMustImplementCloneable"/>
50+
<rule ref="category/java/errorprone.xml/CloneMethodReturnTypeMustMatchClassName"/>
51+
<rule ref="category/java/errorprone.xml/CloneThrowsCloneNotSupportedException"/>
52+
<rule ref="category/java/errorprone.xml/ProperCloneImplementation"/>
53+
54+
<!-- Comments -->
55+
56+
<rule ref="category/java/documentation.xml/CommentContent"/>
57+
58+
<!-- Design -->
59+
60+
<rule ref="category/java/design.xml/AbstractClassWithoutAnyMethod"/>
61+
<rule ref="category/java/design.xml/AvoidDeeplyNestedIfStmts"/>
62+
<rule ref="category/java/design.xml/ClassWithOnlyPrivateConstructorsShouldBeFinal"/>
63+
<rule ref="category/java/design.xml/DataClass"/>
64+
<rule ref="category/java/design.xml/FinalFieldCouldBeStatic"/>
65+
<rule ref="category/java/design.xml/GodClass"/>
66+
<rule ref="category/java/design.xml/ImmutableField"/>
67+
<rule ref="category/java/design.xml/LogicInversion"/>
68+
<rule ref="category/java/design.xml/SimplifyBooleanExpressions"/>
69+
<rule ref="category/java/design.xml/SimplifyBooleanReturns"/>
70+
<rule ref="category/java/design.xml/SimplifyConditional"/>
71+
<rule ref="category/java/design.xml/SingularField"/>
72+
<rule ref="category/java/design.xml/SwitchDensity"/>
73+
<rule ref="category/java/design.xml/UseUtilityClass"/>
74+
<rule ref="category/java/errorprone.xml/AssignmentToNonFinalStatic"/>
75+
<rule ref="category/java/errorprone.xml/AvoidInstanceofChecksInCatchClause"/>
76+
<rule ref="category/java/errorprone.xml/BadComparison"/>
77+
<rule ref="category/java/errorprone.xml/CloseResource"/>
78+
<rule ref="category/java/errorprone.xml/CompareObjectsWithEquals"/>
79+
<rule ref="category/java/errorprone.xml/ConstructorCallsOverridableMethod"/>
80+
<rule ref="category/java/errorprone.xml/EqualsNull"/>
81+
<rule ref="category/java/errorprone.xml/IdempotentOperations"/>
82+
<rule ref="category/java/errorprone.xml/InstantiationToGetClass"/>
83+
<rule ref="category/java/errorprone.xml/MissingBreakInSwitch"/>
84+
<rule ref="category/java/errorprone.xml/MissingStaticMethodInNonInstantiatableClass"/>
85+
<rule ref="category/java/errorprone.xml/NonCaseLabelInSwitchStatement"/>
86+
<rule ref="category/java/errorprone.xml/NonStaticInitializer"/>
87+
<rule ref="category/java/errorprone.xml/ReturnEmptyArrayRatherThanNull"/>
88+
<rule ref="category/java/errorprone.xml/SimpleDateFormatNeedsLocale"/>
89+
<rule ref="category/java/errorprone.xml/SingleMethodSingleton"/>
90+
<rule ref="category/java/errorprone.xml/SingletonClassReturningNewInstance"/>
91+
<rule ref="category/java/errorprone.xml/UseLocaleWithCaseConversions"/>
92+
<rule ref="category/java/codestyle.xml/AvoidProtectedFieldInFinalClass"/>
93+
<rule ref="category/java/codestyle.xml/AvoidProtectedMethodInFinalClassNotExtending"/>
94+
<rule ref="category/java/codestyle.xml/EmptyMethodInAbstractClassShouldBeAbstract"/>
95+
<rule ref="category/java/codestyle.xml/FieldDeclarationsShouldBeAtStartOfClass"/>
96+
<rule ref="category/java/codestyle.xml/UnnecessaryLocalBeforeReturn"/>
97+
<rule ref="category/java/multithreading.xml/AvoidSynchronizedAtMethodLevel"/>
98+
<rule ref="category/java/multithreading.xml/NonThreadSafeSingleton"/>
99+
<rule ref="category/java/multithreading.xml/UnsynchronizedStaticDateFormatter"/>
100+
<rule ref="category/java/multithreading.xml/UseNotifyAllInsteadOfNotify"/>
101+
<rule ref="category/java/bestpractices.xml/AbstractClassWithoutAbstractMethod"/>
102+
<rule ref="category/java/bestpractices.xml/AvoidReassigningParameters"/>
103+
<rule ref="category/java/bestpractices.xml/ConstantsInInterface"/>
104+
<rule ref="category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt"/>
105+
<rule ref="category/java/bestpractices.xml/PositionLiteralsFirstInCaseInsensitiveComparisons"/>
106+
<rule ref="category/java/bestpractices.xml/PositionLiteralsFirstInComparisons"/>
107+
<rule ref="category/java/bestpractices.xml/PreserveStackTrace"/>
108+
<rule ref="category/java/bestpractices.xml/SwitchStmtsShouldHaveDefault"/>
109+
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty"/>
110+
<rule ref="category/java/bestpractices.xml/UseVarargs"/>
111+
<rule ref="category/java/performance.xml/OptimizableToArrayCall"/>
112+
<rule ref="category/java/performance.xml/TooFewBranchesForASwitchStatement"/>
113+
<rule ref="category/java/documentation.xml/UncommentedEmptyConstructor"/>
114+
<rule ref="category/java/documentation.xml/UncommentedEmptyMethodBody"/>
115+
116+
<!-- Empty -->
117+
118+
<rule ref="category/java/errorprone.xml/EmptyCatchBlock"/>
119+
<rule ref="category/java/errorprone.xml/EmptyFinallyBlock"/>
120+
<rule ref="category/java/errorprone.xml/EmptyIfStmt"/>
121+
<rule ref="category/java/errorprone.xml/EmptyInitializer"/>
122+
<rule ref="category/java/errorprone.xml/EmptyStatementBlock"/>
123+
<rule ref="category/java/errorprone.xml/EmptyStatementNotInLoop"/>
124+
<rule ref="category/java/errorprone.xml/EmptyInitializer" name="EmptyStaticInitializer"/>
125+
<rule ref="category/java/errorprone.xml/EmptySwitchStatements"/>
126+
<rule ref="category/java/errorprone.xml/EmptySynchronizedBlock"/>
127+
<rule ref="category/java/errorprone.xml/EmptyTryBlock"/>
128+
<rule ref="category/java/errorprone.xml/EmptyWhileStmt"/>
129+
130+
<!-- Finalizers -->
131+
132+
<rule ref="category/java/errorprone.xml/AvoidCallingFinalize"/>
133+
<rule ref="category/java/errorprone.xml/EmptyFinalizer"/>
134+
<rule ref="category/java/errorprone.xml/FinalizeDoesNotCallSuperFinalize"/>
135+
<rule ref="category/java/errorprone.xml/FinalizeOnlyCallsSuperFinalize"/>
136+
<rule ref="category/java/errorprone.xml/FinalizeOverloaded"/>
137+
<rule ref="category/java/errorprone.xml/FinalizeShouldBeProtected"/>
138+
139+
<!-- Imports -->
140+
141+
<rule ref="category/java/bestpractices.xml/UnusedImports"/>
142+
<rule ref="category/java/errorprone.xml/ImportFromSamePackage"/>
143+
<rule ref="category/java/codestyle.xml/DontImportJavaLang"/>
144+
<rule ref="category/java/codestyle.xml/DuplicateImports"/>
145+
<rule ref="category/java/codestyle.xml/TooManyStaticImports"/>
146+
<rule ref="category/java/codestyle.xml/UnnecessaryFullyQualifiedName"/>
147+
148+
<!-- Naming -->
149+
150+
<rule ref="category/java/errorprone.xml/MethodWithSameNameAsEnclosingClass"/>
151+
<rule ref="category/java/errorprone.xml/SuspiciousEqualsMethodName"/>
152+
<rule ref="category/java/errorprone.xml/SuspiciousHashcodeMethodName"/>
153+
<rule ref="category/java/codestyle.xml/AvoidDollarSigns"/>
154+
<rule ref="category/java/codestyle.xml/BooleanGetMethodName"/>
155+
<rule ref="category/java/codestyle.xml/ClassNamingConventions"/>
156+
<rule ref="category/java/codestyle.xml/GenericsNaming"/>
157+
<rule ref="category/java/codestyle.xml/MethodNamingConventions"/>
158+
<rule ref="category/java/codestyle.xml/MIsLeadingVariableName"/>
159+
<rule ref="category/java/codestyle.xml/NoPackage"/>
160+
<rule ref="category/java/codestyle.xml/PackageCase"/>
161+
<rule ref="category/java/codestyle.xml/SuspiciousConstantFieldName"/>
162+
<rule ref="category/java/codestyle.xml/VariableNamingConventions"/>
163+
164+
<!-- Optimizations -->
165+
166+
<rule ref="category/java/codestyle.xml/LocalVariableCouldBeFinal"/>
167+
<rule ref="category/java/codestyle.xml/MethodArgumentCouldBeFinal"/>
168+
<rule ref="category/java/codestyle.xml/PrematureDeclaration"/>
169+
<rule ref="category/java/performance.xml/AddEmptyString"/>
170+
<rule ref="category/java/performance.xml/AvoidArrayLoops"/>
171+
<rule ref="category/java/performance.xml/RedundantFieldInitializer"/>
172+
<rule ref="category/java/performance.xml/SimplifyStartsWith"/>
173+
<rule ref="category/java/performance.xml/UnnecessaryWrapperObjectCreation"/>
174+
<rule ref="category/java/performance.xml/UseArrayListInsteadOfVector"/>
175+
<rule ref="category/java/performance.xml/UseArraysAsList"/>
176+
<rule ref="category/java/performance.xml/UseStringBufferForStringAppends"/>
177+
178+
<!-- Strict Exception -->
179+
180+
<rule ref="category/java/errorprone.xml/AvoidCatchingNPE"/>
181+
<rule ref="category/java/errorprone.xml/AvoidCatchingThrowable"/>
182+
<rule ref="category/java/errorprone.xml/AvoidLosingExceptionInformation"/>
183+
<rule ref="category/java/errorprone.xml/DoNotThrowExceptionInFinally"/>
184+
<rule ref="category/java/design.xml/AvoidCatchingGenericException"/>
185+
<rule ref="category/java/design.xml/AvoidRethrowingException"/>
186+
<rule ref="category/java/design.xml/AvoidThrowingNewInstanceOfSameException"/>
187+
<rule ref="category/java/design.xml/AvoidThrowingRawExceptionTypes"/>
188+
<rule ref="category/java/design.xml/DoNotExtendJavaLangError"/>
189+
<rule ref="category/java/design.xml/ExceptionAsFlowControl"/>
190+
<rule ref="category/java/design.xml/SignatureDeclareThrowsException"/>
191+
192+
<!-- Strings -->
193+
194+
<rule ref="category/java/errorprone.xml/StringBufferInstantiationWithChar"/>
195+
<rule ref="category/java/errorprone.xml/UnnecessaryCaseChange"/>
196+
<rule ref="category/java/errorprone.xml/UseEqualsToCompareStrings"/>
197+
<rule ref="category/java/bestpractices.xml/AvoidStringBufferField"/>
198+
<rule ref="category/java/performance.xml/AppendCharacterWithChar"/>
199+
<rule ref="category/java/performance.xml/ConsecutiveAppendsShouldReuse"/>
200+
<rule ref="category/java/performance.xml/ConsecutiveLiteralAppends"/>
201+
<rule ref="category/java/performance.xml/InefficientEmptyStringCheck"/>
202+
<rule ref="category/java/performance.xml/InefficientStringBuffering"/>
203+
<rule ref="category/java/performance.xml/InsufficientStringBufferDeclaration"/>
204+
<rule ref="category/java/performance.xml/StringInstantiation"/>
205+
<rule ref="category/java/performance.xml/StringToString"/>
206+
<rule ref="category/java/performance.xml/UseIndexOfChar"/>
207+
<rule ref="category/java/performance.xml/UselessStringValueOf"/>
208+
<rule ref="category/java/performance.xml/UseStringBufferLength"/>
209+
210+
<!-- Type Resolution -->
211+
212+
<rule ref="category/java/bestpractices.xml/LooseCoupling"/>
213+
<rule ref="category/java/errorprone.xml/CloneMethodMustImplementCloneable"/>
214+
<rule ref="category/java/bestpractices.xml/UnusedImports"/>
215+
<rule ref="category/java/design.xml/SignatureDeclareThrowsException"/>
216+
217+
<!-- Unnecessary -->
218+
219+
<rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary"/>
220+
<rule ref="category/java/errorprone.xml/UnusedNullCheckInEquals"/>
221+
<rule ref="category/java/errorprone.xml/UselessOperationOnImmutable"/>
222+
<rule ref="category/java/codestyle.xml/UnnecessaryModifier"/>
223+
<rule ref="category/java/codestyle.xml/UnnecessaryReturn"/>
224+
<rule ref="category/java/codestyle.xml/UselessParentheses"/>
225+
<rule ref="category/java/codestyle.xml/UselessQualifiedThis"/>
226+
<rule ref="category/java/design.xml/UselessOverridingMethod"/>
227+
228+
<!-- Unused Code -->
229+
230+
<rule ref="category/java/bestpractices.xml/UnusedFormalParameter"/>
231+
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/>
232+
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/>
233+
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/>
234+
235+
</ruleset>

library/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,16 @@ checkstyle {
160160
}
161161

162162
findbugs {
163-
excludeFilter = file('config/findbugs/findbugs-filter.xml')
163+
excludeFilter = rootProject.file('config/findbugs/findbugs-filter.xml')
164164
sourceSets = [sourceSets.main]
165165

166166
setToolVersion(findbugsVersion)
167167
}
168168

169169
pmd {
170+
ruleSetFiles = rootProject.files("config/pmd/pmd-rulesets.xml")
171+
ruleSets = []
172+
170173
setToolVersion(pmdVersion)
171174
}
172175

library/src/main/java/me/proxer/library/api/BooleanAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
class BooleanAdapter {
99

10-
private PrimitiveBooleanAdapter delegate = new PrimitiveBooleanAdapter();
10+
private final PrimitiveBooleanAdapter delegate = new PrimitiveBooleanAdapter();
1111

1212
@FromJson
1313
Boolean fromJson(final Object json) {

library/src/main/java/me/proxer/library/api/DateAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.text.ParseException;
88
import java.text.SimpleDateFormat;
99
import java.util.Date;
10+
import java.util.Locale;
1011

1112
/**
1213
* @author Ruben Gees
@@ -23,7 +24,7 @@ Date fromJson(final String date) throws ParseException {
2324
if (dateAsLong != null) {
2425
return new Date(dateAsLong * DATE_MULTIPLICAND);
2526
} else {
26-
return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(date);
27+
return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.GERMANY).parse(date);
2728
}
2829
}
2930

library/src/main/java/me/proxer/library/api/EpisodeInfoAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EpisodeInfoAdapter {
2929
EpisodeInfo fromJson(final IntermediateEpisodeInfo json) {
3030
final List<Episode> episodes = new ArrayList<>(json.episodes.size());
3131

32-
for (IntermediateEpisode episode : json.episodes) {
32+
for (final IntermediateEpisode episode : json.episodes) {
3333
if (json.category == Category.ANIME) {
3434
episodes.add(new AnimeEpisode(episode.number, episode.language,
3535
new HashSet<>(Arrays.asList(episode.hosters.split(DELIMITER))),

library/src/main/java/me/proxer/library/api/LoggingInterceptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.AllArgsConstructor;
44
import me.proxer.library.api.ProxerApi.Builder.LoggingStrategy;
55
import me.proxer.library.util.ProxerUrls;
6+
import me.proxer.library.util.ProxerUtils;
67
import okhttp3.Interceptor;
78
import okhttp3.Request;
89
import okhttp3.RequestBody;
@@ -63,7 +64,7 @@ private String buildBodyMessage(final Request requestCopy) throws IOException {
6364

6465
if (bodyContent == null) {
6566
return "";
66-
} else if (bodyContent.trim().isEmpty()) {
67+
} else if (ProxerUtils.isBlank(bodyContent)) {
6768
return "\nand a blank body.";
6869
} else {
6970
return "\nand this body:\n" + bodyContent;

library/src/main/java/me/proxer/library/api/NotificationInfoAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class NotificationInfoAdapter {
1717
private static final int NOTIFICATIONS_FIELD_LOCATION = 5;
1818

1919
@FromJson
20+
@SuppressWarnings("PMD.UseVarargs")
2021
NotificationInfo fromJson(final int[] json) {
2122
if (json.length != FIELD_AMOUNT) {
2223
throw new JsonDataException("Invalid json array size: " + json.length);

0 commit comments

Comments
 (0)