Skip to content

Commit d950da2

Browse files
authored
Merge branch 'master' into testCSVRecord
2 parents dd9b3cc + a35797b commit d950da2

25 files changed

Lines changed: 369 additions & 155 deletions

NOTICE.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Apache Commons CSV
2-
Copyright 2005-2019 The Apache Software Foundation
2+
Copyright 2005-2020 The Apache Software Foundation
33

44
This product includes software developed at
5-
The Apache Software Foundation (http://www.apache.org/).
5+
The Apache Software Foundation (https://www.apache.org/).

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ Apache Commons CSV
4646
[![Build Status](https://travis-ci.org/apache/commons-csv.svg)](https://travis-ci.org/apache/commons-csv)
4747
[![Coverage Status](https://coveralls.io/repos/apache/commons-csv/badge.svg)](https://coveralls.io/r/apache/commons-csv)
4848
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-csv/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-csv/)
49-
[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-csv/1.7.svg)](https://javadoc.io/doc/org.apache.commons/commons-csv/1.7)
49+
[![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-csv/1.8.svg)](https://javadoc.io/doc/org.apache.commons/commons-csv/1.8)
5050

51-
The Apache Commons CSV library provides a simple interface for reading and writing
52-
CSV files of various types.
51+
The Apache Commons CSV library provides a simple interface for reading and writing CSV files of various types.
5352

5453
Documentation
5554
-------------
@@ -68,7 +67,7 @@ Alternatively you can pull it from the central Maven repositories:
6867
<dependency>
6968
<groupId>org.apache.commons</groupId>
7069
<artifactId>commons-csv</artifactId>
71-
<version>1.7</version>
70+
<version>1.8</version>
7271
</dependency>
7372
```
7473

RELEASE-NOTES.txt

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,66 @@
1+
Apache Commons CSV
2+
Version 1.8
3+
Release Notes
4+
5+
6+
INTRODUCTION:
7+
8+
This document contains the release notes for the 1.8-SNAPSHOT version of Apache Commons CSV.
9+
Commons CSV reads and writes files in variations of the Comma Separated Value (CSV) format.
10+
11+
Commons CSV requires at least Java 6.
12+
13+
The Apache Commons CSV library provides a simple interface for reading and writing CSV files of various types.
14+
15+
Feature and bug fix release (Java 8).
16+
This release fixes serialization compatibility of CSVRecord with versions 1.0 to 1.6. New fields added since
17+
1.7 are not serialized. Support for Serializable is scheduled to be removed in version 2.0.
18+
19+
Changes in this version include:
20+
21+
NEW FEATURES
22+
==============
23+
24+
o CSV-255: Add CSVRecord.isSet(int) method #52. Thanks to 0x100.
25+
26+
FIXED BUGS
27+
============
28+
29+
o CSV-135: Char escape doesn't work properly with quoting. Thanks to Mateusz Zakarczemny.
30+
o CSV-244: Test case failures following CSVFormat#equals() update.
31+
o CSV-243: CSVFormat withTrim() and withIgnoreSurroundingSpaces() need better docs.
32+
o CSV-242: CSVFormat equals() and hashCode() don't use all fields.
33+
o CSV-241: CSVFormat#validate() does not account for allowDuplicateHeaderNames #43. Thanks to LuckyIlam, Gary Gregory.
34+
o CSV-245: Post 1.7 release fixes. Thanks to Alex Herbert.
35+
o CSV-252: Upgrade test framework to JUnit 5 Jupiter #49, #50. Thanks to Alex Herbert.
36+
o CSV-247: A single empty header is allowed when not allowing empty column headers. #47. Thanks to Alex Herbert, Gary Gregory.
37+
o CSV-248: CSVRecord is not Serializable. Thanks to Alex Herbert.
38+
o Use test scope for supercsv #48. Thanks to Alex Herbert.
39+
40+
CHANGES
41+
=========
42+
43+
o Update tests from H2 1.4.199 to 1.4.200. Thanks to Gary Gregory.
44+
o Update tests from Hamcrest 2.1 to 2.2. Thanks to Gary Gregory.
45+
o Update tests from Mockito 3.1.0 to 3.2.4. Thanks to Gary Gregory.
46+
o Fix typos in site and test #53. Thanks to Chen.
47+
o Fix typo performance test #55. Thanks to Chen.
48+
49+
50+
Historical list of changes: https://commons.apache.org/proper/commons-csv/changes-report.html
51+
52+
For complete information on Apache Commons CSV, including instructions on how to submit bug reports,
53+
patches, or suggestions for improvement, see the Apache Apache Commons CSV website:
54+
55+
https://commons.apache.org/proper/commons-csv/
56+
57+
Download page: https://commons.apache.org/proper/commons-csv/download_csv.cgi
58+
59+
Have fun!
60+
-Apache Commons CSV team
61+
62+
------------------------------------------------------------------------------
63+
164
Apache Commons CSV
265
Version 1.7
366
Release Notes
@@ -50,7 +113,6 @@ Have fun!
50113

51114
------------------------------------------------------------------------------
52115

53-
54116
Apache Commons CSV
55117
Version 1.6
56118
Release Notes

pom.xml

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,19 @@
2020
<parent>
2121
<groupId>org.apache.commons</groupId>
2222
<artifactId>commons-parent</artifactId>
23-
<version>48</version>
23+
<version>50</version>
2424
</parent>
2525
<artifactId>commons-csv</artifactId>
2626
<version>1.8-SNAPSHOT</version>
2727
<name>Apache Commons CSV</name>
2828
<url>https://commons.apache.org/proper/commons-csv/</url>
29-
<description>
30-
The Apache Commons CSV library provides a simple interface for reading and writing
31-
CSV files of various types.
32-
</description>
29+
<description>The Apache Commons CSV library provides a simple interface for reading and writing CSV files of various types.</description>
3330

3431
<dependencies>
3532
<dependency>
3633
<groupId>org.junit.jupiter</groupId>
3734
<artifactId>junit-jupiter</artifactId>
38-
<version>5.5.2</version>
35+
<version>5.6.0</version>
3936
<scope>test</scope>
4037
</dependency>
4138
<dependency>
@@ -143,7 +140,7 @@ CSV files of various types.
143140
<commons.release.version>1.8</commons.release.version>
144141
<commons.release.desc>(Java 8)</commons.release.desc>
145142
<!-- The RC version used in the staging repository URL. -->
146-
<commons.rc.version>RC1</commons.rc.version>
143+
<commons.rc.version>RC2</commons.rc.version>
147144
<commons.bc.version>1.7</commons.bc.version>
148145
<commons.componentid>csv</commons.componentid>
149146
<commons.module.name>org.apache.commons.csv</commons.module.name>
@@ -261,6 +258,7 @@ CSV files of various types.
261258
<!-- The ferc.gov files are included discussion in https://issues.apache.org/jira/browse/LEGAL-175. -->
262259
<exclude>src/test/resources/ferc.gov/contract.txt</exclude>
263260
<exclude>src/test/resources/ferc.gov/transaction.txt</exclude>
261+
<exclude>src/test/resources/**/*.bin</exclude>
264262
</excludes>
265263
</configuration>
266264
</plugin>
@@ -337,7 +335,7 @@ CSV files of various types.
337335
</tags>
338336
</tagClass>
339337
<tagClass>
340-
<displayName>Noteable Markers</displayName>
338+
<displayName>Notable Markers</displayName>
341339
<tags>
342340
<tag>
343341
<matchString>NOTE</matchString>
@@ -379,59 +377,14 @@ CSV files of various types.
379377
<exclude>src/test/resources/CSVFileParser/testCSV85_ignoreEmpty.txt</exclude>
380378
<exclude>src/test/resources/ferc.gov/contract.txt</exclude>
381379
<exclude>src/test/resources/ferc.gov/transaction.txt</exclude>
380+
<exclude>src/test/resources/**/*.bin</exclude>
382381
</excludes>
383382
</configuration>
384383
</plugin>
385384
</plugins>
386385
</reporting>
387386

388387
<profiles>
389-
<profile>
390-
<id>setup-checkout</id>
391-
<activation>
392-
<file>
393-
<missing>site-content</missing>
394-
</file>
395-
</activation>
396-
<build>
397-
<plugins>
398-
<plugin>
399-
<groupId>org.apache.maven.plugins</groupId>
400-
<artifactId>maven-antrun-plugin</artifactId>
401-
<version>1.8</version>
402-
<executions>
403-
<execution>
404-
<id>prepare-checkout</id>
405-
<phase>pre-site</phase>
406-
<goals>
407-
<goal>run</goal>
408-
</goals>
409-
<configuration>
410-
<tasks>
411-
<exec executable="svn">
412-
<arg line="checkout --depth immediates ${commons.scmPubUrl} ${commons.scmPubCheckoutDirectory}" />
413-
</exec>
414-
415-
<exec executable="svn">
416-
<arg line="update --set-depth exclude ${commons.scmPubCheckoutDirectory}/javadocs" />
417-
</exec>
418-
419-
<pathconvert pathsep=" " property="dirs">
420-
<dirset dir="${commons.scmPubCheckoutDirectory}" includes="*" />
421-
</pathconvert>
422-
<exec executable="svn">
423-
<arg line="update --set-depth infinity ${dirs}" />
424-
</exec>
425-
</tasks>
426-
</configuration>
427-
</execution>
428-
</executions>
429-
</plugin>
430-
</plugins>
431-
</build>
432-
</profile>
433-
434-
435388
<!-- Profile to build and run the benchmarks. Use 'mvn test -Pbenchmark', and add '-Dbenchmark=foo' to run only the foo benchmark -->
436389
<profile>
437390
<id>benchmark</id>

src/changes/changes.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@
3838
<title>Apache Commons CSV Release Notes</title>
3939
</properties>
4040
<body>
41-
<release version="1.8" date="2019-MM-DD" description="Feature and bug fix release (Java 8)">
41+
<release version="1.8" date="2019-02-01" description="Feature and bug fix release (Java 8).
42+
43+
This release fixes serialization compatibility of CSVRecord with versions 1.0 to 1.6.
44+
New fields added since 1.7 are not serialized. Support for Serializable is scheduled to be
45+
removed in version 2.0.
46+
">
4247
<action issue="CSV-255" type="add" dev="ggregory" due-to="0x100">Add CSVRecord.isSet(int) method #52.</action>
4348
<action issue="CSV-135" type="fix" dev="sebb" due-to="Mateusz Zakarczemny">Char escape doesn't work properly with quoting.</action>
4449
<action issue="CSV-244" type="fix" dev="sebb">Test case failures following CSVFormat#equals() update.</action>
@@ -48,10 +53,13 @@
4853
<action issue="CSV-245" type="fix" dev="ggregory" due-to="Alex Herbert">Post 1.7 release fixes.</action>
4954
<action issue="CSV-252" type="fix" dev="ggregory" due-to= "Alex Herbert">Upgrade test framework to JUnit 5 Jupiter #49, #50.</action>
5055
<action issue="CSV-247" type="fix" dev="ggregory" due-to="Alex Herbert, Gary Gregory">A single empty header is allowed when not allowing empty column headers. #47.</action>
56+
<action issue="CSV-248" type="fix" dev="ggregory" due-to="Alex Herbert">CSVRecord is not Serializable.</action>
5157
<action type="fix" dev="ggregory" due-to="Alex Herbert">Use test scope for supercsv #48.</action>
5258
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from H2 1.4.199 to 1.4.200.</action>
5359
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from Hamcrest 2.1 to 2.2.</action>
5460
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from Mockito 3.1.0 to 3.2.4.</action>
61+
<action type="update" dev="ggregory" due-to="Chen">Fix typos in site and test #53.</action>
62+
<action type="update" dev="ggregory" due-to="Chen">Fix typo performance test #55.</action>
5563
</release>
5664
<release version="1.7" date="2019-06-01" description="Feature and bug fix release (Java 8)">
5765
<action issue="CSV-233" type="add" dev="ggregory" due-to="Gary Gregory">Add predefined CSVFormats for printing MongoDB CSV and TSV.</action>

src/changes/release-notes.vm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ INTRODUCTION:
2525
This document contains the release notes for the ${version} version of Apache Commons CSV.
2626
Commons CSV reads and writes files in variations of the Comma Separated Value (CSV) format.
2727

28-
CSV requires at least Java 6.
28+
Commons CSV requires at least Java 6.
2929

3030
$introduction.replaceAll("(?<!\015)\012", "
3131
").replaceAll("(?m)^ +","")
@@ -122,5 +122,7 @@ patches, or suggestions for improvement, see the Apache ${project.name} website:
122122

123123
${project.url}
124124

125+
Download page: ${project.url}download_csv.cgi
126+
125127
Have fun!
126128
-Apache Commons CSV team

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,9 +2112,8 @@ public CSVFormat withIgnoreSurroundingSpaces() {
21122112
/**
21132113
* Returns a new {@code CSVFormat} with the parser trimming behavior of the format set to the given value.
21142114
*
2115-
* @param ignoreSurroundingSpaces
2116-
* the parser trimming behavior, {@code true} to remove the surrounding spaces, {@code false} to leave the
2117-
* spaces as is.
2115+
* @param ignoreSurroundingSpaces the parser trimming behavior, {@code true} to remove the surrounding spaces,
2116+
* {@code false} to leave the spaces as is.
21182117
* @return A new CSVFormat that is equal to this but with the specified trimming behavior.
21192118
*/
21202119
public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpaces) {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,11 @@ public String getFirstEndOfLine() {
555555
* <p>
556556
* The map keys are column names. The map values are 0-based indices.
557557
* </p>
558+
* <p>
559+
* Note: The map can only provide a one-to-one mapping when the format did not
560+
* contain null or duplicate column names.
561+
* </p>
562+
*
558563
* @return a copy of the header map.
559564
*/
560565
public Map<String, Integer> getHeaderMap() {
@@ -577,8 +582,14 @@ Map<String, Integer> getHeaderMapRaw() {
577582

578583
/**
579584
* Returns a read-only list of header names that iterates in column order.
585+
* <p>
586+
* Note: The list provides strings that can be used as keys in the header map.
587+
* The list will not contain null column names if they were present in the input
588+
* format.
589+
* </p>
580590
*
581591
* @return read-only list of header names that iterates in column order.
592+
* @see #getHeaderMap()
582593
* @since 1.7
583594
*/
584595
public List<String> getHeaderNames() {

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import java.util.Map.Entry;
27+
import java.util.Objects;
2728

2829
/**
2930
* A CSV record parsed from a CSV file.
31+
*
32+
* <p>
33+
* Note: Support for {@link Serializable} is scheduled to be removed in version 2.0.
34+
* In version 1.8 the mapping between the column header and the column index was
35+
* removed from the serialised state. The class maintains serialization compatibility
36+
* with versions pre-1.8 for the record values; these must be accessed by index
37+
* following deserialization. There will be loss of any functionally linked to the header
38+
* mapping when transferring serialised forms pre-1.8 to 1.8 and vice versa.
39+
* </p>
3040
*/
3141
public final class CSVRecord implements Serializable, Iterable<String> {
3242

@@ -45,8 +55,8 @@ public final class CSVRecord implements Serializable, Iterable<String> {
4555
/** The values of the record */
4656
private final String[] values;
4757

48-
/** The parser that originates this record. */
49-
private final CSVParser parser;
58+
/** The parser that originates this record. This is not serialized. */
59+
private final transient CSVParser parser;
5060

5161
CSVRecord(final CSVParser parser, final String[] values, final String comment, final long recordNumber,
5262
final long characterPosition) {
@@ -65,7 +75,7 @@ public final class CSVRecord implements Serializable, Iterable<String> {
6575
* @return the String at the given enum String
6676
*/
6777
public String get(final Enum<?> e) {
68-
return get(e.toString());
78+
return get(Objects.toString(e, null));
6979
}
7080

7181
/**
@@ -82,14 +92,24 @@ public String get(final int i) {
8292
/**
8393
* Returns a value by name.
8494
*
95+
* <p>
96+
* Note: This requires a field mapping obtained from the original parser.
97+
* A check using {@link #isMapped(String)} should be used to determine if a
98+
* mapping exists from the provided {@code name} to a field index. In this case an
99+
* exception will only be thrown if the record does not contain a field corresponding
100+
* to the mapping, that is the record length is not consistent with the mapping size.
101+
* </p>
102+
*
85103
* @param name
86104
* the name of the column to be retrieved.
87105
* @return the column value, maybe null depending on {@link CSVFormat#getNullString()}.
88106
* @throws IllegalStateException
89107
* if no header mapping was provided
90108
* @throws IllegalArgumentException
91109
* if {@code name} is not mapped or if the record is inconsistent
110+
* @see #isMapped(String)
92111
* @see #isConsistent()
112+
* @see #getParser()
93113
* @see CSVFormat#withNullString(String)
94114
*/
95115
public String get(final String name) {
@@ -135,12 +155,17 @@ public String getComment() {
135155
}
136156

137157
private Map<String, Integer> getHeaderMapRaw() {
138-
return parser.getHeaderMapRaw();
158+
return parser == null ? null : parser.getHeaderMapRaw();
139159
}
140160

141161
/**
142162
* Returns the parser.
143163
*
164+
* <p>
165+
* Note: The parser is not part of the serialized state of the record. A null check
166+
* should be used when the record may have originated from a serialized form.
167+
* </p>
168+
*
144169
* @return the parser.
145170
* @since 1.7
146171
*/

src/site/site.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<item name="Issue Tracking" href="/issue-tracking.html"/>
4040
<item name="Team" href="/team.html"/>
4141
<item name="Javadoc" href="/apidocs/index.html"/>
42+
<item name="Javadoc 1.8" href="https://javadoc.io/doc/org.apache.commons/commons-csv/1.8"/>
4243
<item name="Javadoc 1.7" href="https://javadoc.io/doc/org.apache.commons/commons-csv/1.7"/>
4344
<item name="Javadoc 1.6" href="https://javadoc.io/doc/org.apache.commons/commons-csv/1.6"/>
4445
<item name="Javadoc 1.5" href="https://javadoc.io/doc/org.apache.commons/commons-csv/1.5"/>

0 commit comments

Comments
 (0)