Skip to content

Commit

Permalink
Updating versions of kotlin, okio and kotlinx to latest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
orchestr7 committed Nov 22, 2021
1 parent 3c604d1 commit b1838ce
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 35 deletions.
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.akuleshov7.buildutils.*

plugins {
kotlin("multiplatform") version Versions.KOTLIN apply false
kotlin("multiplatform") apply false
kotlin("plugin.serialization") version Versions.KOTLIN apply false
}

Expand All @@ -10,7 +10,6 @@ configureVersioning()
allprojects {
repositories {
mavenCentral()
maven(url = "https://kotlin.bintray.com/kotlinx/")
}
configureDiktat()
configureDetekt()
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ repositories {
}

dependencies {
// this hack prevents the following bug: https://github.com/gradle/gradle/issues/9770
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0")

implementation("org.cqfn.diktat:diktat-gradle-plugin:1.0.0-rc.3")
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.15.0")
implementation("io.github.gradle-nexus:publish-plugin:1.1.0")
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/com/akuleshov7/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// now it is just a workaround

object Versions {
const val KOTLIN = "1.4.32"
const val KOTLIN = "1.6.0"
const val JUNIT = "5.7.1"
const val OKIO = "3.0.0-alpha.1"
const val SERIALIZATION = "1.2.1"
const val OKIO = "3.0.0"
const val SERIALIZATION = "1.3.1"
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
9 changes: 6 additions & 3 deletions ktoml-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {
}

kotlin {

explicitApi()
jvm {
compilations.all {
Expand All @@ -18,11 +17,17 @@ kotlin {
}
}

js(LEGACY)

linuxX64()
mingwX64()
macosX64()

sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
}

val commonMain by getting {
dependencies {
api("org.jetbrains.kotlinx:kotlinx-serialization-core:${Versions.SERIALIZATION}")
Expand Down Expand Up @@ -50,8 +55,6 @@ kotlin {
}
}

configurePublishing()

tasks.withType<KotlinJvmTest> {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public sealed class TomlNode(

// this constructor is used by TomlKeyValueList and TomlKeyValuePrimitive and we concatenate keyValuePair to the content
// only for logging, debug information and unification of the code
constructor(
private constructor(
key: TomlKey,
value: TomlValue,
lineNo: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SimpleArrayDecoderTest {
fun testRegressions() {
// ==== #77 ====
val testClassWithMutableList: ClassWithMutableList = Toml.decodeFromString("field = []")
assertEquals(emptyList(), testClassWithMutableList.field)
assertEquals(mutableListOf(), testClassWithMutableList.field)

val testClassWithImmutableList: ClassWithImmutableList = Toml.decodeFromString("field = []")
assertEquals(emptyList(), testClassWithImmutableList.field)
Expand Down
37 changes: 29 additions & 8 deletions ktoml-file/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.akuleshov7.buildutils.configurePublishing
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest

plugins {
Expand All @@ -9,6 +8,7 @@ plugins {

kotlin {
explicitApi()

jvm {
compilations.all {
kotlinOptions {
Expand All @@ -17,24 +17,46 @@ kotlin {
}
}

val os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem()
val os = getCurrentOperatingSystem()

when {
val target = listOf(when {
os.isWindows -> mingwX64()
os.isLinux -> linuxX64()
os.isMacOsX -> macosX64()
else -> throw GradleException("Unknown operating system $os")
}
})

sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
}

val nativeMain by creating {
dependencies {
implementation("com.squareup.okio:okio:${Versions.OKIO}")
implementation("org.jetbrains.kotlin:kotlin-stdlib:${Versions.KOTLIN}")
}
}

val jvmMain by getting {
dependencies {
implementation("com.squareup.okio:okio:${Versions.OKIO}")
implementation("org.jetbrains.kotlin:kotlin-stdlib:${Versions.KOTLIN}")
}
}

val commonMain by getting {
dependencies {
implementation("com.squareup.okio:okio-multiplatform:${Versions.OKIO}")
implementation("com.squareup.okio:okio:${Versions.OKIO}")
implementation("org.jetbrains.kotlin:kotlin-stdlib:${Versions.KOTLIN}")
implementation(project(":ktoml-core"))
}
}

target.forEach {
getByName("${it.name}Main").dependsOn(nativeMain)
}

val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
Expand All @@ -49,14 +71,13 @@ kotlin {
implementation("org.junit.jupiter:junit-jupiter-engine:5.0.0")
}
}

all {
languageSettings.enableLanguageFeature("InlineClasses")
}
}
}

configurePublishing()

tasks.withType<KotlinJvmTest> {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package com.akuleshov7.ktoml.file

import okio.ExperimentalFileSystem
import okio.FileNotFoundException
import okio.FileSystem
import okio.Path.Companion.toPath
Expand All @@ -16,11 +15,10 @@ import okio.Path.Companion.toPath
* @return list with strings
* @throws FileNotFoundException if the toml file is missing
*/
@ExperimentalFileSystem
internal fun readAndParseFile(tomlFile: String): List<String> {
try {
val ktomlPath = tomlFile.toPath()
return FileSystem.SYSTEM.read(ktomlPath) {
return getOsSpecificFileSystem().read(ktomlPath) {
// FixMe: may be we need to read and at the same time parse (to make it parallel)
generateSequence { readUtf8Line() }.toList()
}
Expand All @@ -29,3 +27,5 @@ internal fun readAndParseFile(tomlFile: String): List<String> {
throw e
}
}

internal expect fun getOsSpecificFileSystem(): FileSystem
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ package com.akuleshov7.ktoml.file
import com.akuleshov7.ktoml.KtomlConf
import com.akuleshov7.ktoml.Toml

import okio.ExperimentalFileSystem

import kotlin.native.concurrent.ThreadLocal
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.modules.EmptySerializersModule
import kotlinx.serialization.modules.SerializersModule

Expand All @@ -16,6 +15,7 @@ import kotlinx.serialization.modules.SerializersModule
* that is used to serialize/deserialize TOML file or string
* @property serializersModule
*/
@OptIn(ExperimentalSerializationApi::class)
public open class TomlFileReader(
private val config: KtomlConf = KtomlConf(),
override val serializersModule: SerializersModule = EmptySerializersModule
Expand All @@ -27,7 +27,6 @@ public open class TomlFileReader(
* @param tomlFilePath path to the file where toml is stored
* @return deserialized object of type T
*/
@ExperimentalFileSystem
public fun <T> decodeFromFile(
deserializer: DeserializationStrategy<T>,
tomlFilePath: String,
Expand All @@ -49,7 +48,6 @@ public open class TomlFileReader(
* @param tomlTableName fully qualified name of the toml table (it should be the full name - a.b.c.d)
* @return deserialized object of type T
*/
@ExperimentalFileSystem
public fun <T> partiallyDecodeFromFile(
deserializer: DeserializationStrategy<T>,
tomlFilePath: String,
Expand Down
9 changes: 0 additions & 9 deletions ktoml-file/src/commonTest/kotlin/file/TomlFileParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.akuleshov7.ktoml.parsers.node.TomlTable
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import okio.ExperimentalFileSystem
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -36,8 +35,6 @@ class TomlFileParserTest {
val myotherserver: String
)

@OptIn(ExperimentalFileSystem::class)
@ExperimentalSerializationApi
@Test
fun readParseAndDecodeFile() {
val expected = TestClass(
Expand Down Expand Up @@ -77,7 +74,6 @@ class TomlFileParserTest {
data class InnerTest(val str: String = "Undefined")

@Test
@ExperimentalFileSystem
@ExperimentalSerializationApi
fun testTableDiscovery() {
val file = "src/commonTest/resources/complex_toml_tables.toml"
Expand All @@ -93,7 +89,6 @@ class TomlFileParserTest {
@Serializable
data class RegressionTest(val a: Long?, val b: Long, val c: Long, val d: Long?)

@OptIn(ExperimentalFileSystem::class)
@ExperimentalSerializationApi
@Test
fun regressionCast2Test() {
Expand All @@ -102,7 +97,6 @@ class TomlFileParserTest {
assertEquals(RegressionTest(null, 1, 2, null), parsedResult)
}

@OptIn(ExperimentalFileSystem::class)
@ExperimentalSerializationApi
@Test
fun regressionPartialTest() {
Expand Down Expand Up @@ -137,7 +131,6 @@ class TomlFileParserTest {
val list: List<String>
)

@OptIn(ExperimentalFileSystem::class)
@ExperimentalSerializationApi
@Test
fun regressionInvalidIndex() {
Expand Down Expand Up @@ -183,7 +176,6 @@ class TomlFileParserTest {
@Serializable
data class TwoTomlTables(val table1: Table1, val table2: Table2)

@OptIn(ExperimentalFileSystem::class)
@Test
fun testPartialFileDecoding() {
val file = "src/commonTest/resources/partial_decoder.toml"
Expand All @@ -196,7 +188,6 @@ class TomlFileParserTest {
)
}

@OptIn(ExperimentalFileSystem::class)
@Test
fun readTopLevelTables() {
val file = "src/commonTest/resources/simple_example.toml"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* File utils to read files using okio
*/

package com.akuleshov7.ktoml.file

import okio.FileSystem

internal actual fun getOsSpecificFileSystem(): FileSystem = FileSystem.SYSTEM
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* File utils to read files using okio
*/

package com.akuleshov7.ktoml.file

import okio.FileSystem

internal actual fun getOsSpecificFileSystem(): FileSystem = FileSystem.SYSTEM

0 comments on commit b1838ce

Please sign in to comment.