fix nesting bugs
All checks were successful
Publish to snapshot maven / build (push) Successful in 20s

This commit is contained in:
moehreag 2024-06-11 03:04:55 +02:00
parent 9360e2e4d6
commit 181462f0b4

View file

@ -2,6 +2,7 @@ package dev.frogmc.phytotelma.nest
import com.electronwill.nightconfig.core.Config import com.electronwill.nightconfig.core.Config
import com.electronwill.nightconfig.core.UnmodifiableConfig import com.electronwill.nightconfig.core.UnmodifiableConfig
import com.electronwill.nightconfig.toml.TomlParser
import com.google.common.jimfs.Jimfs import com.google.common.jimfs.Jimfs
import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.ProjectDependency
@ -34,13 +35,10 @@ object Nester {
) )
}.get() }.get()
path.createDirectories() path.createDirectories()
val target = path.resolve(location.fileName.toString()) val target = path.resolve(location.file.fileName.toString())
Files.copy(location, target) Files.copy(location.file, target)
files.add( files.add(
NestedJar(("${dependency.group}_${dependency.name}${if (task.archiveClassifier.isPresent) "_${task.archiveClassifier}" else ""}").replace( NestedJar(location.modId, target.absolute().toString())
"\\.".toRegex(),
"_"
).lowercase(Locale.ROOT), target.absolute().toString())
) )
} }
} }
@ -55,14 +53,14 @@ object Nester {
memFs memFs
) )
path.createDirectories() path.createDirectories()
val target = path.resolve(location.fileName.toString()) val target = path.resolve(location.file.fileName.toString())
Files.copy(location, target)
files.add( if (target.notExists()) {
NestedJar(("${dep.moduleGroup}_${dep.moduleName}${if (artifact.classifier != null) "_${artifact.classifier}" else ""}").replace( Files.copy(location.file, target)
"\\.".toRegex(), files.add(
"_" NestedJar(location.modId, target.absolute().toString())
).lowercase(Locale.ROOT), target.absolute().toString()) )
) }
} }
} }
} }
@ -76,7 +74,7 @@ object Nester {
version: String, version: String,
classifier: String?, classifier: String?,
memFs: FileSystem memFs: FileSystem
): Path { ): JarMetadata {
FileSystems.newFileSystem(input).use { original -> FileSystems.newFileSystem(input).use { original ->
val toml = original.getPath("frog.mod.toml") val toml = original.getPath("frog.mod.toml")
if (toml.notExists()) { if (toml.notExists()) {
@ -90,13 +88,16 @@ object Nester {
) )
if (tempFile.exists()) { if (tempFile.exists()) {
FileSystems.newFileSystem(tempFile).use { FileSystems.newFileSystem(tempFile).use {
if (it.getPath("frog.mod.toml").exists()){ val metadata = it.getPath("frog.mod.toml")
return tempFile if (metadata.exists()){
return JarMetadata(readModId(metadata), tempFile)
} }
} }
} }
tempFile.createParentDirectories() tempFile.createParentDirectories()
input.copyTo(tempFile) input.copyTo(tempFile)
val modId = ("${group}_$name${if (classifier != null) "_$classifier" else ""}").replace(
"\\.".toRegex(), "_").lowercase(Locale.ROOT)
FileSystems.newFileSystem(tempFile).use { FileSystems.newFileSystem(tempFile).use {
it.getPath("frog.mod.toml").writeText( it.getPath("frog.mod.toml").writeText(
""" """
@ -104,12 +105,7 @@ object Nester {
manifest_version = "1.0.0" manifest_version = "1.0.0"
[frog.mod] [frog.mod]
id = "${ id = "$modId"
("${group}_$name${if (classifier != null) "_$classifier" else ""}").replace(
"\\.".toRegex(),
"_"
).lowercase(Locale.ROOT)
}"
name = "$name" name = "$name"
version = "${version.replace("(\\d+\\.\\d+\\.\\d+)(.*)".toRegex(), "$1+$2")}" version = "${version.replace("(\\d+\\.\\d+\\.\\d+)(.*)".toRegex(), "$1+$2")}"
license = "" license = ""
@ -119,13 +115,19 @@ object Nester {
""".trimIndent() """.trimIndent()
) )
} }
return tempFile return JarMetadata(modId, tempFile)
} }
return input return JarMetadata(readModId(toml), input)
} }
} }
private fun readModId(toml: Path): String {
return TomlParser().parse(toml.inputStream()).get("frog.mod.id")
}
} }
data class JarMetadata(val modId: String, val file: Path)
class NestedJar(val id: String, val path: String){ class NestedJar(val id: String, val path: String){
fun toml(): UnmodifiableConfig { fun toml(): UnmodifiableConfig {
val config = Config.inMemory() val config = Config.inMemory()