Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplatform Setting #29

Merged
merged 20 commits into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ jobs:

- run:
command: |
./gradlew test
./gradlew jacocoTestReport
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO:
removed temporarily, so revert this diff when this PR is merged.

./gradlew check
bash <(curl -s https://codecov.io/bash)
148 changes: 91 additions & 57 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
plugins {
id("org.jetbrains.kotlin.jvm").version("1.3.41")
kotlin("multiplatform") version "1.3.50"
id("org.jetbrains.dokka").version("0.9.18")
jacoco
`maven-publish`
signing
}

group = "com.github.doyaaaaaken"
version = "0.6.1"
version = "0.7.0"

buildscript {
repositories {
Expand All @@ -22,64 +21,107 @@ repositories {
jcenter()
}

val test by tasks.getting(Test::class) {
useJUnitPlatform { }
kotlin {
jvm {
val main by compilations.getting {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}

jvm().compilations["main"].defaultSourceSet {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}
}
jvm().compilations["test"].defaultSourceSet {
dependencies {
implementation("io.kotlintest:kotlintest-runner-junit5:3.3.2")
}
}
}
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.3.2")
val jvmTest by tasks.getting(Test::class) {
useJUnitPlatform { }
}

////publishing settings
////https://docs.gradle.org/current/userguide/publishing_maven.html
//val sourcesJar = task<Jar>("sourcesJar") {
// from(sourceSets.main.get().allSource)
// archiveClassifier.set("sources")
//}
//val dokkaJar = task<Jar>("dokkaJar") {
// group = JavaBasePlugin.DOCUMENTATION_GROUP
// archiveClassifier.set("javadoc")
//}

//publishing settings
//https://docs.gradle.org/current/userguide/publishing_maven.html
val sourcesJar = task<Jar>("sourcesJar") {
from(sourceSets.main.get().allSource)
archiveClassifier.set("sources")
}
val dokkaJar = task<Jar>("dokkaJar") {
group = JavaBasePlugin.DOCUMENTATION_GROUP
archiveClassifier.set("javadoc")
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = "kotlin-csv"
from(components["java"])
artifacts {
artifact(sourcesJar)
artifact(dokkaJar)
}
pom {
name.set("kotlin-csv")
description.set("Kotlin CSV Reader/Writer")
url.set("https://github.com/doyaaaaaken/kotlin-csv")
// publications["jvm"].apply {
// artifactId = "kotlin-csv"
// from(components["java"])
// (this as MavenPublication).setArtifacts(dokkaJar)

organization {
name.set("com.github.doyaaaaaken")
url.set("https://github.com/doyaaaaaken")
}
licenses {
license {
name.set("Apache License 2.0")
url.set("https://github.com/doyaaaaaken/kotlin-csv/blob/master/LICENSE")
}
}
scm {
url.set("https://github.com/doyaaaaaken/kotlin-csv")
connection.set("scm:git:git://github.com/doyaaaaaken/kotlin-csv.git")
developerConnection.set("https://github.com/doyaaaaaken/kotlin-csv")
// artifacts {
// artifact(sourcesJar)
// artifact(dokkaJar)
// }
// }
publications.all {
(this as MavenPublication).pom {
name.set("kotlin-csv")
description.set("Kotlin CSV Reader/Writer")
url.set("https://github.com/doyaaaaaken/kotlin-csv")

organization {
name.set("com.github.doyaaaaaken")
url.set("https://github.com/doyaaaaaken")
}
licenses {
license {
name.set("Apache License 2.0")
url.set("https://github.com/doyaaaaaken/kotlin-csv/blob/master/LICENSE")
}
developers {
developer {
name.set("doyaaaaaken")
}
}
scm {
url.set("https://github.com/doyaaaaaken/kotlin-csv")
connection.set("scm:git:git://github.com/doyaaaaaken/kotlin-csv.git")
developerConnection.set("https://github.com/doyaaaaaken/kotlin-csv")
}
developers {
developer {
name.set("doyaaaaaken")
}
}
}
}
// publications {
// create<MavenPublication>("mavenJava") {
// artifactId = "kotlin-csv"
// from(components["java"])
// artifacts {
// artifact(sourcesJar)
// artifact(dokkaJar)
// }
// }
// }
repositories {
maven {
credentials {
Expand All @@ -97,13 +139,5 @@ publishing {
}

signing {
sign(publishing.publications["mavenJava"])
}

tasks.withType<JacocoReport> {
reports {
xml.isEnabled = true
xml.destination = File("$buildDir/reports/jacoco/report.xml")
html.isEnabled = false
}
sign(publishing.publications)
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rootProject.name = "kotlin-csv"
enableFeaturePreview("GRADLE_METADATA")
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.doyaaaaaken.kotlincsv.parser

import com.github.doyaaaaaken.kotlincsv.util.MalformedCSVException
import java.util.*

/**
* @author doyaaaaaaken
Expand All @@ -16,7 +15,7 @@ internal class ParseStateMachine(

private var state = ParseState.START

private val fields = Vector<String>()
private val fields = ArrayList<String>()

private var field = StringBuilder()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ package com.github.doyaaaaaken.kotlincsv.util
* @author doyaaaaaken
*/
internal object Const {
val defaultCharset = Charsets.UTF_8
val defaultCharset = "UTF-8"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.github.doyaaaaaken.kotlincsv.util

import java.lang.RuntimeException

/**
* @author doyaaaaaken
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.github.doyaaaaaken.kotlincsv.dsl.context.ICsvReaderContext
import java.io.BufferedReader
import java.io.File
import java.io.InputStream
import java.nio.charset.Charset

/**
* CSV Reader class
Expand All @@ -15,13 +16,15 @@ class CsvReader(
private val ctx: CsvReaderContext = CsvReaderContext()
) : ICsvReaderContext by ctx {

private val charsetCode = Charset.forName(charset)

/**
* read csv data as String, and convert into List<List<String>>
*
* No need to close InputStream when calling this method.
*/
fun readAll(data: String): List<List<String>> {
val br = data.byteInputStream(charset).bufferedReader(charset)
val br = data.byteInputStream(charsetCode).bufferedReader(charsetCode)
return open(br) { readAll() }
}

Expand All @@ -31,7 +34,7 @@ class CsvReader(
* No need to close InputStream when calling this method.
*/
fun readAll(file: File): List<List<String>> {
val br = file.inputStream().bufferedReader(charset)
val br = file.inputStream().bufferedReader(charsetCode)
return open(br) { readAll() }
}

Expand All @@ -41,7 +44,7 @@ class CsvReader(
* No need to close InputStream when calling this method.
*/
fun readAll(ips: InputStream): List<List<String>> {
val br = ips.bufferedReader(charset)
val br = ips.bufferedReader(charsetCode)
return open(br) { readAll() }
}

Expand All @@ -51,7 +54,7 @@ class CsvReader(
* No need to close InputStream when calling this method.
*/
fun readAllWithHeader(data: String): List<Map<String, String>> {
val br = data.byteInputStream(charset).bufferedReader(charset)
val br = data.byteInputStream(charsetCode).bufferedReader(charsetCode)
return open(br) { readAllWithHeader() }
}

Expand All @@ -61,7 +64,7 @@ class CsvReader(
* No need to close InputStream when calling this method.
*/
fun readAllWithHeader(file: File): List<Map<String, String>> {
val br = file.inputStream().bufferedReader(charset)
val br = file.inputStream().bufferedReader(charsetCode)
return open(br) { readAllWithHeader() }
}

Expand All @@ -71,7 +74,7 @@ class CsvReader(
* No need to close InputStream when calling this method.
*/
fun readAllWithHeader(ips: InputStream): List<Map<String, String>> {
val br = ips.bufferedReader(charset)
val br = ips.bufferedReader(charsetCode)
return open(br) { readAllWithHeader() }
}

Expand Down Expand Up @@ -104,7 +107,7 @@ class CsvReader(
* @see open method
*/
fun <T> open(file: File, read: CsvFileReader.() -> T): T {
val br = file.inputStream().bufferedReader(charset)
val br = file.inputStream().bufferedReader(charsetCode)
return open(br, read)
}

Expand All @@ -118,7 +121,7 @@ class CsvReader(
* @see open method
*/
fun <T> open(ips: InputStream, read: CsvFileReader.() -> T): T {
val br = ips.bufferedReader(charset)
val br = ips.bufferedReader(charsetCode)
return open(br, read)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.github.doyaaaaaken.kotlincsv.dsl.context

import com.github.doyaaaaaken.kotlincsv.util.Const
import com.github.doyaaaaaken.kotlincsv.util.CsvDslMarker
import java.nio.charset.Charset

/**
* Interface for CSV Reader settings
Expand All @@ -11,7 +10,7 @@ import java.nio.charset.Charset
*/
@CsvDslMarker
interface ICsvReaderContext {
val charset: Charset
val charset: String
val quoteChar: Char
val delimiter: Char
val escapeChar: Char
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.github.doyaaaaaken.kotlincsv.dsl.context

import com.github.doyaaaaaken.kotlincsv.util.Const
import com.github.doyaaaaaken.kotlincsv.util.CsvDslMarker
import java.nio.charset.Charset

/**
* Interface for CSV Writer settings
Expand All @@ -11,7 +10,7 @@ import java.nio.charset.Charset
*/
@CsvDslMarker
interface ICsvWriterContext {
val charset: Charset
val charset: String
val delimiter: Char
val nullCode: String
val lineTerminator: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.doyaaaaaken.kotlincsv.client

import io.kotlintest.shouldBe
import io.kotlintest.specs.WordSpec
import com.github.doyaaaaaken.kotlincsv.dsl.context.CsvReaderContext
import com.github.doyaaaaaken.kotlincsv.dsl.csvReader
import com.github.doyaaaaaken.kotlincsv.util.Const
import com.github.doyaaaaaken.kotlincsv.util.MalformedCSVException
import io.kotlintest.shouldBe
import io.kotlintest.shouldThrow
import java.io.File

Expand All @@ -22,13 +22,13 @@ class CsvReaderTest : WordSpec() {
}
"be created with CsvReaderContext argument" {
val context = CsvReaderContext().apply {
charset = Charsets.ISO_8859_1
charset = Charsets.ISO_8859_1.name()
quoteChar = '\''
delimiter = '\t'
escapeChar = '"'
}
val reader = CsvReader(context)
reader.charset shouldBe Charsets.ISO_8859_1
reader.charset shouldBe Charsets.ISO_8859_1.name()
reader.quoteChar shouldBe '\''
reader.delimiter shouldBe '\t'
reader.escapeChar shouldBe '"'
Expand Down Expand Up @@ -158,7 +158,7 @@ class CsvReaderTest : WordSpec() {
}

"open method (with fileName argument)" should {
val rows = csvReader().open("src/test/resources/testdata/csv/simple.csv") {
val rows = csvReader().open("src/jvmTest/resources/testdata/csv/simple.csv") {
readAll()
}
rows shouldBe listOf(listOf("a", "b", "c"), listOf("d", "e", "f"))
Expand All @@ -175,5 +175,5 @@ class CsvReaderTest : WordSpec() {
}

private fun readTestDataFile(fileName: String): File {
return File("src/test/resources/testdata/csv/$fileName")
return File("src/jvmTest/resources/testdata/csv/$fileName")
}
Loading