Skip to content

Commit 02efd16

Browse files
committed
# WARNING: head commit changed in the meantime
Add CSVParser#stream(). - Use JApiCmp instead of Clirr in the default goal. - Allow for longer lines. - Fix PMD custom rules for current version of PMD. - Bump checkstyle from 8.29 to 8.44. - Bump commons.javadoc.version from 3.2.0 to 3.3.0.
1 parent ee9b09e commit 02efd16

6 files changed

Lines changed: 60 additions & 23 deletions

File tree

pom.xml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@
164164
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
165165
<commons.encoding>UTF-8</commons.encoding>
166166

167-
<checkstyle.version>3.1.2</checkstyle.version>
167+
<commons.checkstyle-plugin.version>3.1.2</commons.checkstyle-plugin.version>
168+
<commons.checkstyle.version>8.44</commons.checkstyle.version>
168169
<checkstyle.header.file>${basedir}/src/site/resources/checkstyle/checkstyle-header.txt</checkstyle.header.file>
169170
<checkstyle.config.file>${basedir}/src/site/resources/checkstyle/checkstyle.xml</checkstyle.config.file>
170171
<checkstyle.suppress.file>${basedir}/src/site/resources/checkstyle/checkstyle-suppressions.xml</checkstyle.suppress.file>
@@ -181,7 +182,28 @@
181182
</properties>
182183

183184
<build>
184-
<defaultGoal>clean verify apache-rat:check clirr:check checkstyle:check spotbugs:check javadoc:javadoc</defaultGoal>
185+
<defaultGoal>clean package apache-rat:check japicmp:cmp checkstyle:check spotbugs:check javadoc:javadoc</defaultGoal>
186+
<pluginManagement>
187+
<plugins>
188+
<plugin>
189+
<groupId>org.apache.maven.plugins</groupId>
190+
<artifactId>maven-checkstyle-plugin</artifactId>
191+
<version>${commons.checkstyle-plugin.version}</version>
192+
<configuration>
193+
<configLocation>${checkstyle.config.file}</configLocation>
194+
<enableRulesSummary>false</enableRulesSummary>
195+
<suppressionsLocation>${checkstyle.suppress.file}</suppressionsLocation>
196+
</configuration>
197+
<dependencies>
198+
<dependency>
199+
<groupId>com.puppycrawl.tools</groupId>
200+
<artifactId>checkstyle</artifactId>
201+
<version>${commons.checkstyle.version}</version>
202+
</dependency>
203+
</dependencies>
204+
</plugin>
205+
</plugins>
206+
</pluginManagement>
185207
<plugins>
186208
<plugin>
187209
<artifactId>maven-compiler-plugin</artifactId>
@@ -214,12 +236,6 @@
214236
<plugin>
215237
<groupId>org.apache.maven.plugins</groupId>
216238
<artifactId>maven-checkstyle-plugin</artifactId>
217-
<version>${checkstyle.version}</version>
218-
<configuration>
219-
<configLocation>${checkstyle.config.file}</configLocation>
220-
<enableRulesSummary>false</enableRulesSummary>
221-
<suppressionsLocation>${checkstyle.suppress.file}</suppressionsLocation>
222-
</configuration>
223239
</plugin>
224240
<plugin>
225241
<groupId>com.github.spotbugs</groupId>
@@ -285,12 +301,6 @@
285301
<plugin>
286302
<groupId>org.apache.maven.plugins</groupId>
287303
<artifactId>maven-checkstyle-plugin</artifactId>
288-
<version>${checkstyle.version}</version>
289-
<configuration>
290-
<configLocation>${checkstyle.config.file}</configLocation>
291-
<enableRulesSummary>false</enableRulesSummary>
292-
<suppressionsLocation>${checkstyle.suppress.file}</suppressionsLocation>
293-
</configuration>
294304
<!-- We need to specify reportSets because 2.9.1 creates two reports -->
295305
<reportSets>
296306
<reportSet>

