Skip to content

Commit a36d5bc

Browse files
committed
Bump commons-parent from 69 to 70
Fix PMD issues for port to PMD 7.1.0
1 parent bef059b commit a36d5bc

4 files changed

Lines changed: 78 additions & 100 deletions

File tree

pom.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<parent>
2121
<groupId>org.apache.commons</groupId>
2222
<artifactId>commons-parent</artifactId>
23-
<version>69</version>
23+
<version>70</version>
2424
</parent>
2525
<artifactId>commons-csv</artifactId>
2626
<version>1.11.1-SNAPSHOT</version>
@@ -216,9 +216,6 @@
216216
<configuration>
217217
<targetJdk>${maven.compiler.target}</targetJdk>
218218
<skipEmptyReport>false</skipEmptyReport>
219-
<rulesets>
220-
<ruleset>${basedir}/src/site/resources/pmd/pmd-ruleset.xml</ruleset>
221-
</rulesets>
222219
</configuration>
223220
</plugin>
224221
<!-- We need to add our test data files to rat exclusions -->

src/changes/changes.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
<release version="1.11.1" date="YYYY-MM-DD" description="Feature and bug fix release (Java 8 or above)">
4444
<!-- ADD -->
4545
<!-- FIX -->
46+
<action type="update" dev="ggregory" due-to="Gary Gregory">Fix PMD issues for port to PMD 7.1.0.</action>
4647
<!-- UPDATE -->
4748
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons-codec:commons-codec from 1.16.1 to 1.17.0 #422.</action>
49+
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-parent from 69 to 70.</action>
4850
</release>
4951
<release version="1.11.0" date="2024-04-28" description="Feature and bug fix release (Java 8 or above)">
5052
<!-- ADD -->

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@
1717

1818
package org.apache.commons.csv;
1919

20-
import static org.apache.commons.csv.Constants.BACKSLASH;
21-
import static org.apache.commons.csv.Constants.COMMA;
22-
import static org.apache.commons.csv.Constants.COMMENT;
23-
import static org.apache.commons.csv.Constants.CR;
24-
import static org.apache.commons.csv.Constants.CRLF;
25-
import static org.apache.commons.csv.Constants.DOUBLE_QUOTE_CHAR;
26-
import static org.apache.commons.csv.Constants.EMPTY;
27-
import static org.apache.commons.csv.Constants.LF;
28-
import static org.apache.commons.csv.Constants.PIPE;
29-
import static org.apache.commons.csv.Constants.SP;
30-
import static org.apache.commons.csv.Constants.TAB;
3120
import static org.apache.commons.io.IOUtils.EOF;
3221

