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

Upgraded kotlin to 1.9.20 #556

Merged
merged 17 commits into from
Feb 28, 2024
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
kotlin = "1.9.10"
kotlin = "1.9.20"
okio = "3.6.0"
serialization = "1.6.0"
diktat = "1.2.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ import okio.FileSystem
import okio.Path
import kotlin.random.Random

/**
* Marks method to be executed before all tests, supported on JVM and Native
*/
expect annotation class BeforeClass

/**
* Marks method to be executed after all tests, supported on JVM and Native
*/
expect annotation class AfterClass

/**
* Create a temporary directory
*
Expand Down
10 changes: 0 additions & 10 deletions save-common-test/src/jvmMain/kotlin/com/saveourtool/save/Utils.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ package com.saveourtool.save.core.logging
import com.saveourtool.save.core.config.LogType
import com.saveourtool.save.core.config.OutputStreamType
import com.saveourtool.save.core.utils.GenericAtomicReference
import com.saveourtool.save.core.utils.createGenericAtomicReference
import com.saveourtool.save.core.utils.writeToStream

import kotlin.native.concurrent.SharedImmutable
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime

/**
* Logging mode
*/
@SharedImmutable
val logType: GenericAtomicReference<LogType> = GenericAtomicReference(LogType.WARN)
val logType: GenericAtomicReference<LogType> = createGenericAtomicReference(LogType.WARN)