src/changes/changes.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,26 @@
5959
<action issue="CSV-123" type="fix" dev="ggregory" due-to="Emmanuel Bourg, Benedikt Ritter, shivakrishnaah, Gary Gregory">Add possibility to use ResultSet header meta data as CSV header #11.</action>
6060
<!-- ADD -->
6161
<action issue="CSV-275" type="add" dev="ggregory" due-to="Michael Wyraz, Gary Gregory">Make CSVRecord#toList() public.</action>
62-
<action type="add" dev="ggregory" due-to="Gary Gregory">Add CSVRecord#toStream().</action>
62+
<action type="add" dev="ggregory" due-to="Gary Gregory">Add CSVRecord#stream().</action>
63+
<action type="add" dev="ggregory" due-to="Gary Gregory">Add CSVParser#stream().</action>
6364
<!-- UPDATE -->
6465
<action type="update" dev="ggregory" due-to="Gary Gregory">Update org.junit.jupiter:junit-jupiter from 5.6.0 to 5.7.0, #84 #109</action>
6566
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from Apache Commons Lang 3.9 to 3.12.0.</action>
6667
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from commons-io:commons-io 2.6 to 2.10.0, #108.</action>
6768
<action type="update" dev="ggregory" due-to="Dependabot">Bump actions/checkout from v1 to v2.3.4, #79, #92, #121.</action>
6869
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons-parent from 50 to 51 #80.</action>
69-
<action type="update" dev="ggregory" due-to="Gary Gregory">Update maven-checkstyle-plugin from 3.0.0 to 3.1.1.</action>
7070
<action type="update" dev="ggregory" due-to="Dependabot">Bump tests from opencsv from 3.1 to 5.2 #81.</action>
71-
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump tests from org.mockito:mockito-core 3.2.4 -> 3.4.6; #88.</action>
7271
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from super-csv from 2.2.1 to 2.4.0 #86.</action>
73-
<action type="update" dev="ggregory" due-to="Dependabot">Bump tests mockito-core from 3.4.6 to 3.5.11 #107, #110.</action>
7472
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump build actions/setup-java from v1.4.0 to v2, #101, #113.</action>
7573
<action type="update" dev="ggregory" due-to="Dependabot">Bump maven-pmd-plugin from 3.13.0 to 3.14.0 #122.</action>
76-
<action type="update" dev="ggregory" due-to="Dependabot">Bump mockito-core from 3.5.11 to 3.11.2, #123, #128, #129, #156.</action>
74+
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump tests from org.mockito:mockito-core 3.2.4 -> 3.11.2; #88, #107, #110, #123, #128, #129, #156.</action>
7775
<action type="update" dev="ggregory" due-to="Dependabot">Bump actions/cache from v2 to v2.1.6 #132, #153.</action>
78-
<action type="update" dev="ggregory" due-to="Dependabot">Bump maven-checkstyle-plugin from 3.1.1 to 3.1.2 #131.</action>
76+
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump maven-checkstyle-plugin from 3.0.0 to 3.1.2 #131.</action>
77+
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump checkstyle from 8.29 to 8.44.</action>
7978
<action type="update" dev="ggregory" due-to="Dependabot">Bump junit-jupiter from 5.7.0 to 5.7.2 #133, #149.</action>
8079
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons.jacoco.version from 0.8.5 to 0.8.7 (Java 16).</action>
8180
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons.spotbugs.version from 4.0.4 to 4.2.3 (Java 16).</action>
81+
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump commons.javadoc.version from 3.2.0 to 3.3.0.</action>
8282
</release>
8383
<release version="1.8" date="2020-02-01" description="Feature and bug fix release (Java 8).
8484

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
import java.util.Map;
4141
import java.util.NoSuchElementException;
4242
import java.util.Objects;
43+
import java.util.Spliterator;
44+
import java.util.Spliterators;
4345
import java.util.TreeMap;
46+
import java.util.stream.Stream;
47+
import java.util.stream.StreamSupport;
4448

4549
/**
4650
* Parses CSV files according to the specified format.
@@ -712,4 +716,14 @@ CSVRecord nextRecord() throws IOException {
712716
return result;
713717
}
714718

719+
/**
720+
* Returns a sequential {@code Stream} with this collection as its source.
721+
*
722+
* @return a sequential {@code Stream} with this collection as its source.
723+
* @since 1.9.0
724+
*/
725+
public Stream<CSVRecord> stream() {
726+
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator(), Spliterator.ORDERED), false);
727+
}
728+
715729
}

src/site/resources/checkstyle/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ limitations under the License.
5656
</module>
5757

5858
<module name="LineLength">
59-
<property name="max" value="120"/>
59+
<property name="max" value="160"/>
6060
</module>
6161

6262
<module name="TreeWalker">

src/site/resources/pmd/pmd-ruleset.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@
7777
<rule ref="category/java/performance.xml/BigIntegerInstantiation"/>
7878
<rule ref="category/java/performance.xml/BooleanInstantiation"/>
7979

80-
<!-- Rule customisations. -->
80+
<!-- Custom rules. -->
8181

8282
<rule ref="category/java/codestyle.xml/TooManyStaticImports">
8383
<properties>
8484
<property name="violationSuppressXPath"
85-
value="//ClassOrInterfaceDeclaration[@Image='CSVFormat' or @Image='Lexer']"/>
85+
value="//ClassOrInterfaceDeclaration[.[typeIs('org.apache.commons.csv.CSVFormat')]]" />
86+
<property name="violationSuppressXPath"
87+
value="//ClassOrInterfaceDeclaration[.[typeIs('org.apache.commons.csv.Lexer')]]" />
8688
</properties>
8789
</rule>
8890

src/test/java/org/apache/commons/csv/CSVParserTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.List;
4949
import java.util.Map;
5050
import java.util.NoSuchElementException;
51+
import java.util.stream.Collectors;
5152

5253
import org.apache.commons.io.input.BOMInputStream;
5354
import org.junit.jupiter.api.Disabled;
@@ -1159,6 +1160,16 @@ public void testStartWithEmptyLinesThenHeaders() throws Exception {
11591160
}
11601161
}
11611162

1163+
@Test
1164+
public void testStream() throws Exception {
1165+
final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
1166+
final List<CSVRecord> list = CSVFormat.DEFAULT.parse(in).stream().collect(Collectors.toList());
1167+
assertFalse(list.isEmpty());
1168+
assertArrayEquals(new String[] { "a", "b", "c" }, list.get(0).values());
1169+
assertArrayEquals(new String[] { "1", "2", "3" }, list.get(1).values());
1170+
assertArrayEquals(new String[] { "x", "y", "z" }, list.get(2).values());
1171+
}
1172+
11621173
@Test
11631174
public void testTrailingDelimiter() throws Exception {
11641175
final Reader in = new StringReader("a,a,a,\n\"1\",\"2\",\"3\",\nx,y,z,");

0 commit comments

Comments
 (0)