Skip to content

Commits on Source 19

......@@ -3,3 +3,5 @@ build/*
lib/*
_site
gradle.properties
.idea
groovycsv.iml
\ No newline at end of file
Copyright 2010 Leonard Axelsson
Copyright 2016 Leonard Gram
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......
......@@ -2,23 +2,18 @@
GroovyCSV is a library for Groovy which aims to make csv data
easier (and more idiomatically Groovy) to work with. The library was inspired by @[goeh's](http://twitter.com/goeh)
[ExcelBuilder](http://www.technipelago.se/blog/?p=44) that lets you
[ExcelBuilder](http://www.technipelago.se/blog/show/groovy-poi-excel) that lets you
iterate over rows in the excel file using `eachLine` and access values
using the column names.
*Important*
Package structure was changed from `com.xlson.csvparser` to
`com.xlson.groovycsv` between release 0.1 and 0.2.
## Features
* Value-access by header name or position
* Iteration using the ordinary collection methods (`findAll`, `collect`
and so on)
* Full support for OpenCSV's configurability
* Support for guessing separator and/or quote character
* Support for reading csv without headers
* Support for skipping initial lines of the csv
## Example
......@@ -26,7 +21,7 @@ The parse method returns an iterator over the rows in the csv. This
means we can use any of the default groovy ways to iterate, in this
example we see the for each loop in use.
@Grab('com.xlson.groovycsv:groovycsv:1.0')
@Grab('com.xlson.groovycsv:groovycsv:1.3')
import static com.xlson.groovycsv.CsvParser.parseCsv
def csv = '''Name,Lastname
......@@ -47,8 +42,7 @@ The parse method takes a String or a Reader as argument.
## Getting GroovyCSV
GroovyCSV is available in Maven Central. It is also available directly from GitHub
(links below).
GroovyCSV is available through Maven Central.
### Maven & Ivy configuration
......@@ -56,27 +50,29 @@ GroovyCSV is available in Maven Central. It is also available directly from GitH
* *GroupId:* com.xlson.groovycsv
* *ArtifactId:* groovycsv
* *Version:* 1.0
* *Version:* 1.3
#### Latest snapshot
* *Version:* 1.0-SNAPSHOT
* *Version:* 1.3-SNAPSHOT
* *Repository:* https://oss.sonatype.org/content/groups/public/
### Downloads
*GroovyCSV 1.0*
*GroovyCSV 1.3*
* [groovycsv-1.0.jar](https://github.com/downloads/xlson/groovycsv/groovycsv-0.2.jar)
* [groovycsv-1.0-javadoc.jar](https://github.com/downloads/xlson/groovycsv/groovycsv-0.2-javadoc.jar)
* [Javadoc Online](http://xlson.github.com/groovycsv/docs/1.0/javadoc/)
* [groovycsv-1.3.jar](http://repo1.maven.org/maven2/com/xlson/groovycsv/groovycsv/1.3/groovycsv-1.3.jar)
* [groovycsv-1.3-javadoc.jar](http://repo1.maven.org/maven2/com/xlson/groovycsv/groovycsv/1.3/groovycsv-1.3-javadoc.jar)
* [Javadoc Online](http://xlson.github.com/groovycsv/docs/1.3/javadoc/)
## Dependencies
* [Groovy 1.7.x](http://groovy.codehaus.org)
* [OpenCSV 2.x](http://opencsv.sourceforge.net/)
* [Groovy 1.8.x](http://groovy.codehaus.org) or later
* [OpenCSV 4.x](http://opencsv.sourceforge.net/)
Many thanks to Glen Smith and the other's in the OpenCSV team for
Many thanks to everyone who's contributed to the project and everyone in the OpenCSV team for
doing all the heavy lifting.
## Building
......
......@@ -10,23 +10,23 @@ buildscript {
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: de.huxhorn.gradle.pgp.PgpPlugin
apply plugin: 'signing'
apply plugin: 'idea'
repositories {
mavenCentral()
mavenRepo urls: "http://m2repo.spockframework.org/snapshots"
maven { url "http://m2repo.spockframework.org/snapshots" }
}
dependencies {
groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.7.3'
compile 'net.sf.opencsv:opencsv:2.1'
testCompile "org.spockframework:spock-core:0.4-groovy-1.7"
testCompile "cglib:cglib-nodep:2.2"
testCompile "org.objenesis:objenesis:1.2"
compile 'com.opencsv:opencsv:4.0'
compileOnly 'org.codehaus.groovy:groovy-all:1.8.8'
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4-rc-2'
testCompile 'cglib:cglib-nodep:2.2'
testCompile 'org.objenesis:objenesis:1.2'
}
version = '1.0'
version = '1.3'
group = 'com.xlson.groovycsv'
sourceSets {
......@@ -53,56 +53,83 @@ task sourcesJar(type: Jar) {
}
artifacts {
archives groovydocJar
archives sourcesJar
archives groovydocJar, sourcesJar
}
if(isSetupForDeployToMavenCentral()) {
signing {
sign configurations.archives
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.3.1'
}
task downloadDeps << {
def libDir = file('lib')
ant.delete(dir: libDir)
copy {
from configurations.testRuntime
into libDir
}
}
def deployer = null
def installer = install.repositories.mavenInstaller
uploadArchives {
// Checks if login information for the logon repo is set correctly.
// Should be set in gradle.properties (check gradle.properties.example)
if(project.hasProperty('repoUserName') && project.hasProperty('repoPassword')) {
repositories {
deployer = mavenDeployer {
configureAuth = {
authentication(userName: repoUserName, password: repoPassword)
def isSetupForDeployToMavenCentral() {
def requiredProperties = ['ossrhUsername',
'ossrhPassword',
'signing.keyId',
'signing.password',
'signing.secretKeyRingFile']
for(prop in requiredProperties) {
if(!project.hasProperty(prop)) {
return false
}
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/", configureAuth)
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/", configureAuth)
return true
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
if(isSetupForDeployToMavenCentral()) {
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
}
[installer, deployer]*.pom*.whenConfigured {pom ->
pom.project {
name 'GroovyCSV'
packaging 'jar' // not working
packaging 'jar'
// optionally artifactId can be defined here
description 'Library for parsing csv in Groovy'
url 'http://github.com/xlson/groovycsv'
inceptionYear '2010'
scm {
url 'scm:git:git@github.com:xlson/groovycsv.git'
connection 'http://github.com/xlson/groovycsv'
connection 'scm:git:git@github.com:xlson/groovycsv.git'
developerConnection 'scm:git:git@github.com:xlson/groovycsv.git'
url 'http://github.com/xlson/groovycsv'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'xlson'
name 'Leonard Axelsson'
email 'leonard.axelsson@gmail.com'
name 'Leonard Gram'
email 'leo@xlson.com'
url 'http://xlson.com/'
timezone '+1'
}
......@@ -123,16 +150,5 @@ uploadArchives {
xml.append(newXml.toString())
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.0-milestone-3'
}
task downloadDeps << {
def libDir = file('lib')
ant.delete(dir: libDir)
copy {
from configurations.testRuntime
into libDir
}
}
groovycsv (1.3-1) unstable; urgency=medium
* Team upload.
* New upstream version 1.3
* Removing patches, as all of them seem to be integrated upstream.
* Bumping Standards-Version (no changes).
* Bumping debhelper compatibility level (no changes).
* Updating Vcs-* tags in debian/control.
* Enabling the build time tests.
* Adding a patch migrating the code to use opencsv v5.
* Removing 'get-orig-source' target.
* Switching URLs from HTTP to HTTPS.
-- Andrius Merkys <merkys@debian.org> Tue, 05 Nov 2019 10:17:55 -0500
groovycsv (1.0-2) unstable; urgency=medium
* Fixed the build failure caused by the transition from groovy2 to groovy
......
......@@ -2,20 +2,27 @@ Source: groovycsv
Section: java
Priority: optional
Maintainer: Debian Java Maintainers <pkg-java-maintainers@lists.alioth.debian.org>
Uploaders: Emmanuel Bourg <ebourg@apache.org>
Build-Depends: debhelper (>= 9),
Uploaders:
Emmanuel Bourg <ebourg@apache.org>,
Build-Depends:
debhelper (>= 12),
default-jdk,
gradle-debian-helper,
libcglib-nodep-java <!nocheck>,
libobjenesis-java <!nocheck>,
libopencsv-java,
maven-repo-helper
Standards-Version: 3.9.8
Vcs-Git: https://anonscm.debian.org/git/pkg-java/groovycsv.git
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/groovycsv.git
Homepage: http://github.com/xlson/groovycsv
libspock-java <!nocheck>,
maven-repo-helper,
Standards-Version: 4.4.1
Vcs-Git: https://salsa.debian.org/java-team/groovycsv.git
Vcs-Browser: https://salsa.debian.org/java-team/groovycsv
Homepage: https://github.com/xlson/groovycsv
Package: libgroovycsv-java
Architecture: all
Depends: libopencsv-java, ${misc:Depends}
Depends:
libopencsv-java,
${misc:Depends},
Description: CSV parsing library for Groovy
GroovyCSV is a library to make CSV processing just a little bit
Groovier. The library uses opencsv behind the scenes and merely
......
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: GroovyCSV
Source: http://github.com/xlson/groovycsv
Source: https://github.com/xlson/groovycsv
Files-Excluded: gradlew*
gradle/
......
cglib cglib-nodep * * * *
de.huxhorn.gradle de.huxhorn.gradle.pgp-plugin * * * *
org.objenesis objenesis * * * *
org.spockframework spock-core * * * *
cglib cglib-nodep * s/.*/3.x/ * *
Description: Ignore the GPG plugin (not needed)
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
--- a/build.gradle
+++ b/build.gradle
@@ -10,7 +10,7 @@
apply plugin: 'groovy'
apply plugin: 'maven'
-apply plugin: de.huxhorn.gradle.pgp.PgpPlugin
+//apply plugin: de.huxhorn.gradle.pgp.PgpPlugin
apply plugin: 'idea'
repositories {
Description: Fixes the compatibility with the latest version of Gradle
Origin: backport, https://github.com/xlson/groovycsv/commit/1e3d41e
--- a/build.gradle
+++ b/build.gradle
@@ -15,11 +15,11 @@
repositories {
mavenCentral()
- mavenRepo urls: "http://m2repo.spockframework.org/snapshots"
+ maven { url "http://m2repo.spockframework.org/snapshots" }
}
dependencies {
- groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.7.3'
+ compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.7.3'
compile 'net.sf.opencsv:opencsv:2.1'
testCompile "org.spockframework:spock-core:0.4-groovy-1.7"
testCompile "cglib:cglib-nodep:2.2"
Description: Use groovy-all to build test code.
Author: Andrius Merkys <merkys@debian.org>
--- a/build.gradle
+++ b/build.gradle
@@ -20,7 +20,7 @@
dependencies {
compile 'com.opencsv:opencsv:4.0'
- compileOnly 'org.codehaus.groovy:groovy-all:1.8.8'
+ compile 'org.codehaus.groovy:groovy-all:1.8.8'
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4-rc-2'
testCompile 'cglib:cglib-nodep:2.2'
testCompile 'org.objenesis:objenesis:1.2'
Description: Migrate the code to use opencsv v5.
Author: Andrius Merkys <merkys@debian.org>
--- a/src/com/xlson/groovycsv/CsvParser.groovy
+++ b/src/com/xlson/groovycsv/CsvParser.groovy
@@ -16,7 +16,11 @@
package com.xlson.groovycsv
+import com.opencsv.CSVParser
import com.opencsv.CSVReader
+import com.opencsv.ICSVParser
+import com.opencsv.validators.LineValidatorAggregator
+import com.opencsv.validators.RowValidatorAggregator
/**
* Helper class used to parse information from csv files using the column names
@@ -152,11 +156,23 @@
quoteChar = args.quoteChar ?: '"'
}
- if (escapeChar != null) {
- return new CSVReader(reader, separator, quoteChar, escapeChar, skipLines)
- } else {
- return new CSVReader(reader, separator, quoteChar, skipLines)
+ if (escapeChar == null) {
+ escapeChar = ICSVParser.DEFAULT_ESCAPE_CHARACTER
}
+ CSVParser parser = new CSVParser(separator, quoteChar, escapeChar,
+ ICSVParser.DEFAULT_STRICT_QUOTES,
+ ICSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE,
+ ICSVParser.DEFAULT_IGNORE_QUOTATIONS,
+ ICSVParser.DEFAULT_NULL_FIELD_INDICATOR,
+ Locale.getDefault())
+ return new CSVReader(reader, skipLines, parser,
+ CSVReader.DEFAULT_KEEP_CR,
+ CSVReader.DEFAULT_VERIFY_READER,
+ CSVReader.DEFAULT_MULTILINE_LIMIT,
+ Locale.getDefault(),
+ new LineValidatorAggregator(),
+ new RowValidatorAggregator(),
+ null)
}
/**
01-ignore-gpg-plugin.patch
02-gradle-compatibility.patch
enable-tests.patch
migrate-to-opencsv-v5.patch
......@@ -5,5 +5,9 @@ export JAVA_HOME := /usr/lib/jvm/default-java
%:
dh $@ --buildsystem=gradle --with maven-repo-helper
get-orig-source:
uscan --download-current-version --force-download --no-symlink
# Quick-and-dirty way to execute build time tests using gradle-debian-helper.
# See #934729 for the description.
override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
dh_auto_build -- test
endif
// This must be configured if you wanna deploy to the Nexus OSS Public Repo
repoUserName=usernameHere
repoPassword=passwordHere
signing.keyId=
signing.password=
signing.secretKeyRingFile=
ossrhUsername=
ossrhPassword=
/*
* Copyright 2010 Leonard Axelsson
* Copyright 2010 Leonard Gram
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -16,12 +16,12 @@
package com.xlson.groovycsv
import au.com.bytecode.opencsv.CSVReader
import com.opencsv.CSVReader
/**
* Iterates over the csv data in a non-synchronized way.
*
* @author Leonard Axelsson
* @author Leonard Gram
* @since 0.1
*/
class CsvIterator implements Iterator {
......@@ -65,11 +65,10 @@ class CsvIterator implements Iterator {
boolean hasNext() {
if (isClosed()) {
return false
}
else if(nextValueIsRead()) {
} else if (nextValueIsRead()) {
return true
} else {
readValue = csvReader.readNext()
readValue = getNextValue()
if (readValue == null) {
close()
}
......@@ -97,10 +96,24 @@ class CsvIterator implements Iterator {
readValue = null
return value
} else {
return csvReader.readNext()
def nextValue
for (; ;) {
nextValue = csvReader.readNext()
if (nextValue == null) {
break
} else if (isEmptyLine(nextValue)) {
// Continues the loop and reads another value
} else {
break
}
}
return nextValue
}
}
private boolean isEmptyLine(String[] nextValue) {
nextValue.size() == 1 && nextValue.first().isEmpty()
}
/**
* Gets the next row in the csv file.
......
/*
* Copyright 2010 Leonard Axelsson
* Copyright 2010 Leonard Gram
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -16,7 +16,7 @@
package com.xlson.groovycsv
import au.com.bytecode.opencsv.CSVReader
import com.opencsv.CSVReader
/**
* Helper class used to parse information from csv files using the column names
......@@ -30,12 +30,11 @@ import au.com.bytecode.opencsv.CSVReader
* Pete,Hansen'''
*
* def data = new CsvParser().parse(csv)
* for(line in data) {
* println "$line.Name $line.Lastname"
* for(line in data) {* println "$line.Name $line.Lastname"
*}</pre>
*
*
* @author Leonard Axelsson
* @author Leonard Gram
* @since 0.1
*/
class CsvParser {
......@@ -91,10 +90,12 @@ class CsvParser {
* Arguments for configuration:
* <li>separator: configures the separator character to use (default: ,)
* <li>quoteChar: configures the quote character to use (default: ")
* <li>escapeChar: configures the escape character for the separator and quoteChar (default:\
* <li>escapeChar: configures the escape character for the separator and quoteChar (default:\)
* <li>autoDetect: sets up autodetect that will honor other configurations you've done (default: false)
* <li>columnNames: set custom column names instead of using the first line
* <li>readFirstLine: reads the first line as csv instead of using it as headers
* <li>trimWhitespaceFromColumnNames: trims leading and trailing whitespace for column names when parsing them (default: false)
* <li>skipLines: skips the specified number of lines at the beginning (default: 0)
*
* <p>
* Usage:
......@@ -106,8 +107,7 @@ class CsvParser {
* def data = new CsvParser().parse(csv, separator: '-')
*
* // Print all fruits that have a quantity higher than 3
* data.findAll{ (it.Quantity as int) > 3 }.each{ println it }
* </pre>
* data.findAll{ (it.Quantity as int) > 3 }.each{ println it }* </pre>
* </p>
* @param reader the csv to parse
* @param args the configuration arguments
......@@ -129,13 +129,18 @@ class CsvParser {
if (args.columnNames) {
columnNames = args.columnNames
}
if (args.trimWhitespaceFromColumnNames) {
columnNames = columnNames.collect { it.toString().trim() }
}
return columnNames
}
private CSVReader createCSVReader(Map args = [:], Reader reader) {
char separator
char quoteChar
char escapeChar = args.escapeChar
Character separator
Character quoteChar
Character escapeChar = args.escapeChar
Integer skipLines = args.skipLines ?: 0
if (args.autoDetect == true) {
reader = new PushbackReader(reader, autoDetectCharNumber)
......@@ -147,10 +152,10 @@ class CsvParser {
quoteChar = args.quoteChar ?: '"'
}
if(escapeChar) {
return new CSVReader(reader, separator, quoteChar, escapeChar)
if (escapeChar != null) {
return new CSVReader(reader, separator, quoteChar, escapeChar, skipLines)
} else {
return new CSVReader(reader, separator, quoteChar)
return new CSVReader(reader, separator, quoteChar, skipLines)
}
}
......