Skip to content

Commit

Permalink
Create FileSystem.SYSTEM property in shared source set (#1455)
Browse files Browse the repository at this point in the history
* Create FileSystem.SYSTEM property in shared source set

Co-authored-by: Sebastian Sellmair <sebastian.sellmair@jetbrains.com>

* Only configure native platforms in samples if kmpNativeEnabled is set

* Use FileSystem.SYSTEM in existing tests, remove new multiplatform samples

---------

Co-authored-by: Sebastian Sellmair <sebastian.sellmair@jetbrains.com>
  • Loading branch information
zsmb13 and sellmair committed Mar 12, 2024
1 parent fe6ac99 commit eac869b
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 24 deletions.
2 changes: 0 additions & 2 deletions okio-testing-support/src/jvmMain/kotlin/okio/TestingJvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package okio

actual val SYSTEM_FILE_SYSTEM = FileSystem.SYSTEM

actual fun isBrowser() = false

actual fun isWasm() = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.toKString
import platform.posix.getenv

actual val SYSTEM_FILE_SYSTEM = FileSystem.SYSTEM

actual fun isBrowser() = false

actual fun isWasm() = false
Expand Down
18 changes: 0 additions & 18 deletions okio-testing-support/src/zlibMain/kotlin/okio/TestingZlib.kt

This file was deleted.

4 changes: 4 additions & 0 deletions okio/api/okio.api
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,10 @@ public abstract interface class okio/Source : java/io/Closeable {
public abstract fun timeout ()Lokio/Timeout;
}

public final class okio/SystemFileSystem {
public static final synthetic fun getSYSTEM (Lokio/FileSystem$Companion;)Lokio/FileSystem;
}

public final class okio/Throttler {
public fun <init> ()V
public final fun bytesPerSecond (J)V
Expand Down
8 changes: 8 additions & 0 deletions okio/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ plugins {
*
* The `hashFunctions` source set builds on all platforms. It ships as a main source set on non-JVM
* platforms and as a test source set on the JVM platform.
*
* The `systemFileSystem` source set is used on jvm and native targets, and provides the FileSystem.SYSTEM property.
*/
kotlin {
configureOrCreateOkioPlatforms()
Expand Down Expand Up @@ -87,6 +89,10 @@ kotlin {
dependsOn(commonMain)
}

val systemFileSystemMain by creating {
dependsOn(commonMain)
}

val nonJvmTest by creating {
dependsOn(commonTest)
}
Expand All @@ -104,6 +110,7 @@ kotlin {

val jvmMain by getting {
dependsOn(zlibMain)
dependsOn(systemFileSystemMain)
}
val jvmTest by getting {
kotlin.srcDir("src/jvmTest/hashFunctions")
Expand Down Expand Up @@ -131,6 +138,7 @@ kotlin {
createSourceSet("nativeMain", parent = nonJvmMain)
.also { nativeMain ->
nativeMain.dependsOn(zlibMain)
nativeMain.dependsOn(systemFileSystemMain)
createSourceSet("mingwMain", parent = nativeMain, children = mingwTargets).also { mingwMain ->
mingwMain.dependsOn(nonAppleMain)
}
Expand Down
13 changes: 13 additions & 0 deletions okio/src/jvmMain/kotlin/okio/FileSystem.System.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@file:JvmName("SystemFileSystem")

package okio

/*
* JVM and native platforms do offer a [SYSTEM] [FileSystem], however we cannot refine an 'expect' companion object.
* Therefore an extension property is provided, which on respective platforms (here JVM) will be shadowed by the
* original implementation.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
actual inline val FileSystem.Companion.SYSTEM: FileSystem
@JvmSynthetic
get() = SYSTEM
9 changes: 9 additions & 0 deletions okio/src/nativeMain/kotlin/okio/FileSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,12 @@ actual abstract class FileSystem {
actual val SYSTEM_TEMPORARY_DIRECTORY: Path = PLATFORM_TEMPORARY_DIRECTORY
}
}

/*
* JVM and native platforms do offer a [SYSTEM] [FileSystem], however we cannot refine an 'expect' companion object.
* Therefore an extension property is provided, which on respective platforms (here JVM) will be shadowed by the
* original implementation.
*/
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
actual inline val FileSystem.Companion.SYSTEM: FileSystem
get() = SYSTEM
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package okio

/*
* The current process's host file system. Use this instance directly, or dependency inject a
* [FileSystem] to make code testable.
*/
expect val FileSystem.Companion.SYSTEM: FileSystem
2 changes: 1 addition & 1 deletion okio/src/zlibTest/kotlin/okio/ZipFileSystemGoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import okio.Path.Companion.toPath
* https://github.com/golang/go/blob/6f5d77454e31be8af11a7e2bcda36d200fda07c5/src/archive/zip/reader_test.go
*/
class ZipFileSystemGoTest {
private val fileSystem = SYSTEM_FILE_SYSTEM
private val fileSystem = FileSystem.SYSTEM
private var base = okioRoot / "okio-testing-support" /
"src/commonMain/resources/go/src/archive/zip/testdata"

Expand Down
2 changes: 1 addition & 1 deletion okio/src/zlibTest/kotlin/okio/ZipFileSystemTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import okio.ByteString.Companion.encodeUtf8
import okio.Path.Companion.toPath

class ZipFileSystemTest {
private val fileSystem = SYSTEM_FILE_SYSTEM
private val fileSystem = FileSystem.SYSTEM
private var base = okioRoot / "okio-testing-support/src/commonMain/resources/okio/zipfilesystem"

@Test
Expand Down

0 comments on commit eac869b

Please sign in to comment.