Skip to content

Commit

Permalink
renamed package name and removed off unused code and added authors de…
Browse files Browse the repository at this point in the history
…tails.
  • Loading branch information
sachin-verma committed Jul 9, 2015
1 parent ed39857 commit 059e5cc
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 46 deletions.
2 changes: 1 addition & 1 deletion grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
grails {
profile = 'web'
codegen {
defaultPackage = 'org.grails.plugins'
defaultPackage = 'grails.plugins.csv'
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.grails.plugins.csv
package grails.plugins.csv

class CsvTestController {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.grails.plugins.csv
package grails.plugins.csv

import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration
Expand Down
3 changes: 0 additions & 3 deletions resources/fileTest.csv

This file was deleted.

3 changes: 0 additions & 3 deletions resources/mapTest.csv

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.grails.plugins.csv
package grails.plugins.csv

import grails.test.mixin.integration.Integration
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
* under the License.
*/
package org.grails.plugins.csv
package grails.plugins.csv

import grails.test.mixin.TestFor
import grails.test.mixin.integration.Integration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.grails.plugins.csv
package grails.plugins.csv

import grails.test.mixin.integration.Integration
import grails.transaction.*
Expand All @@ -16,13 +16,6 @@ class CsvTestControllerGebSpec extends GebSpec {
def cleanup() {
}

void "canary test"() {
when: "The home page is visited"
go '/'

then: "The title is correct"
$('title').text() == "Welcome to Grails"
}

void "test writeCsv"(){
when: "writeCsv action is visited"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.grails.plugins.csv
package grails.plugins.csv

import grails.test.mixin.TestFor
import spock.lang.Specification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
* under the License.
*/
package org.grails.plugins.csv
package grails.plugins.csv

import au.com.bytecode.opencsv.CSVReader

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
* under the License.
*/
package org.grails.plugins.csv
package grails.plugins.csv

import au.com.bytecode.opencsv.CSVParser
import au.com.bytecode.opencsv.CSVReader
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package org.grails.plugins.csv
package grails.plugins.csv
/**
* Writes CSV content to a given writer, using a definition DSL.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.grails.plugins.csv
package grails.plugins.csv

import au.com.bytecode.opencsv.CSVReader
import grails.core.GrailsApplication
import grails.plugins.*
import org.grails.plugins.csv.CSVMapReader
import org.grails.plugins.csv.CSVReaderUtils
import org.grails.plugins.csv.controller.RenderCsvMethod
import grails.plugins.csv.controller.RenderCsvMethod

class GrailsCsvGrailsPlugin extends Plugin {

Expand All @@ -16,15 +15,69 @@ class GrailsCsvGrailsPlugin extends Plugin {
]

// TODO Fill in these fields
def title = "Grails Csv" // Headline display name of the plugin
def author = "Your name"
def authorEmail = ""
def description = '''\
Brief summary/description of the plugin.
'''
def author = "Les Hazlewood"
def authorEmail = "[email protected]"
def title = "Grails CSV Plugin"
def description = '''
The Grails CSV Plugin allows you to easily parse and consume CSV data from a number of input sources. It
supports complex parsing scenarios such as nested commas inside quotes, escaped tokens, multi-line quoted
values and allows configuration of parsing options (separator char, escape char, text encoding, etc). It is
based on Glen Smith (et. al.)'s OpenCSV project (http://opencsv.sourceforge.net)
This plugin adds two dynamic methods 'eachCsvLine' and 'toCsvReader' to each of the following classes:
- java.lang.String
- java.io.File
- java.io.InputStream
- java.io.Reader
Using it is extremely simple. On any instance of the four data types, call the 'eachCvsLine' method with a
closure accepting the tokens (a String array) for each parsed line:
"hello, world, how, are, you".eachCsvLine { tokens ->
//only one line in this case and tokens.length == 5
}
new File("iso3166Countries.csv").eachCsvLine { tokens ->
new Country(tokens[0], //ISO 3166 country name
tokens[1]).save() //ISO 3166 2 letter character code
}
Configuration
If you need to specify how the parsing should occur, you can construct your own csv reader with a map of
configuration options and call the 'eachLine' method on the constructed reader:
anInputStream.toCsvReader(['charset':'UTF-8']).eachLine { tokens ->
...
}
The supported config options:
'separatorChar': the character to use as the delimiter to separate the tokens. Defaults to the comma: ','
'quoteChar': the character indicating a quoted string is about to follow. Internal separatorChars can be
inside the quoted string and they will not be split into tokens.
Defaults to the double quote char: '"'
'escapeChar': the character to escape an immediately following character, indicating to the parser not to treat
it as a special char. Defaults to the backslash char: '\'
'skipLines': the number of lines in the input source to skip before parsing begins. This is useful to skip
any potential CSV header lines that are not part of the CSV data. Defaults to zero '0'
'strictQuotes': if characters outside of quotes should be ignored (implying each individual token is
quoted. Defaults to false
'ignoreLeadingWhiteSpace': white space in front of a quoted token is ignored. Defaults to true
'charset': use the specified charset when parsing an InputStream. The value can be either the Charset name
as a String, a java.nio.charset.Charset instance, or a java.nio.charset.CharsetDecoder instance.
Defaults to the system default charset.
*Note that this option is ONLY valid for InputStream instances. It is ignored otherwise.
'''
// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/grails-csv"
def documentation = "http://grails.org/plugin/csv"

// Extra (optional) plugin metadata

Expand All @@ -35,7 +88,7 @@ Brief summary/description of the plugin.
// def organization = [ name: "My Company", url: "http://www.my-company.com/" ]

// Any additional developers beyond the author specified above.
// def developers = [ [ name: "Joe Bloggs", email: "[email protected]" ]]
def developers = [ [ name: "Sachin Verma", email: "[email protected]"],[ name: "Neha Gupta", email: "[email protected]"] ]

// Location of the plugin's issue tracker.
// def issueManagement = [ system: "JIRA", url: "http://jira.grails.org/browse/GPMYPLUGIN" ]
Expand Down Expand Up @@ -103,15 +156,17 @@ Brief summary/description of the plugin.
void onChange(Map<String, Object> event) {
// TODO Implement code that is executed when any artefact that this plugin is
// watching is modified and reloaded. The event contains: event.source,
// event.application, event.manager, event.ctx, and event.plugin.
if (grailsApplication.isControllerClass(event.source)) {
event.source.metaClass.renderCsv = renderCsvMethod
}
}

void onConfigChange(Map<String, Object> event) {
// TODO Implement code that is executed when the project configuration changes.
// The event is the same as for 'onChange'.
// if (grailsApplication.isControllerClass(event.source)) {
// event.source.metaClass.renderCsv = renderCsvMethod
// }
if (grailsApplication.isControllerClass(event.source)) {
event.source.metaClass.renderCsv = renderCsvMethod
}
}

void onShutdown(Map<String, Object> event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.grails.plugins.csv.controller
package grails.plugins.csv.controller

import org.grails.plugins.csv.CSVWriter
import grails.plugins.csv.CSVWriter

class RenderCsvMethod {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.grails.plugins.csv
package grails.plugins.csv


class CSVMapReaderBatchTest extends GroovyTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.grails.plugins.csv
package grails.plugins.csv


class CSVMapReaderTest extends GroovyTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
* limitations under the License.
* under the License.
*/
package org.grails.plugins.csv
package grails.plugins.csv

import au.com.bytecode.opencsv.CSVReader
import grails.test.mixin.TestFor

/**
* Unit tests for the {@link CSVReaderUtils} class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.grails.plugins.csv
package grails.plugins.csv

class CSVWriterTest extends GroovyTestCase {

Expand Down

0 comments on commit 059e5cc

Please sign in to comment.