Skip to content

Commit 4b5b8af

Browse files
committed
FileSystemProvider experiment
1 parent d03bfbc commit 4b5b8af

4 files changed

Lines changed: 12 additions & 25 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.6.1
1+
version=0.6.2

minecraft-codev-core/src/main/kotlin/net/msrandom/minecraftcodev/core/utils/path-utils.kt

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,24 @@ package net.msrandom.minecraftcodev.core.utils
33
import org.gradle.api.file.FileSystemLocation
44
import org.gradle.api.file.FileSystemLocationProperty
55
import org.jetbrains.annotations.Blocking
6-
import org.slf4j.LoggerFactory
7-
import java.lang.Thread.sleep
8-
import java.net.URI
96
import java.nio.file.*
7+
import java.nio.file.spi.FileSystemProvider
108
import kotlin.streams.asSequence
11-
import kotlin.time.Duration.Companion.seconds
129

13-
private val logger = LoggerFactory.getLogger("path-utils")
14-
15-
@Blocking
1610
fun zipFileSystem(
17-
file: Path,
11+
path: Path,
1812
create: Boolean = false,
1913
): FileSystem {
20-
val uri = URI.create("jar:${file.toUri()}")
21-
22-
if (create) {
23-
return FileSystems.newFileSystem(uri, mapOf("create" to true.toString()))
24-
}
14+
val env = mapOf("create" to create.toString())
2515

26-
while (true) {
16+
for (provider in FileSystemProvider.installedProviders()) {
2717
try {
28-
return FileSystems.newFileSystem(uri, emptyMap<String, Any>())
29-
} catch (e: FileSystemAlreadyExistsException) {
30-
logger.info("Couldn't acquire access to $file file-system, waiting", e)
31-
32-
sleep(1.seconds.inWholeMilliseconds)
18+
return provider.newFileSystem(path, env)
19+
} catch (_: UnsupportedOperationException) {
3320
}
3421
}
22+
23+
throw ProviderNotFoundException("Provider not found")
3524
}
3625

3726
fun <T> Path.walk(action: Sequence<Path>.() -> T) =

minecraft-codev-remapper/src/main/kotlin/net/msrandom/minecraftcodev/remapper/JarRemapper.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ import net.msrandom.minecraftcodev.core.utils.zipFileSystem
1010
import net.msrandom.minecraftcodev.remapper.extra.InnerClassRemapper
1111
import net.msrandom.minecraftcodev.remapper.extra.SimpleFallbackRemapper
1212
import java.io.File
13-
import java.nio.file.FileSystems
1413
import java.nio.file.Path
15-
import java.util.*
1614
import java.util.EnumSet
1715
import java.util.concurrent.CompletableFuture
18-
import kotlin.io.path.exists
1916
import kotlin.io.path.listDirectoryEntries
2017

2118
const val REMAP_OPERATION_VERSION = 3
2219

23-
private fun hasRefmaps(path: Path) = FileSystems.newFileSystem(path, null).use {
20+
private fun hasRefmaps(path: Path) = zipFileSystem(path).use {
2421
it.getPath("/").listDirectoryEntries("*refmap.json").isNotEmpty()
2522
}
2623

minecraft-codev-remapper/src/main/kotlin/net/msrandom/minecraftcodev/remapper/RemapAction.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import net.fabricmc.mappingio.format.tiny.Tiny2FileReader
44
import net.fabricmc.mappingio.tree.MemoryMappingTree
55
import net.msrandom.minecraftcodev.core.utils.cacheExpensiveOperation
66
import net.msrandom.minecraftcodev.core.utils.getAsPath
7+
import net.msrandom.minecraftcodev.core.utils.zipFileSystem
78
import net.msrandom.minecraftcodev.includes.includedJarListingRules
89
import org.gradle.api.artifacts.transform.CacheableTransform
910
import org.gradle.api.artifacts.transform.InputArtifact
@@ -128,7 +129,7 @@ abstract class RemapAction : TransformAction<RemapAction.Parameters> {
128129
classpath,
129130
)
130131

131-
FileSystems.newFileSystem(output, null).use { outputFs ->
132+
zipFileSystem(output).use { outputFs ->
132133
val root = outputFs.getPath("/")
133134
val handler = includedJarListingRules.firstNotNullOfOrNull { it.load(root) }
134135
if (handler != null) {

0 commit comments

Comments
 (0)