Skip to content

Commit 89c05e9

Browse files
authored
NIFI-14890 Aligned Maven PMD configuration with standard NiFi Rules (#19)
Signed-off-by: David Handermann <[email protected]>
1 parent 1c59ac8 commit 89c05e9

File tree

10 files changed

+101
-12
lines changed

10 files changed

+101
-12
lines changed

pmd-ruleset.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<ruleset name="Maven PMD Plugin Ruleset"
21+
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
24+
25+
<description>Default PMD Rules for Apache NiFi API</description>
26+
27+
<rule ref="category/java/bestpractices.xml/AvoidMessageDigestField" />
28+
<rule ref="category/java/bestpractices.xml/AvoidReassigningCatchVariables" />
29+
<rule ref="category/java/bestpractices.xml/DoubleBraceInitialization" />
30+
<rule ref="category/java/bestpractices.xml/ExhaustiveSwitchHasDefault" />
31+
<rule ref="category/java/bestpractices.xml/ForLoopCanBeForeach" />
32+
<rule ref="category/java/bestpractices.xml/LooseCoupling" />
33+
<rule ref="category/java/bestpractices.xml/MissingOverride" />
34+
<rule ref="category/java/bestpractices.xml/PrimitiveWrapperInstantiation" />
35+
<rule ref="category/java/bestpractices.xml/SimplifiableTestAssertion" />
36+
<rule ref="category/java/bestpractices.xml/UnusedPrivateField" />
37+
<rule ref="category/java/bestpractices.xml/UnnecessaryVarargsArrayCreation" />
38+
<rule ref="category/java/bestpractices.xml/UnusedLocalVariable" />
39+
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty" />
40+
<rule ref="category/java/bestpractices.xml/UseStandardCharsets" />
41+
42+
<rule ref="category/java/codestyle.xml/AvoidDollarSigns" />
43+
<rule ref="category/java/codestyle.xml/ExtendsObject" />
44+
<rule ref="category/java/codestyle.xml/IdenticalCatchBranches" />
45+
<rule ref="category/java/codestyle.xml/ForLoopShouldBeWhileLoop" />
46+
<rule ref="category/java/codestyle.xml/UnnecessaryConstructor" />
47+
<rule ref="category/java/codestyle.xml/UnnecessaryImport" />
48+
<rule ref="category/java/codestyle.xml/UnnecessaryModifier" />
49+
<rule ref="category/java/codestyle.xml/UnnecessarySemicolon" />
50+
<rule ref="category/java/codestyle.xml/UseDiamondOperator" />
51+
<rule ref="category/java/codestyle.xml/UseExplicitTypes" />
52+
53+
<rule ref="category/java/errorprone.xml/AvoidAssertAsIdentifier" />
54+
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor" />
55+
<rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators" />
56+
<rule ref="category/java/errorprone.xml/AvoidUsingOctalValues" />
57+
<rule ref="category/java/errorprone.xml/BrokenNullCheck" />
58+
<rule ref="category/java/errorprone.xml/CheckSkipResult" />
59+
<rule ref="category/java/errorprone.xml/ClassCastExceptionWithToArray" />
60+
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices" />
61+
<rule ref="category/java/errorprone.xml/EmptyCatchBlock" />
62+
<rule ref="category/java/errorprone.xml/ImplicitSwitchFallThrough" />
63+
<rule ref="category/java/errorprone.xml/JumbledIncrementer" />
64+
<rule ref="category/java/errorprone.xml/MisplacedNullCheck" />
65+
<rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock" />
66+
<rule ref="category/java/errorprone.xml/UnconditionalIfStatement" />
67+
<rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary" />
68+
<rule ref="category/java/errorprone.xml/UselessOperationOnImmutable" />
69+
70+
<rule ref="category/java/multithreading.xml/AvoidThreadGroup" />
71+
<rule ref="category/java/multithreading.xml/DontCallThreadRun" />
72+
<rule ref="category/java/multithreading.xml/DoubleCheckedLocking" />
73+
<rule ref="category/java/multithreading.xml/UnsynchronizedStaticFormatter" />
74+
75+
<rule ref="category/java/performance.xml/BigIntegerInstantiation" />
76+
<rule ref="category/java/performance.xml/InefficientEmptyStringCheck" />
77+
<rule ref="category/java/performance.xml/StringInstantiation" />
78+
<rule ref="category/java/performance.xml/StringToString" />
79+
<rule ref="category/java/performance.xml/TooFewBranchesForSwitch">
80+
<properties>
81+
<property name="minimumNumberCaseForASwitch" value="2" />
82+
</properties>
83+
</rule>
84+
<rule ref="category/java/performance.xml/UselessStringValueOf" />
85+
<rule ref="category/java/performance.xml/UseStringBufferForStringAppends" />
86+
</ruleset>

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@
249249
<printFailingErrors>true</printFailingErrors>
250250
<linkXRef>false</linkXRef>
251251
<targetJdk>${maven.compiler.release}</targetJdk>
252+
<rulesets>
253+
<ruleset>${maven.multiModuleProjectDirectory}/pmd-ruleset.xml</ruleset>
254+
</rulesets>
252255
</configuration>
253256
<executions>
254257
<execution>

src/main/java/org/apache/nifi/components/PropertyDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public <E extends Enum<E>> Builder allowableValues(final Class<E> enumClass) {
428428
* @param <E> generic parameter for an enum class, that may implement the DescribedValue interface
429429
* @return the builder
430430
*/
431-
public <E extends Enum<E>> Builder allowableValues(final EnumSet<E> enumValues) {
431+
public <E extends Enum<E>> Builder allowableValues(final EnumSet<E> enumValues) { //NOPMD
432432
if (null != enumValues) {
433433
this.allowableValues = enumValues.stream()
434434
.map(enumValue -> enumValue instanceof DescribedValue describedValue

src/main/java/org/apache/nifi/components/resource/StandardResourceReferenceFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class StandardResourceReferenceFactory implements ResourceReferenceFactor
3030

3131
private static final ResourceReferences EMPTY_RESOURCE_REFERENCES = new StandardResourceReferences(Collections.emptyList());
3232

33+
@Override
3334
public ResourceReferences createResourceReferences(final String value, final ResourceDefinition resourceDefinition) {
3435
if (value == null) {
3536
return EMPTY_RESOURCE_REFERENCES;
@@ -52,6 +53,7 @@ public ResourceReferences createResourceReferences(final String value, final Res
5253
return new StandardResourceReferences(references);
5354
}
5455

56+
@Override
5557
public ResourceReference createResourceReference(final String value, final ResourceDefinition resourceDefinition) {
5658
if (value == null) {
5759
return null;

src/main/java/org/apache/nifi/documentation/xml/XmlDocumentationWriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ private void writeUseCase(final UseCase useCase) throws IOException {
401401
writeEndElement();
402402
}
403403

404+
@Override
404405
protected void writeMultiProcessorUseCases(final List<MultiProcessorUseCase> multiProcessorUseCases) throws IOException {
405406
if (multiProcessorUseCases.isEmpty()) {
406407
return;

src/main/java/org/apache/nifi/flowfile/FlowFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ public static String validateKey(final String key) {
120120
if (key == null) {
121121
throw new IllegalArgumentException("Invalid attribute key: null");
122122
}
123-
if (key.trim().isEmpty()) {
123+
if (key.isBlank()) {
124124
throw new IllegalArgumentException("Invalid attribute key: <Empty String>");
125125
}
126126
return key;
127127
}
128128

129129
public static boolean isValid(final String key) {
130-
return key != null && !key.trim().isEmpty();
130+
return key != null && !key.isBlank();
131131
}
132132
}
133133
}

src/main/java/org/apache/nifi/processor/exception/TerminatedTaskException.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,4 @@
3131
* Process Sessions
3232
*/
3333
public class TerminatedTaskException extends ProcessException {
34-
public TerminatedTaskException() {
35-
super();
36-
}
3734
}

src/main/java/org/apache/nifi/processor/util/StandardValidators.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public ValidationResult validate(String subject, String input, ValidationContext
224224
@Override
225225
public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
226226
return new ValidationResult.Builder().subject(subject).input(value)
227-
.valid(value != null && !value.trim().isEmpty())
227+
.valid(value != null && !value.isBlank())
228228
.explanation(subject
229229
+ " must contain at least one character that is not white space").build();
230230
}
@@ -426,7 +426,7 @@ public ValidationResult validate(final String subject, final String input, final
426426
}
427427

428428
Optional<ValidationResult> invalidUri = Arrays.stream(input.split(","))
429-
.filter(uri -> uri != null && !uri.trim().isEmpty())
429+
.filter(uri -> uri != null && !uri.isBlank())
430430
.map(String::trim)
431431
.map((uri) -> URI_VALIDATOR.validate(subject, uri, context)).filter((uri) -> !uri.isValid()).findFirst();
432432

@@ -939,7 +939,7 @@ public ValidationResult validate(final String subject, final String value, final
939939
.explanation("Not a valid Expression Language value: " + e.getMessage()).build();
940940
}
941941

942-
if (substituted.trim().isEmpty() && !value.trim().isEmpty()) {
942+
if (substituted.isBlank() && !value.isBlank()) {
943943
// User specified an Expression and nothing more... assume valid.
944944
return new ValidationResult.Builder().subject(subject).input(value).valid(true).build();
945945
}

src/main/java/org/apache/nifi/registry/VariableDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static final class Builder {
116116
* @param name of the property
117117
*/
118118
public Builder(final String name) {
119-
if (null == name || name.trim().isEmpty()) {
119+
if (null == name || name.isBlank()) {
120120
throw new IllegalArgumentException("Name must not be null or empty");
121121
}
122122
this.name = name.trim();

src/main/java/org/apache/nifi/time/DurationFormat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ static List<Object> makeWholeNumberTime(double decimal, TimeUnit timeUnit) {
140140
// If the value is already a whole number, return it and the current time unit
141141
if (decimal == Math.rint(decimal)) {
142142
final long rounded = Math.round(decimal);
143-
return Arrays.asList(new Object[]{rounded, timeUnit});
143+
return Arrays.asList(rounded, timeUnit);
144144
} else if (TimeUnit.NANOSECONDS == timeUnit) {
145145
// The time unit is as small as possible
146146
if (decimal < 1.0) {
147147
decimal = 1;
148148
} else {
149149
decimal = Math.rint(decimal);
150150
}
151-
return Arrays.asList(new Object[]{(long) decimal, timeUnit});
151+
return Arrays.asList((long) decimal, timeUnit);
152152
} else {
153153
// Determine the next time unit and the respective multiplier
154154
TimeUnit smallerTimeUnit = getSmallerTimeUnit(timeUnit);

0 commit comments

Comments
 (0)