/**
* Whether to add time stamps to log messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ enum class CurrentOs {
}

/**
* Class that holds value and shares atomic reference to the value (native only)
* Interface that holds value and shares atomic reference to the value (native only)
*
* @param valueToStore value to store
*/
@Suppress("USE_DATA_CLASS")
expect class GenericAtomicReference<T>(valueToStore: T) {
interface GenericAtomicReference<T> {
/**
* @return stored value
*/
Expand All @@ -33,6 +31,12 @@ expect class GenericAtomicReference<T>(valueToStore: T) {
fun set(newValue: T)
}

/**
* @param valueToStore value to store
* @return a new [GenericAtomicReference] with default value [valueToStore]
*/
expect fun <T> createGenericAtomicReference(valueToStore: T): GenericAtomicReference<T>

/**
* Get type of current OS
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ import okio.Path.Companion.toPath
import kotlinx.datetime.Clock

/**
* A class that is capable of executing processes, specific to different OS and returning their output.
* An interface that is capable of executing processes, specific to different OS and returning their output.
*/
expect class ProcessBuilderInternal(
stdoutFile: Path,
stderrFile: Path,
useInternalRedirections: Boolean,
) {
interface ProcessBuilderInternal {
/**
* Modify execution command according behavior of different OS,
* also stdout and stderr will be redirected to tmp files
Expand Down Expand Up @@ -97,7 +93,7 @@ class ProcessBuilder(private val useInternalRedirections: Boolean, private val f
val stderrFile = tmpDir / "stderr.txt"
logTrace("Creating stderr file of ProcessBuilder: $stderrFile")
// Instance, containing platform-dependent realization of command execution
val processBuilderInternal = ProcessBuilderInternal(stdoutFile, stderrFile, useInternalRedirections)
val processBuilderInternal = createProcessBuilderInternal(stdoutFile, stderrFile, useInternalRedirections)
fs.createDirectories(tmpDir)
fs.createFile(stdoutFile)
fs.createFile(stderrFile)
Expand Down Expand Up @@ -236,3 +232,15 @@ data class ExecutionResult(
val stdout: List<String>,
val stderr: List<String>,
)

/**
* @param stdoutFile
* @param stderrFile
* @param useInternalRedirections
* @return implementation of [ProcessBuilderInternal]
*/
expect fun createProcessBuilderInternal(
stdoutFile: Path,
stderrFile: Path,
useInternalRedirections: Boolean,
): ProcessBuilderInternal
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ package com.saveourtool.save.core.utils

import com.saveourtool.save.core.config.OutputStreamType

@Suppress("USE_DATA_CLASS")
actual class GenericAtomicReference<T> actual constructor(valueToStore: T) {
private var value: T = valueToStore
actual fun get(): T = value
actual fun set(newValue: T) {
value = newValue
}
}
actual fun <T> createGenericAtomicReference(valueToStore: T): GenericAtomicReference<T> =
object : GenericAtomicReference<T> {
private var value: T = valueToStore
override fun get(): T = value
override fun set(newValue: T) {
value = newValue
}
}

actual fun getCurrentOs(): CurrentOs = error("Not implemented for JS")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
@file:Suppress(
"MISSING_KDOC_TOP_LEVEL",
"MISSING_KDOC_CLASS_ELEMENTS",
"KDOC_NO_EMPTY_TAGS",
"MISSING_KDOC_ON_FUNCTION",
"FILE_NAME_MATCH_CLASS",
"MatchingDeclarationName",
)
/**
* Implementation of [ProcessBuilderInternal] for JS
*/

package com.saveourtool.save.core.utils

import okio.Path

actual class ProcessBuilderInternal actual constructor(
nulls marked this conversation as resolved.
Show resolved Hide resolved
actual fun createProcessBuilderInternal(
stdoutFile: Path,
stderrFile: Path,
useInternalRedirections: Boolean,
) {
actual fun prepareCmd(command: String): String = error("Not implemented for JS")
): ProcessBuilderInternal = object : ProcessBuilderInternal {
override fun prepareCmd(command: String): String = error("Not implemented for JS")

actual fun exec(cmd: String, timeOutMillis: Long): Int = error("Not implemented for JS")
override fun exec(cmd: String, timeOutMillis: Long): Int = error("Not implemented for JS")
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ package com.saveourtool.save.core.utils

import com.saveourtool.save.core.config.OutputStreamType

@Suppress("USE_DATA_CLASS")
actual class GenericAtomicReference<T> actual constructor(valueToStore: T) {
private val holder: java.util.concurrent.atomic.AtomicReference<T> = java.util.concurrent.atomic.AtomicReference(valueToStore)
actual fun get(): T = holder.get()
actual fun set(newValue: T) {
holder.set(newValue)
}
}
actual fun <T> createGenericAtomicReference(valueToStore: T): GenericAtomicReference<T> =
object : GenericAtomicReference<T> {
private val holder = java.util.concurrent.atomic.AtomicReference(valueToStore)
override fun get(): T = holder.get()
override fun set(newValue: T) {
holder.set(newValue)
}
}

actual fun getCurrentOs() = when {
System.getProperty("os.name").startsWith("Linux", ignoreCase = true) -> CurrentOs.LINUX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@ import okio.Path
import java.io.BufferedReader
import java.io.InputStreamReader

import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.newFixedThreadPoolContext
import kotlinx.coroutines.runBlocking

@Suppress("MISSING_KDOC_TOP_LEVEL",
"MISSING_KDOC_CLASS_ELEMENTS",
"MISSING_KDOC_ON_FUNCTION"
)
actual class ProcessBuilderInternal actual constructor(
private class ProcessBuilderInternalImpl(
private val stdoutFile: Path,
private val stderrFile: Path,
private val useInternalRedirections: Boolean
) {
@OptIn(ExperimentalStdlibApi::class)
actual fun prepareCmd(command: String): String {
private val useInternalRedirections: Boolean,
) : ProcessBuilderInternal {
override fun prepareCmd(command: String): String {
val cmd = buildList {
if (isCurrentOsWindows()) {
add("CMD")
Expand All @@ -36,9 +30,8 @@ actual class ProcessBuilderInternal actual constructor(
return cmd.joinToString()
}

@OptIn(ObsoleteCoroutinesApi::class)
@Suppress("UnsafeCallOnNullableType")
actual fun exec(
override fun exec(
cmd: String,
timeOutMillis: Long,
): Int {
Expand Down Expand Up @@ -92,3 +85,9 @@ actual class ProcessBuilderInternal actual constructor(
}
}
}

actual fun createProcessBuilderInternal(
stdoutFile: Path,
stderrFile: Path,
useInternalRedirections: Boolean,
): ProcessBuilderInternal = ProcessBuilderInternalImpl(stdoutFile, stderrFile, useInternalRedirections)
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ import platform.posix.fprintf
import platform.posix.stderr
import platform.posix.stdout

import kotlin.experimental.ExperimentalNativeApi
import kotlinx.cinterop.ExperimentalForeignApi

@Suppress("USE_DATA_CLASS")
actual class GenericAtomicReference<T> actual constructor(valueToStore: T) {
private val holder: kotlin.concurrent.AtomicReference<T> = kotlin.concurrent.AtomicReference(valueToStore)
actual fun get(): T = holder.value
actual fun set(newValue: T) {
holder.value = newValue
}
}

/**
* Escaping percent symbol in the string in case it is not escaped already
*
Expand All @@ -51,6 +43,16 @@ fun String.escapePercent(): String {
return stringBuilder.toString()
}

actual fun <T> createGenericAtomicReference(valueToStore: T): GenericAtomicReference<T> =
object : GenericAtomicReference<T> {
private val holder = kotlin.concurrent.AtomicReference(valueToStore)
override fun get(): T = holder.value
override fun set(newValue: T) {
holder.value = newValue
}
}

@OptIn(ExperimentalNativeApi::class)
actual fun getCurrentOs() = when (Platform.osFamily) {
OsFamily.LINUX -> CurrentOs.LINUX
OsFamily.MACOSX -> CurrentOs.MACOS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("FILE_WILDCARD_IMPORTS")

package com.saveourtool.save.core.utils

import com.saveourtool.save.core.logging.logTrace
Expand All @@ -14,23 +12,19 @@ import kotlinx.coroutines.joinAll
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.runBlocking

@Suppress("MISSING_KDOC_TOP_LEVEL",
"MISSING_KDOC_CLASS_ELEMENTS",
"MISSING_KDOC_ON_FUNCTION"
)
actual class ProcessBuilderInternal actual constructor(
private class ProcessBuilderInternalImpl(
private val stdoutFile: Path,
private val stderrFile: Path,
private val useInternalRedirections: Boolean
) {
actual fun prepareCmd(command: String) = if (useInternalRedirections) {
private val useInternalRedirections: Boolean,
) : ProcessBuilderInternal {
override fun prepareCmd(command: String) = if (useInternalRedirections) {
"($command) >$stdoutFile 2>$stderrFile"
} else {
command
}

@OptIn(ExperimentalCoroutinesApi::class)
actual fun exec(
override fun exec(
cmd: String,
timeOutMillis: Long
): Int {
Expand Down Expand Up @@ -66,3 +60,9 @@ actual class ProcessBuilderInternal actual constructor(
logTrace("Executed kill command: $killCmd")
}
}

actual fun createProcessBuilderInternal(
stdoutFile: Path,
stderrFile: Path,
useInternalRedirections: Boolean,
): ProcessBuilderInternal = ProcessBuilderInternalImpl(stdoutFile, stderrFile, useInternalRedirections)