add included mod ids to manifest
This commit is contained in:
parent
4094397909
commit
056350e1dd
|
@ -21,10 +21,12 @@ import org.jetbrains.java.decompiler.main.decompiler.SingleFileSaver
|
||||||
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences
|
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
import java.nio.charset.StandardCharsets
|
||||||
import java.nio.file.FileSystems
|
import java.nio.file.FileSystems
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.StandardCopyOption
|
import java.nio.file.StandardCopyOption
|
||||||
|
import kotlin.io.path.appendText
|
||||||
import kotlin.io.path.createDirectories
|
import kotlin.io.path.createDirectories
|
||||||
import kotlin.io.path.deleteExisting
|
import kotlin.io.path.deleteExisting
|
||||||
import kotlin.io.path.exists
|
import kotlin.io.path.exists
|
||||||
|
@ -129,30 +131,40 @@ class NonsenseGradlePlugin : Plugin<Project> {
|
||||||
it.isCanBeConsumed = false
|
it.isCanBeConsumed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
project.tasks.getByName("jar").actions.addLast { task ->
|
project.tasks.getByName("jar") { task ->
|
||||||
task.outputs.files.forEach {file ->
|
task.outputs.upToDateWhen { false }
|
||||||
val output = file.toPath().parent.resolveSibling("frog")
|
task.actions.addLast { _ ->
|
||||||
output.createDirectories()
|
task.outputs.files.forEach { file ->
|
||||||
if (file.name.endsWith(".jar") && !(file.name.contains("-dev.") || file.name.contains("-sources."))){
|
val output = file.toPath().parent.resolveSibling("frog")
|
||||||
val outFile = output.resolve(file.name.substring(0, file.name.length-4)+".frogmod")
|
output.createDirectories()
|
||||||
Files.copy(file.toPath(), outFile, StandardCopyOption.REPLACE_EXISTING)
|
if (file.name.endsWith(".jar") && !(file.name.contains("-dev.") || file.name.contains("-sources."))) {
|
||||||
if (includeConfiguration.isPresent) {
|
val outFile = output.resolve(file.name.substring(0, file.name.length - 4) + ".frogmod")
|
||||||
FileSystems.newFileSystem(outFile).use {fs ->
|
Files.copy(file.toPath(), outFile, StandardCopyOption.REPLACE_EXISTING)
|
||||||
val jijPath = fs.getPath("META-INF/jars")
|
FileSystems.newFileSystem(outFile).use { fs ->
|
||||||
jijPath.createDirectories()
|
if (includeConfiguration.isPresent) {
|
||||||
val files = Nester.run(includeConfiguration.get(), jijPath).map { it.toString() }.toList()
|
val jijPath = fs.getPath("META-INF/jars")
|
||||||
if (files.isNotEmpty()) {
|
val files =
|
||||||
val manifest = fs.getPath("frog.mod.toml")
|
listOf(Nester.run(includeConfiguration.get(), jijPath).map { it.toml() }.toList())
|
||||||
val config: CommentedConfig =
|
if (files.isNotEmpty()) {
|
||||||
TomlParser().parse(manifest, FileNotFoundAction.THROW_ERROR)
|
val manifest = fs.getPath("frog.mod.toml")
|
||||||
if (!config.add("frog.extensions.included_jars", files)) {
|
val config: CommentedConfig =
|
||||||
println("Failed to add included jars to mod manifest, make sure it doesn't include a key at 'frog.extensions.included_jars'!")
|
TomlParser().parse(manifest, FileNotFoundAction.THROW_ERROR)
|
||||||
|
if (!config.add("frog.extensions.included_jars", files)) {
|
||||||
|
println("Failed to add included jars to mod manifest, make sure it doesn't include a key at 'frog.extensions.included_jars'!")
|
||||||
|
}
|
||||||
|
TomlWriter().write(config, manifest, WritingMode.REPLACE)
|
||||||
}
|
}
|
||||||
TomlWriter().write(config, manifest, WritingMode.REPLACE)
|
|
||||||
}
|
}
|
||||||
|
fs.getPath("META-INF/MANIFEST.MF").appendText(
|
||||||
|
"""
|
||||||
|
Built-By: Phytotelma ${this.javaClass.`package`.implementationVersion}
|
||||||
|
Target-Namespace: Mojmap
|
||||||
|
Built-For: Minecraft $minecraftVersion
|
||||||
|
""".trimIndent(), StandardCharsets.UTF_8
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
println("Built mod to ${outFile.toUri()}")
|
||||||
}
|
}
|
||||||
println("Built mod to ${outFile.toUri()}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.ecorous.esnesnon.gradle.nest
|
package org.ecorous.esnesnon.gradle.nest
|
||||||
|
|
||||||
|
import com.electronwill.nightconfig.core.Config
|
||||||
|
import com.electronwill.nightconfig.core.UnmodifiableConfig
|
||||||
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
|
||||||
|
@ -13,8 +15,8 @@ import java.util.*
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
|
|
||||||
object Nester {
|
object Nester {
|
||||||
fun run(configuration: Configuration, path: Path): Collection<Path> {
|
fun run(configuration: Configuration, path: Path): Collection<NestedJar> {
|
||||||
val files = mutableListOf<Path>()
|
val files = mutableListOf<NestedJar>()
|
||||||
Jimfs.newFileSystem(com.google.common.jimfs.Configuration.unix()).use { memFs ->
|
Jimfs.newFileSystem(com.google.common.jimfs.Configuration.unix()).use { memFs ->
|
||||||
configuration.dependencies.filterIsInstance<ProjectDependency>().forEach { dependency ->
|
configuration.dependencies.filterIsInstance<ProjectDependency>().forEach { dependency ->
|
||||||
val project = dependency.dependencyProject
|
val project = dependency.dependencyProject
|
||||||
|
@ -31,9 +33,13 @@ object Nester {
|
||||||
memFs
|
memFs
|
||||||
)
|
)
|
||||||
}.get()
|
}.get()
|
||||||
|
path.createDirectories()
|
||||||
val target = path.resolve(location.fileName.toString())
|
val target = path.resolve(location.fileName.toString())
|
||||||
Files.copy(location, target)
|
Files.copy(location, target)
|
||||||
files.add(target.absolute())
|
files.add(NestedJar(("${dependency.group}_${dependency.name}${if (task.archiveClassifier.isPresent) "_${task.archiveClassifier}" else ""}").replace(
|
||||||
|
"\\.".toRegex(),
|
||||||
|
"_"
|
||||||
|
).lowercase(Locale.ROOT), target.absolute().toString()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configuration.resolvedConfiguration.firstLevelModuleDependencies.forEach { dep ->
|
configuration.resolvedConfiguration.firstLevelModuleDependencies.forEach { dep ->
|
||||||
|
@ -46,9 +52,13 @@ object Nester {
|
||||||
artifact.classifier,
|
artifact.classifier,
|
||||||
memFs
|
memFs
|
||||||
)
|
)
|
||||||
|
path.createDirectories()
|
||||||
val target = path.resolve(location.fileName.toString())
|
val target = path.resolve(location.fileName.toString())
|
||||||
Files.copy(location, target)
|
Files.copy(location, target)
|
||||||
files.add(target.absolute())
|
files.add(NestedJar(("${dep.moduleGroup}_${dep.moduleName}${if (artifact.classifier != null) "_${artifact.classifier}" else ""}").replace(
|
||||||
|
"\\.".toRegex(),
|
||||||
|
"_"
|
||||||
|
).lowercase(Locale.ROOT), target.absolute().toString()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,4 +120,13 @@ object Nester {
|
||||||
return input
|
return input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NestedJar(val id: String, val path: String){
|
||||||
|
fun toml(): UnmodifiableConfig {
|
||||||
|
val config = Config.inMemory()
|
||||||
|
config.add("id", id)
|
||||||
|
config.add("path", path)
|
||||||
|
return config
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue