Skip to content

Commit d9526da

Browse files
fix: PMD errors
1 parent 4252a22 commit d9526da

29 files changed

Lines changed: 88 additions & 106 deletions

pmd-ruleset.xml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<ruleset name="Translation API RuleSet"
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
name="Translation-API PMD RuleSet"
34
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
66

7-
<description>Translation API RuleSet</description>
7+
<description>Translation-API PMD RuleSet</description>
88

99
<rule ref="category/java/design.xml/LoosePackageCoupling">
1010
<properties>
11-
<property name="packages" value="com.sitepark.ies.contentrepository.core"/>
11+
<property name="packages" value="com.sitepark.ies.userrepository.core"/>
1212
</properties>
1313
</rule>
1414

15-
<rule ref="category/java/design.xml/LawOfDemeter">
15+
<rule ref="category/java/errorprone.xml/AvoidFieldNameMatchingMethodName">
1616
<properties>
1717
<property name="violationSuppressXPath"
18-
value="./ancestor-or-self::ClassDeclaration[matches(@PackageName, '.*\.usecase|.*\.domain\.entity|.*\.domain\.entity\.sort')]"/>
18+
value="./ancestor-or-self::ClassDeclaration[matches(@SimpleName, '^.*Builder')]"/>
1919
</properties>
2020
</rule>
2121

22-
<rule ref="category/java/errorprone.xml/AvoidFieldNameMatchingMethodName">
22+
<rule ref="category/java/design.xml/LawOfDemeter">
2323
<properties>
2424
<property name="violationSuppressXPath"
25-
value="./ancestor-or-self::ClassDeclaration[matches(@SimpleName, '^.*Builder')]"/>
25+
value="./ancestor-or-self::ClassDeclaration[matches(@PackageName, '.*')]"/>
2626
</properties>
2727
</rule>
2828

@@ -40,7 +40,6 @@
4040
</properties>
4141
</rule>
4242

43-
4443
<!-- Best Practices -->
4544
<rule ref="category/java/bestpractices.xml"/>
4645

@@ -59,5 +58,4 @@
5958
<!-- Multithreading -->
6059
<rule ref="category/java/multithreading.xml"/>
6160

62-
6361
</ruleset>

spotbug-exclude-filter.xml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<FindBugsFilter
3-
xmlns="https://github.com/spotbugs/filter/3.0.0"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
6-
3+
xmlns="https://github.com/spotbugs/filter/3.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
76

87
<!-- https://spotbugs.readthedocs.io/en/stable/filter.html -->
98
<Match>
109
<Bug
11-
pattern="REC_CATCH_EXCEPTION,RV_CHECK_FOR_POSITIVE_INDEXOF,BC_UNCONFIRMED_CAST_OF_RETURN_VALUE,THROWS_METHOD_THROWS_CLAUSE_THROWABLE,PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES" />
12-
</Match>
13-
14-
<Match>
15-
<Class name="~com.sitepark.ies.contentrepository.core.usecase.*" />
16-
<Method name="&lt;init&gt;"/>
17-
<Bug pattern="EI_EXPOSE_REP2" />
10+
pattern="REC_CATCH_EXCEPTION,RV_CHECK_FOR_POSITIVE_INDEXOF,BC_UNCONFIRMED_CAST_OF_RETURN_VALUE,THROWS_METHOD_THROWS_CLAUSE_THROWABLE,PI_DO_NOT_REUSE_PUBLIC_IDENTIFIERS_CLASS_NAMES"/>
1811
</Match>
1912

2013
<!-- False positive: https://github.com/spotbugs/spotbugs/issues/2628 -->
2114
<Match>
22-
<Class name="~.*\.*Test" />
23-
<Bug pattern="RV_EXCEPTION_NOT_THROWN" />
15+
<Class name="~.*\.*Test"/>
16+
<Bug pattern="RV_EXCEPTION_NOT_THROWN"/>
2417
</Match>
25-
2618
</FindBugsFilter>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.sitepark.translate;
22

3+
@SuppressWarnings("PMD.ImplicitFunctionalInterface")
34
public interface TranslationProviderConfiguration {
45
public SupportedProvider getType();
56
}

src/main/java/com/sitepark/translate/provider/deepl/GlossaryResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import java.time.OffsetDateTime;
55