3322
import java.io.File;
@@ -203,7 +192,7 @@ public static class Builder {
203192
* @return a copy of the builder
204193
*/
205194
public static Builder create() {
206-
return new Builder(CSVFormat.DEFAULT);
195+
return new Builder(DEFAULT);
207196
}
208197

209198
/**
@@ -850,57 +839,57 @@ public enum Predefined {
850839
/**
851840
* @see CSVFormat#DEFAULT
852841
*/
853-
Default(CSVFormat.DEFAULT),
842+
Default(DEFAULT),
854843

855844
/**
856845
* @see CSVFormat#EXCEL
857846
*/
858-
Excel(CSVFormat.EXCEL),
847+
Excel(EXCEL),
859848

860849
/**
861850
* @see CSVFormat#INFORMIX_UNLOAD
862851
* @since 1.3
863852
*/
864-
InformixUnload(CSVFormat.INFORMIX_UNLOAD),
853+
InformixUnload(INFORMIX_UNLOAD),
865854

866855
/**
867856
* @see CSVFormat#INFORMIX_UNLOAD_CSV
868857
* @since 1.3
869858
*/
870-
InformixUnloadCsv(CSVFormat.INFORMIX_UNLOAD_CSV),
859+
InformixUnloadCsv(INFORMIX_UNLOAD_CSV),
871860

872861
/**
873862
* @see CSVFormat#MONGODB_CSV
874863
* @since 1.7
875864
*/
876-
MongoDBCsv(CSVFormat.MONGODB_CSV),
865+
MongoDBCsv(MONGODB_CSV),
877866

878867
/**
879868
* @see CSVFormat#MONGODB_TSV
880869
* @since 1.7
881870
*/
882-
MongoDBTsv(CSVFormat.MONGODB_TSV),
871+
MongoDBTsv(MONGODB_TSV),
883872

884873
/**
885874
* @see CSVFormat#MYSQL
886875
*/
887-
MySQL(CSVFormat.MYSQL),
876+
MySQL(MYSQL),
888877

889878
/**
890879
* @see CSVFormat#ORACLE
891880
*/
892-
Oracle(CSVFormat.ORACLE),
881+
Oracle(ORACLE),
893882

894883
/**
895884
* @see CSVFormat#POSTGRESQL_CSV
896885
* @since 1.5
897886
*/
898-
PostgreSQLCsv(CSVFormat.POSTGRESQL_CSV),
887+
PostgreSQLCsv(POSTGRESQL_CSV),
899888

900889
/**
901890
* @see CSVFormat#POSTGRESQL_CSV
902891
*/
903-
PostgreSQLText(CSVFormat.POSTGRESQL_TEXT),
892+
PostgreSQLText(POSTGRESQL_TEXT),
904893

905894
/**
906895
* @see CSVFormat#RFC4180
@@ -945,8 +934,8 @@ public CSVFormat getFormat() {
945934
*
946935
* @see Predefined#Default
947936
*/
948-
public static final CSVFormat DEFAULT = new CSVFormat(COMMA, DOUBLE_QUOTE_CHAR, null, null, null, false, true, CRLF, null, null, null, false, false, false,
949-
false, false, false, DuplicateHeaderMode.ALLOW_ALL, false, false);
937+
public static final CSVFormat DEFAULT = new CSVFormat(Constants.COMMA, Constants.DOUBLE_QUOTE_CHAR, null, null, null, false, true, Constants.CRLF, null,
938+
null, null, false, false, false, false, false, false, DuplicateHeaderMode.ALLOW_ALL, false, false);
950939

951940
/**
952941
* Excel file format (using a comma as the value delimiter). Note that the actual value delimiter used by Excel is locale-dependent, it might be necessary
@@ -1014,10 +1003,10 @@ public CSVFormat getFormat() {
10141003
*/
10151004
// @formatter:off
10161005
public static final CSVFormat INFORMIX_UNLOAD = DEFAULT.builder()
1017-
.setDelimiter(PIPE)
1018-
.setEscape(BACKSLASH)
1019-
.setQuote(DOUBLE_QUOTE_CHAR)
1020-
.setRecordSeparator(LF)
1006+
.setDelimiter(Constants.PIPE)
1007+
.setEscape(Constants.BACKSLASH)
1008+
.setQuote(Constants.DOUBLE_QUOTE_CHAR)
1009+
.setRecordSeparator(Constants.LF)
10211010
.build();
10221011
// @formatter:on
10231012

@@ -1045,9 +1034,9 @@ public CSVFormat getFormat() {
10451034
*/
10461035
// @formatter:off
10471036
public static final CSVFormat INFORMIX_UNLOAD_CSV = DEFAULT.builder()
1048-
.setDelimiter(COMMA)
1049-
.setQuote(DOUBLE_QUOTE_CHAR)
1050-
.setRecordSeparator(LF)
1037+
.setDelimiter(Constants.COMMA)
1038+
.setQuote(Constants.DOUBLE_QUOTE_CHAR)
1039+
.setRecordSeparator(Constants.LF)
10511040
.build();
10521041
// @formatter:on
10531042

@@ -1085,9 +1074,9 @@ public CSVFormat getFormat() {
10851074
*/
10861075
// @formatter:off
10871076
public static final CSVFormat MONGODB_CSV = DEFAULT.builder()
1088-
.setDelimiter(COMMA)
1089-
.setEscape(DOUBLE_QUOTE_CHAR)
1090-
.setQuote(DOUBLE_QUOTE_CHAR)
1077+
.setDelimiter(Constants.COMMA)
1078+
.setEscape(Constants.DOUBLE_QUOTE_CHAR)
1079+
.setQuote(Constants.DOUBLE_QUOTE_CHAR)
10911080
.setQuoteMode(QuoteMode.MINIMAL)
10921081
.setSkipHeaderRecord(false)
10931082
.build();
@@ -1122,9 +1111,9 @@ public CSVFormat getFormat() {
11221111
*/
11231112
// @formatter:off
11241113
public static final CSVFormat MONGODB_TSV = DEFAULT.builder()
1125-
.setDelimiter(TAB)
1126-
.setEscape(DOUBLE_QUOTE_CHAR)
1127-
.setQuote(DOUBLE_QUOTE_CHAR)
1114+
.setDelimiter(Constants.TAB)
1115+
.setEscape(Constants.DOUBLE_QUOTE_CHAR)
1116+
.setQuote(Constants.DOUBLE_QUOTE_CHAR)
11281117
.setQuoteMode(QuoteMode.MINIMAL)
11291118
.setSkipHeaderRecord(false)
11301119
.build();
@@ -1157,11 +1146,11 @@ public CSVFormat getFormat() {
11571146
*/
11581147
// @formatter:off
11591148
public static final CSVFormat MYSQL = DEFAULT.builder()
1160-
.setDelimiter(TAB)
1161-
.setEscape(BACKSLASH)
1149+
.setDelimiter(Constants.TAB)
1150+
.setEscape(Constants.BACKSLASH)
11621151
.setIgnoreEmptyLines(false)
11631152
.setQuote(null)
1164-
.setRecordSeparator(LF)
1153+
.setRecordSeparator(Constants.LF)
11651154
.setNullString(Constants.SQL_NULL_STRING)
11661155
.setQuoteMode(QuoteMode.ALL_NON_NULL)
11671156
.build();
@@ -1196,10 +1185,10 @@ public CSVFormat getFormat() {
11961185
*/
11971186
// @formatter:off
11981187
public static final CSVFormat ORACLE = DEFAULT.builder()
1199-
.setDelimiter(COMMA)
1200-
.setEscape(BACKSLASH)
1188+
.setDelimiter(Constants.COMMA)
1189+
.setEscape(Constants.BACKSLASH)
12011190
.setIgnoreEmptyLines(false)
1202-
.setQuote(DOUBLE_QUOTE_CHAR)
1191+
.setQuote(Constants.DOUBLE_QUOTE_CHAR)
12031192
.setNullString(Constants.SQL_NULL_STRING)
12041193
.setTrim(true)
12051194
.setRecordSeparator(System.lineSeparator())
@@ -1235,12 +1224,12 @@ public CSVFormat getFormat() {
12351224
*/
12361225
// @formatter:off
12371226
public static final CSVFormat POSTGRESQL_CSV = DEFAULT.builder()
1238-
.setDelimiter(COMMA)
1227+
.setDelimiter(Constants.COMMA)
12391228
.setEscape(null)
12401229
.setIgnoreEmptyLines(false)
1241-
.setQuote(DOUBLE_QUOTE_CHAR)
1242-
.setRecordSeparator(LF)
1243-
.setNullString(EMPTY)
1230+
.setQuote(Constants.DOUBLE_QUOTE_CHAR)
1231+
.setRecordSeparator(Constants.LF)
1232+
.setNullString(Constants.EMPTY)
12441233
.setQuoteMode(QuoteMode.ALL_NON_NULL)
12451234
.build();
12461235
// @formatter:off
@@ -1273,11 +1262,11 @@ public CSVFormat getFormat() {
12731262
*/
12741263
// @formatter:off
12751264
public static final CSVFormat POSTGRESQL_TEXT = DEFAULT.builder()
1276-
.setDelimiter(TAB)
1277-
.setEscape(BACKSLASH)
1265+
.setDelimiter(Constants.TAB)
1266+
.setEscape(Constants.BACKSLASH)
12781267
.setIgnoreEmptyLines(false)
12791268
.setQuote(null)
1280-
.setRecordSeparator(LF)
1269+
.setRecordSeparator(Constants.LF)
12811270
.setNullString(Constants.SQL_NULL_STRING)
12821271
.setQuoteMode(QuoteMode.ALL_NON_NULL)
12831272
.build();
@@ -1319,7 +1308,7 @@ public CSVFormat getFormat() {
13191308
*/
13201309
// @formatter:off
13211310
public static final CSVFormat TDF = DEFAULT.builder()
1322-
.setDelimiter(TAB)
1311+
.setDelimiter(Constants.TAB)
13231312
.setIgnoreSurroundingSpaces(true)
13241313
.build();
13251314
// @formatter:on
@@ -1356,7 +1345,7 @@ private static boolean contains(final String source, final char searchCh) {
13561345
* @return true if {@code c} contains a line break character.
13571346
*/
13581347
private static boolean containsLineBreak(final String source) {
1359-
return contains(source, CR) || contains(source, LF);
1348+
return contains(source, Constants.CR) || contains(source, Constants.LF);
13601349
}
13611350

13621351
static boolean isBlank(final String value) {
@@ -1371,7 +1360,7 @@ static boolean isBlank(final String value) {
13711360
* @return true if {@code c} is a line break character.
13721361
*/
13731362
private static boolean isLineBreak(final char c) {
1374-
return c == LF || c == CR;
1363+
return c == Constants.LF || c == Constants.CR;
13751364
}
13761365

13771366
/**
@@ -1387,7 +1376,7 @@ private static boolean isLineBreak(final Character c) {
13871376

13881377
/** Same test as in as {@link String#trim()}. */
13891378
private static boolean isTrimChar(final char ch) {
1390-
return ch <= SP;
1379+
return ch <= Constants.SP;
13911380
}
13921381

13931382
/** Same test as in as {@link String#trim()}. */
@@ -2121,7 +2110,7 @@ public synchronized void print(final Object value, final Appendable out, final b
21212110
if (value == null) {
21222111
// https://issues.apache.org/jira/browse/CSV-203
21232112
if (null == nullString) {
2124-
charSequence = EMPTY;
2113+
charSequence = Constants.EMPTY;
21252114
} else if (QuoteMode.ALL == quoteMode) {
21262115
charSequence = quotedNullString;
21272116
} else {
@@ -2259,8 +2248,8 @@ private void printWithEscapes(final CharSequence charSeq, final Appendable appen
22592248
while (pos < end) {
22602249
char c = charSeq.charAt(pos);
22612250
final boolean isDelimiterStart = isDelimiter(c, charSeq, pos, delimArray, delimLength);
2262-
final boolean isCr = c == CR;
2263-
final boolean isLf = c == LF;
2251+
final boolean isCr = c == Constants.CR;
2252+
final boolean isLf = c == Constants.LF;
22642253
if (isCr || isLf || c == escape || isDelimiterStart) {
22652254
// write out segment up until this char
22662255
if (pos > start) {
@@ -2308,8 +2297,8 @@ private void printWithEscapes(final Reader reader, final Appendable appendable)
23082297
Arrays.fill(lookAheadBuffer, (char) 0);
23092298
final String test = builder.toString() + new String(bufferedReader.lookAhead(lookAheadBuffer));
23102299
final boolean isDelimiterStart = isDelimiter((char) c, test, pos, delimArray, delimLength);
2311-
final boolean isCr = c == CR;
2312-
final boolean isLf = c == LF;
2300+
final boolean isCr = c == Constants.CR;
2301+
final boolean isLf = c == Constants.LF;
23132302
if (isCr || isLf || c == escape || isDelimiterStart) {
23142303
// write out segment up until this char
23152304
if (pos > start) {
@@ -2381,15 +2370,15 @@ private void printWithQuotes(final Object object, final CharSequence charSeq, fi
23812370
}
23822371
} else {
23832372
char c = charSeq.charAt(pos);
2384-
if (c <= COMMENT) {
2373+
if (c <= Constants.COMMENT) {
23852374
// Some other chars at the start of a value caused the parser to fail, so for now
23862375
// encapsulate if we start in anything less than '#'. We are being conservative
23872376
// by including the default comment char too.
23882377
quote = true;
23892378
} else {
23902379
while (pos < len) {
23912380
c = charSeq.charAt(pos);
2392-
if (c == LF || c == CR || c == quoteChar || c == escapeChar || isDelimiter(c, charSeq, pos, delim, delimLength)) {
2381+
if (c == Constants.LF || c == Constants.CR || c == quoteChar || c == escapeChar || isDelimiter(c, charSeq, pos, delim, delimLength)) {
23932382
quote = true;
23942383
break;
23952384
}

0 commit comments

Comments
 (0)