You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/07/03 14:31:55 UTC
[commons-csv] 05/05: # WARNING: head commit changed in the meantime
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git
commit 02efd1604fef72aeaa67e70c67202d58830111f7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jul 3 10:31:46 2021 -0400
# 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.
---
pom.xml | 38 ++++++++++++++--------
src/changes/changes.xml | 12 +++----
.../java/org/apache/commons/csv/CSVParser.java | 14 ++++++++
src/site/resources/checkstyle/checkstyle.xml | 2 +-
src/site/resources/pmd/pmd-ruleset.xml | 6 ++--
.../java/org/apache/commons/csv/CSVParserTest.java | 11 +++++++
6 files changed, 60 insertions(+), 23 deletions(-)
diff --git a/pom.xml b/pom.xml
index d001676..cdd9cb6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -164,7 +164,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<commons.encoding>UTF-8</commons.encoding>
- <checkstyle.version>3.1.2</checkstyle.version>
+ <commons.checkstyle-plugin.version>3.1.2</commons.checkstyle-plugin.version>
+ <commons.checkstyle.version>8.44</commons.checkstyle.version>
<checkstyle.header.file>${basedir}/src/site/resources/checkstyle/checkstyle-header.txt</checkstyle.header.file>
<checkstyle.config.file>${basedir}/src/site/resources/checkstyle/checkstyle.xml</checkstyle.config.file>
<checkstyle.suppress.file>${basedir}/src/site/resources/checkstyle/checkstyle-suppressions.xml</checkstyle.suppress.file>
@@ -181,7 +182,28 @@
</properties>
<build>
- <defaultGoal>clean verify apache-rat:check clirr:check checkstyle:check spotbugs:check javadoc:javadoc</defaultGoal>
+ <defaultGoal>clean package apache-rat:check japicmp:cmp checkstyle:check spotbugs:check javadoc:javadoc</defaultGoal>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${commons.checkstyle-plugin.version}</version>
+ <configuration>
+ <configLocation>${checkstyle.config.file}</configLocation>
+ <enableRulesSummary>false</enableRulesSummary>
+ <suppressionsLocation>${checkstyle.suppress.file}</suppressionsLocation>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>com.puppycrawl.tools</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>${commons.checkstyle.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
@@ -214,12 +236,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
- <version>${checkstyle.version}</version>
- <configuration>
- <configLocation>${checkstyle.config.file}</configLocation>
- <enableRulesSummary>false</enableRulesSummary>
- <suppressionsLocation>${checkstyle.suppress.file}</suppressionsLocation>
- </configuration>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
@@ -285,12 +301,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
- <version>${checkstyle.version}</version>
- <configuration>
- <configLocation>${checkstyle.config.file}</configLocation>
- <enableRulesSummary>false</enableRulesSummary>
- <suppressionsLocation>${checkstyle.suppress.file}</suppressionsLocation>
- </configuration>
<!-- We need to specify reportSets because 2.9.1 creates two reports -->
<reportSets>
<reportSet>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0166560..61527cd 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -59,26 +59,26 @@
<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>
<!-- ADD -->
<action issue="CSV-275" type="add" dev="ggregory" due-to="Michael Wyraz, Gary Gregory">Make CSVRecord#toList() public.</action>
- <action type="add" dev="ggregory" due-to="Gary Gregory">Add CSVRecord#toStream().</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add CSVRecord#stream().</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add CSVParser#stream().</action>
<!-- UPDATE -->
<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>
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from Apache Commons Lang 3.9 to 3.12.0.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from commons-io:commons-io 2.6 to 2.10.0, #108.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump actions/checkout from v1 to v2.3.4, #79, #92, #121.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons-parent from 50 to 51 #80.</action>
- <action type="update" dev="ggregory" due-to="Gary Gregory">Update maven-checkstyle-plugin from 3.0.0 to 3.1.1.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump tests from opencsv from 3.1 to 5.2 #81.</action>
- <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>
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from super-csv from 2.2.1 to 2.4.0 #86.</action>
- <action type="update" dev="ggregory" due-to="Dependabot">Bump tests mockito-core from 3.4.6 to 3.5.11 #107, #110.</action>
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump build actions/setup-java from v1.4.0 to v2, #101, #113.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump maven-pmd-plugin from 3.13.0 to 3.14.0 #122.</action>
- <action type="update" dev="ggregory" due-to="Dependabot">Bump mockito-core from 3.5.11 to 3.11.2, #123, #128, #129, #156.</action>
+ <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>
<action type="update" dev="ggregory" due-to="Dependabot">Bump actions/cache from v2 to v2.1.6 #132, #153.</action>
- <action type="update" dev="ggregory" due-to="Dependabot">Bump maven-checkstyle-plugin from 3.1.1 to 3.1.2 #131.</action>
+ <action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump maven-checkstyle-plugin from 3.0.0 to 3.1.2 #131.</action>
+ <action type="update" dev="ggregory" due-to="Gary Gregory">Bump checkstyle from 8.29 to 8.44.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump junit-jupiter from 5.7.0 to 5.7.2 #133, #149.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons.jacoco.version from 0.8.5 to 0.8.7 (Java 16).</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump commons.spotbugs.version from 4.0.4 to 4.2.3 (Java 16).</action>
+ <action type="update" dev="ggregory" due-to="Gary Gregory">Bump commons.javadoc.version from 3.2.0 to 3.3.0.</action>
</release>
<release version="1.8" date="2020-02-01" description="Feature and bug fix release (Java 8).
diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java
index 286901a..11ea355 100644
--- a/src/main/java/org/apache/commons/csv/CSVParser.java
+++ b/src/main/java/org/apache/commons/csv/CSVParser.java
@@ -40,7 +40,11 @@ import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
+import java.util.Spliterator;
+import java.util.Spliterators;
import java.util.TreeMap;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
/**
* Parses CSV files according to the specified format.
@@ -712,4 +716,14 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
return result;
}
+ /**
+ * Returns a sequential {@code Stream} with this collection as its source.
+ *
+ * @return a sequential {@code Stream} with this collection as its source.
+ * @since 1.9.0
+ */
+ public Stream<CSVRecord> stream() {
+ return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator(), Spliterator.ORDERED), false);
+ }
+
}
diff --git a/src/site/resources/checkstyle/checkstyle.xml b/src/site/resources/checkstyle/checkstyle.xml
index 6fb154d..59d5fc9 100644
--- a/src/site/resources/checkstyle/checkstyle.xml
+++ b/src/site/resources/checkstyle/checkstyle.xml
@@ -56,7 +56,7 @@ limitations under the License.
</module>
<module name="LineLength">
- <property name="max" value="120"/>
+ <property name="max" value="160"/>
</module>
<module name="TreeWalker">
diff --git a/src/site/resources/pmd/pmd-ruleset.xml b/src/site/resources/pmd/pmd-ruleset.xml
index 8d52e45..21bae90 100644
--- a/src/site/resources/pmd/pmd-ruleset.xml
+++ b/src/site/resources/pmd/pmd-ruleset.xml
@@ -77,12 +77,14 @@
<rule ref="category/java/performance.xml/BigIntegerInstantiation"/>
<rule ref="category/java/performance.xml/BooleanInstantiation"/>
- <!-- Rule customisations. -->
+ <!-- Custom rules. -->
<rule ref="category/java/codestyle.xml/TooManyStaticImports">
<properties>
<property name="violationSuppressXPath"
- value="//ClassOrInterfaceDeclaration[@Image='CSVFormat' or @Image='Lexer']"/>
+ value="//ClassOrInterfaceDeclaration[.[typeIs('org.apache.commons.csv.CSVFormat')]]" />
+ <property name="violationSuppressXPath"
+ value="//ClassOrInterfaceDeclaration[.[typeIs('org.apache.commons.csv.Lexer')]]" />
</properties>
</rule>
diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java
index 01a8ba8..02d8c6c 100644
--- a/src/test/java/org/apache/commons/csv/CSVParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java
@@ -48,6 +48,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
+import java.util.stream.Collectors;
import org.apache.commons.io.input.BOMInputStream;
import org.junit.jupiter.api.Disabled;
@@ -1160,6 +1161,16 @@ public class CSVParserTest {
}
@Test
+ public void testStream() throws Exception {
+ final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
+ final List<CSVRecord> list = CSVFormat.DEFAULT.parse(in).stream().collect(Collectors.toList());
+ assertFalse(list.isEmpty());
+ assertArrayEquals(new String[] { "a", "b", "c" }, list.get(0).values());
+ assertArrayEquals(new String[] { "1", "2", "3" }, list.get(1).values());
+ assertArrayEquals(new String[] { "x", "y", "z" }, list.get(2).values());
+ }
+
+ @Test
public void testTrailingDelimiter() throws Exception {
final Reader in = new StringReader("a,a,a,\n\"1\",\"2\",\"3\",\nx,y,z,");
final Iterator<CSVRecord> records = CSVFormat.DEFAULT.withHeader("X", "Y", "Z").withSkipHeaderRecord()