6+
@SuppressWarnings("PMD.DataClass")
67
public class GlossaryResponse {
78
@JsonProperty("glossary_id")
89
public String glossaryId;

src/main/java/com/sitepark/translate/provider/libretranslate/TransportRequest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Arrays;
66
import java.util.Objects;
77

8+
@SuppressWarnings("PMD.DataClass")
89
public final class TransportRequest {
910

1011
private final String[] q;
@@ -25,6 +26,10 @@ private TransportRequest(Builder builder) {
2526
this.apiKey = builder.apiKey;
2627
}
2728

29+
public static Builder builder() {
30+
return new Builder();
31+
}
32+
2833
public String[] getQ() {
2934
return Arrays.copyOf(this.q, this.q.length);
3035
}
@@ -46,10 +51,6 @@ public String getApiKey() {
4651
return this.apiKey;
4752
}
4853

49-
public static Builder builder() {
50-
return new Builder();
51-
}
52-
5354
public Builder toBuilder() {
5455
return new Builder(this);
5556
}

src/main/java/com/sitepark/translate/translator/JsonFileTranslator.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,15 @@
2828
})
2929
public final class JsonFileTranslator extends Translator {
3030

31+
private static final String EN_US = "en-us";
3132
private final Path dir;
32-
3333
private final Path output;
34-
3534
private final String sourceLang;
36-
3735
private final String sourceSuffix;
38-
3936
private final Set<String> targetLangList;
40-
4137
private final Logger logger;
42-
4338
private List<JsonFile> jsonFiles;
44-
4539
private List<TranslatableTextNode> translatableTextNodeList;
46-
4740
private TranslatableTextNodeCollectorExcludes excludes;
4841

4942
private JsonFileTranslator(Builder builder) {
@@ -101,7 +94,7 @@ public void translate(SupportedProvider provider, List<String> targets) throws I
10194
+ duration
10295
+ " seconds.");
10396
this.write(targetLanguage);
104-
if (targetLanguage.equals("en-us")) {
97+
if (EN_US.equals(targetLanguage)) {
10598
this.write("en");
10699
}
107100
}

src/test/java/com/sitepark/translate/GlossaryChangeSetTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class GlossaryChangeSetTest {
1010

1111
@Test
1212
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
13-
public void testEqualsContract() {
13+
void testEqualsContract() {
1414
EqualsVerifier.forClass(GlossaryChangeSet.class).verify();
1515
}
1616

1717
@Test
18-
public void testAdded() {
18+
void testAdded() {
1919

2020
GlossaryChangeSet changeSet = new GlossaryChangeSet();
2121
GlossaryEntry entry = GlossaryEntry.builder().source("Hallo").target("Hello").build();
@@ -26,7 +26,7 @@ public void testAdded() {
2626
}
2727

2828
@Test
29-
public void testDeleted() {
29+
void testDeleted() {
3030

3131
GlossaryChangeSet changeSet = new GlossaryChangeSet();
3232
GlossaryEntry entry = GlossaryEntry.builder().source("Hallo").target("Hello").build();

src/test/java/com/sitepark/translate/GlossaryEntryTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ class GlossaryEntryTest {
1010

1111
@Test
1212
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
13-
public void testEqualsContract() {
13+
void testEqualsContract() {
1414
EqualsVerifier.forClass(GlossaryEntry.class).verify();
1515
}
1616

1717
@Test
18-
public void testSetSource() {
18+
void testSetSource() {
1919
GlossaryEntry entry = GlossaryEntry.builder().source("de").target("en").build();
2020
assertEquals("de", entry.getSource(), "unexpected source");
2121
}
2222

2323
@Test
24-
public void testNullSource() {
24+
void testNullSource() {
2525
assertThrows(
2626
NullPointerException.class,
2727
() -> {
@@ -31,7 +31,7 @@ public void testNullSource() {
3131
}
3232

3333
@Test
34-
public void testBlankSource() {
34+
void testBlankSource() {
3535
assertThrows(
3636
IllegalArgumentException.class,
3737
() -> {
@@ -41,7 +41,7 @@ public void testBlankSource() {
4141
}
4242

4343
@Test
44-
public void testUnsetSource() {
44+
void testUnsetSource() {
4545
assertThrows(
4646
IllegalStateException.class,
4747
() -> {
@@ -51,13 +51,13 @@ public void testUnsetSource() {
5151
}
5252

5353
@Test
54-
public void testSetTarget() {
54+
void testSetTarget() {
5555
GlossaryEntry entry = GlossaryEntry.builder().source("de").target("en").build();
5656
assertEquals("en", entry.getTarget(), "unexpected source");
5757
}
5858

5959
@Test
60-
public void testNullTarget() {
60+
void testNullTarget() {
6161
assertThrows(
6262
NullPointerException.class,
6363
() -> {
@@ -67,7 +67,7 @@ public void testNullTarget() {
6767
}
6868

6969
@Test
70-
public void testBlankTarget() {
70+
void testBlankTarget() {
7171
assertThrows(
7272
IllegalArgumentException.class,
7373
() -> {
@@ -77,7 +77,7 @@ public void testBlankTarget() {
7777
}
7878

7979
@Test
80-
public void testUnsetTarget() {
80+
void testUnsetTarget() {
8181
assertThrows(
8282
IllegalStateException.class,
8383
() -> {
@@ -87,7 +87,8 @@ public void testUnsetTarget() {
8787
}
8888

8989
@Test
90-
public void testToBuilder() {
90+
@SuppressWarnings("PMD.UnitTestContainsTooManyAsserts")
91+
void testToBuilder() {
9192

9293
GlossaryEntry entry = GlossaryEntry.builder().source("de").target("en").build();
9394

0 commit comments

Comments
 (0)