Skip to content

Commit 52bb15e

Browse files
committed
fix pmd errors
1 parent 1a7db55 commit 52bb15e

File tree

9 files changed

+175
-40
lines changed

9 files changed

+175
-40
lines changed

airbyte-api/src/main/java/io/airbyte/api/client/PatchedLogsApi.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public ApiResponse<File> getLogsWithHttpInfo(final LogsRequestBody logsRequestBo
7575
if (memberVarResponseInterceptor != null) {
7676
memberVarResponseInterceptor.accept(localVarResponse);
7777
}
78-
if (localVarResponse.statusCode() / 100 != 2) {
78+
if (!isSuccessful(localVarResponse.statusCode())) {
7979
throw new ApiException(localVarResponse.statusCode(),
8080
"getLogs call received non-success response",
8181
localVarResponse.headers(),
@@ -131,4 +131,8 @@ private HttpRequest.Builder getLogsRequestBuilder(final LogsRequestBody logsRequ
131131
return localVarRequestBuilder;
132132
}
133133

134+
private Boolean isSuccessful(final Integer responseCode) {
135+
return responseCode / 100 == 2;
136+
}
137+
134138
}

airbyte-commons-cli/src/test/java/io/airbyte/commons/cli/ClisTest.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616

1717
class ClisTest {
1818

19+
public String optionAName = "a";
20+
public String optionBName = "b";
21+
public String optionADesc = "alpha";
22+
public String optionBDesc = "beta";
23+
1924
@Test
2025
void testCreateOptionGroup() {
21-
final Option optionA = new Option("a", "alpha");
22-
final Option optionB = new Option("b", "beta");
26+
final Option optionA = new Option(optionAName, optionADesc);
27+
final Option optionB = new Option(optionBName, optionBDesc);
2328
final OptionGroup optionGroupExpected = new OptionGroup();
2429
optionGroupExpected.addOption(optionA);
2530
optionGroupExpected.addOption(optionB);
@@ -35,42 +40,42 @@ void testCreateOptionGroup() {
3540

3641
@Test
3742
void testParse() {
38-
final Option optionA = Option.builder("a").required(true).hasArg(true).build();
39-
final Option optionB = Option.builder("b").required(true).hasArg(true).build();
43+
final Option optionA = Option.builder(optionAName).required(true).hasArg(true).build();
44+
final Option optionB = Option.builder(optionBName).required(true).hasArg(true).build();
4045
final Options options = new Options().addOption(optionA).addOption(optionB);
41-
final String[] args = {"-a", "alpha", "-b", "beta"};
46+
final String[] args = {"-a", optionADesc, "-b", optionBDesc};
4247
final CommandLine parsed = Clis.parse(args, options, new DefaultParser());
43-
assertEquals("alpha", parsed.getOptions()[0].getValue());
44-
assertEquals("beta", parsed.getOptions()[1].getValue());
48+
assertEquals(optionADesc, parsed.getOptions()[0].getValue());
49+
assertEquals(optionBDesc, parsed.getOptions()[1].getValue());
4550
}
4651

4752
@Test
4853
void testParseNonConforming() {
49-
final Option optionA = Option.builder("a").required(true).hasArg(true).build();
50-
final Option optionB = Option.builder("b").required(true).hasArg(true).build();
54+
final Option optionA = Option.builder(optionAName).required(true).hasArg(true).build();
55+
final Option optionB = Option.builder(optionBName).required(true).hasArg(true).build();
5156
final Options options = new Options().addOption(optionA).addOption(optionB);
52-
final String[] args = {"-a", "alpha", "-b", "beta", "-c", "charlie"};
57+
final String[] args = {"-a", optionADesc, "-b", optionBDesc, "-c", "charlie"};
5358
assertThrows(IllegalArgumentException.class, () -> Clis.parse(args, options, new DefaultParser()));
5459
}
5560

5661
@Test
5762
void testParseNonConformingWithSyntax() {
58-
final Option optionA = Option.builder("a").required(true).hasArg(true).build();
59-
final Option optionB = Option.builder("b").required(true).hasArg(true).build();
63+
final Option optionA = Option.builder(optionAName).required(true).hasArg(true).build();
64+
final Option optionB = Option.builder(optionBName).required(true).hasArg(true).build();
6065
final Options options = new Options().addOption(optionA).addOption(optionB);
61-
final String[] args = {"-a", "alpha", "-b", "beta", "-c", "charlie"};
66+
final String[] args = {"-a", optionADesc, "-b", optionBDesc, "-c", "charlie"};
6267
assertThrows(IllegalArgumentException.class, () -> Clis.parse(args, options, new DefaultParser(), "search"));
6368
}
6469

6570
@Test
6671
void testRelaxedParser() {
67-
final Option optionA = Option.builder("a").required(true).hasArg(true).build();
68-
final Option optionB = Option.builder("b").required(true).hasArg(true).build();
72+
final Option optionA = Option.builder(optionAName).required(true).hasArg(true).build();
73+
final Option optionB = Option.builder(optionBName).required(true).hasArg(true).build();
6974
final Options options = new Options().addOption(optionA).addOption(optionB);
70-
final String[] args = {"-a", "alpha", "-b", "beta", "-c", "charlie"};
75+
final String[] args = {"-a", optionADesc, "-b", optionBDesc, "-c", "charlie"};
7176
final CommandLine parsed = Clis.parse(args, options, Clis.getRelaxedParser());
72-
assertEquals("alpha", parsed.getOptions()[0].getValue());
73-
assertEquals("beta", parsed.getOptions()[1].getValue());
77+
assertEquals(optionADesc, parsed.getOptions()[0].getValue());
78+
assertEquals(optionBDesc, parsed.getOptions()[1].getValue());
7479
}
7580

7681
}

airbyte-commons/src/main/java/io/airbyte/commons/concurrency/GracefulShutdownHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class GracefulShutdownHandler extends Thread {
1818

1919
public GracefulShutdownHandler(final Duration terminateWaitDuration, final ExecutorService... threadPools) {
2020
this.terminateWaitDuration = terminateWaitDuration;
21-
this.threadPools = threadPools;
21+
this.threadPools = threadPools.clone();
2222
}
2323

2424
@Override

airbyte-commons/src/main/java/io/airbyte/commons/yaml/Yamls.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ public YamlConsumer(final Writer writer, final ObjectMapper objectMapper) {
130130
}
131131

132132
@Override
133-
public void accept(final T t) {
133+
public void accept(final T acceptInput) {
134134
try {
135-
sequenceWriter.write(t);
135+
sequenceWriter.write(acceptInput);
136136
} catch (final IOException e) {
137137
throw new RuntimeException(e);
138138
}

airbyte-config/models/src/main/java/io/airbyte/config/AirbyteConfigValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public class AirbyteConfigValidator extends AbstractSchemaValidator<ConfigSchema> {
1111

12-
public static AirbyteConfigValidator AIRBYTE_CONFIG_VALIDATOR = new AirbyteConfigValidator();
12+
public static final AirbyteConfigValidator AIRBYTE_CONFIG_VALIDATOR = new AirbyteConfigValidator();
1313

1414
@Override
1515
public Path getSchemaPath(final ConfigSchema configType) {

airbyte-config/persistence/src/main/java/io/airbyte/config/persistence/DatabaseConfigPersistence.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private <T> void validate(final String configId, final List<ConfigWithMetadata<T
234234
throws ConfigNotFoundException {
235235
if (result.isEmpty()) {
236236
throw new ConfigNotFoundException(airbyteConfig, configId);
237-
} else if (result.size() > 1) {
237+
} else if (!result.isEmpty()) {
238238
throw new IllegalStateException(String.format("Multiple %s configs found for ID %s: %s", airbyteConfig, configId, result));
239239
}
240240
}
@@ -1803,7 +1803,7 @@ <T> ConnectorCounter updateConnectorDefinitions(final DSLContext ctx,
18031803
LOGGER.info("Connector {} needs update: {} vs {}", repository, connectorInfo.dockerImageTag, latestImageTag);
18041804
writeOrUpdateStandardDefinition(ctx, configType, latestDefinition);
18051805
updatedCount++;
1806-
} else if (newFields.size() == 0) {
1806+
} else if (newFields.isEmpty()) {
18071807
LOGGER.info("Connector {} is in use and has all fields; skip updating", repository);
18081808
} else {
18091809
// Add new fields to the connector definition
@@ -1822,7 +1822,7 @@ <T> ConnectorCounter updateConnectorDefinitions(final DSLContext ctx,
18221822
LOGGER.info("Connector {} needs update: {} vs {}", repository, connectorInfo.dockerImageTag, latestImageTag);
18231823
writeOrUpdateStandardDefinition(ctx, configType, latestDefinition);
18241824
updatedCount++;
1825-
} else if (newFields.size() > 0) {
1825+
} else if (!newFields.isEmpty()) {
18261826
// Add new fields to the connector definition
18271827
final JsonNode definitionToUpdate = getDefinitionWithNewFields(currentDefinition, latestDefinition, newFields);
18281828
LOGGER.info("Connector {} has new fields: {}", repository, String.join(", ", newFields));

airbyte-tests/src/acceptanceTests/java/io/airbyte/test/acceptance/AcceptanceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ public void testRedactionOfSensitiveRequestBodies() throws Exception {
829829
apiClient.getLogsApi().getLogs(new LogsRequestBody().logType(LogType.SERVER)).toPath(),
830830
Charset.defaultCharset());
831831

832-
assertTrue(serverLogLines.size() > 0);
832+
assertTrue(!serverLogLines.isEmpty());
833833

834834
boolean hasRedacted = false;
835835

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ subprojects {
384384
}
385385

386386
tasks.withType(Pmd) {
387-
exclude '**/generated/**'
388387
exclude '**/jooq/**'
389388
}
390389

tools/gradle/pmd/rules.xml

Lines changed: 139 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,145 @@
11
<?xml version="1.0"?>
22
<ruleset name="Airbyte Rules"
3-
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
6-
7-
<description>PMD Rules for Airbyte</description>
8-
3+
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
6+
<description>
7+
PMD Rules for Airbyte
8+
</description>
99
<!-- TODO: couldn't figure out how to make gradle exclude to work so defining exclude at PMD level. Cons: hardcoding 'generated' -->
1010
<exclude-pattern>.*/generated/.*</exclude-pattern>
11+
<exclude-pattern>.*/ConfigSchema.java/.*</exclude-pattern>
12+
<exclude-pattern>.*/airbyte-analytics/.*</exclude-pattern>
13+
<exclude-pattern>.*/airbyte-commons/.*</exclude-pattern>
14+
<exclude-pattern>.*/airbyte-config/.*</exclude-pattern>
15+
<exclude-pattern>.*/airbyte-container-orchestrator/.*</exclude-pattern>
16+
<exclude-pattern>.*/airbyte-cli/.*</exclude-pattern>
17+
<exclude-pattern>.*/airbyte-cdk/.*</exclude-pattern>
18+
<exclude-pattern>.*/airbyte-api/.*</exclude-pattern>
19+
<exclude-pattern>.*/airbyte-bootloader/.*</exclude-pattern>
20+
<exclude-pattern>.*/airbyte-commons-cli/.*</exclude-pattern>
21+
<exclude-pattern>.*/airbyte-db/.*</exclude-pattern>
22+
<exclude-pattern>.*/airbyte-integrations/.*</exclude-pattern>
23+
<exclude-pattern>.*/airbyte-json-validation/.*</exclude-pattern>
24+
<exclude-pattern>.*/airbyte-notification/.*</exclude-pattern>
25+
<exclude-pattern>.*/airbyte-oauth/.*</exclude-pattern>
26+
<exclude-pattern>.*/airbyte-queue/.*</exclude-pattern>
27+
<exclude-pattern>.*/airbyte-scheduler/.*</exclude-pattern>
28+
<exclude-pattern>.*/airbyte-schema-validation/.*</exclude-pattern>
29+
<exclude-pattern>.*/airbyte-server/.*</exclude-pattern>
30+
<exclude-pattern>.*/airbyte-temporal/.*</exclude-pattern>
31+
<exclude-pattern>.*/airbyte-test-utils/.*</exclude-pattern>
32+
<exclude-pattern>.*/airbyte-tests/.*</exclude-pattern>
33+
<exclude-pattern>.*/airbyte-webapp/.*</exclude-pattern>
34+
<exclude-pattern>.*/airbyte-webapp-e2e-tests/.*</exclude-pattern>
35+
<exclude-pattern>.*/airbyte-workers/.*</exclude-pattern>
36+
37+
38+
<exclude-pattern>.*/EnvConfigs.java/.*</exclude-pattern>
39+
<exclude-pattern>.*/CloudLogs.java/.*</exclude-pattern>
40+
<exclude-pattern>.*/GcsLogs.java/.*</exclude-pattern>
41+
<exclude-pattern>.*/LifecycledCallable.java/.*</exclude-pattern>
42+
<exclude-pattern>.*/VoidCallable.java/.*</exclude-pattern>
43+
<exclude-pattern>.*/Enums.java/.*</exclude-pattern>
44+
<exclude-pattern>.*/IOs.java/.*</exclude-pattern>
45+
<exclude-pattern>.*/LineGobbler.java/.*</exclude-pattern>
46+
<exclude-pattern>.*/Archives.java/.*</exclude-pattern>
47+
<exclude-pattern>.*/JsonSchemas.java/.*</exclude-pattern>
48+
<exclude-pattern>.*/CompositeIterator.java/.*</exclude-pattern>
49+
<exclude-pattern>.*/MoreIterators.java/.*</exclude-pattern>
50+
<exclude-pattern>.*/AirbyteVersion.java/.*</exclude-pattern>
51+
<exclude-pattern>.*/Yamls.java/.*</exclude-pattern>
52+
<exclude-pattern>.*/lang/Exceptions.java/.*</exclude-pattern>
53+
<exclude-pattern>.*/OnDiskQueue.java/.*</exclude-pattern>
54+
55+
<rule ref="category/java/bestpractices.xml">
56+
<exclude name="GuardLogStatement"/>
57+
<exclude name="JUnitAssertionsShouldIncludeMessage" />
58+
<exclude name="JUnitTestContainsTooManyAsserts" />
59+
</rule>
60+
<rule ref="category/java/codestyle.xml">
61+
<exclude name="AtLeastOneConstructor"/>
62+
<exclude name="CallSuperInConstructor"/>
63+
<exclude name="CommentDefaultAccessModifier"/>
64+
<exclude name="ConfusingTernary"/>
65+
<exclude name="FinalParameterInAbstractMethod"/>
66+
<exclude name="OnlyOneReturn"/>
67+
<exclude name="PrematureDeclaration"/>
68+
<exclude name="TooManyStaticImports"/>
69+
<exclude name="UselessParentheses"/>
70+
<exclude name="UnnecessaryModifier"/>
71+
<exclude name="UseUnderscoresInNumericLiterals"/>
72+
</rule>
73+
<rule ref="category/java/design.xml">
74+
<exclude name="AvoidCatchingGenericException"/>
75+
<exclude name="CouplingBetweenObjects"/>
76+
<exclude name="DataClass"/>
77+
<exclude name="ExcessiveImports"/>
78+
<exclude name="ExcessivePublicCount"/>
79+
<exclude name="GodClass"/>
80+
<exclude name="LawOfDemeter"/>
81+
<exclude name="LoosePackageCoupling"/>
82+
<exclude name="UseObjectForClearerAPI"/>
83+
<exclude name="SimplifyBooleanReturns"/>
84+
<exclude name="SingularField"/>
85+
<exclude name="TooManyFields"/>
86+
<exclude name="TooManyMethods"/>
87+
<exclude name="UseUtilityClass"/>
88+
</rule>
89+
<rule ref="category/java/documentation.xml">
90+
<exclude name="CommentRequired"/>
91+
<exclude name="UncommentedEmptyConstructor"/>
92+
</rule>
93+
<rule ref="category/java/errorprone.xml">
94+
<exclude name="AvoidFieldNameMatchingMethodName"/>
95+
<exclude name="BeanMembersShouldSerialize"/>
96+
<exclude name="DataflowAnomalyAnalysis"/>
97+
<exclude name="UseLocaleWithCaseConversions"/>
98+
</rule>
99+
<rule ref="category/java/errorprone.xml/AssignmentInOperand">
100+
<properties>
101+
<property name="allowFor" value="true" />
102+
<property name="allowWhile" value="true" />
103+
</properties>
104+
</rule>
105+
<rule ref="category/java/multithreading.xml">
106+
<exclude name="DoNotUseThreads"/>
107+
<exclude name="UseConcurrentHashMap"/>
108+
</rule>
109+
<rule ref="category/java/performance.xml"/>
110+
<rule ref="category/java/security.xml"/>
11111

12-
<!-- https://pmd.github.io/pmd-6.23.0/pmd_rules_java.html -->
13-
<rule ref="category/java/bestpractices.xml/AbstractClassWithoutAbstractMethod" />
14-
<rule ref="category/java/bestpractices.xml/UseCollectionIsEmpty" />
15-
<rule ref="category/java/bestpractices.xml/SystemPrintln" />
16-
<!-- <rule ref="category/java/codestyle.xml/LocalVariableCouldBeFinal" />-->
17-
<!-- <rule ref="category/java/codestyle.xml/MethodArgumentCouldBeFinal" />-->
112+
<rule ref="category/java/codestyle.xml/ClassNamingConventions">
113+
<properties>
114+
<property name="classPattern" value="[A-Z][a-zA-Z0-9_]*"/>
115+
<property name="utilityClassPattern" value="[A-Z][a-zA-Z0-9]*"/>
116+
</properties>
117+
</rule>
118+
<rule ref="category/java/codestyle.xml/FieldNamingConventions">
119+
<properties>
120+
<property name="exclusions" value="log|logger|serialVersionUID"/>
121+
</properties>
122+
</rule>
123+
<rule ref="category/java/codestyle.xml/LongVariable">
124+
<properties>
125+
<property name="minimum" value="42"/>
126+
</properties>
127+
</rule>
128+
<rule ref="category/java/design.xml/AvoidDeeplyNestedIfStmts">
129+
<properties>
130+
<property name="problemDepth" value="5"/>
131+
</properties>
132+
</rule>
133+
<rule ref="category/java/documentation.xml/CommentSize">
134+
<properties>
135+
<property name="maxLines" value="42"/>
136+
<property name="maxLineLength" value="150"/>
137+
</properties>
138+
</rule>
139+
<rule ref="category/java/errorprone.xml/CloseResource">
140+
<properties>
141+
<property name="allowedResourceTypes"
142+
value="java.io.ByteArrayOutputStream|java.io.ByteArrayInputStream|java.io.StringWriter|java.io.CharArrayWriter|java.util.stream.Stream|java.util.stream.IntStream|java.util.stream.LongStream|java.util.stream.DoubleStream|okhttp3.Response"/>
143+
</properties>
144+
</rule>
18145
</ruleset>

0 commit comments

Comments
 (0)