Compare commits
1 commit
main
...
remap-bund
Author | SHA1 | Date | |
---|---|---|---|
|
7d6c9738e3 |
5 changed files with 139 additions and 53 deletions
|
@ -24,6 +24,8 @@ package io.papermc.paperweight.taskcontainers
|
|||
|
||||
import com.google.gson.JsonObject
|
||||
import io.papermc.paperweight.tasks.*
|
||||
import io.papermc.paperweight.tasks.packaging.CreateBundlerJar
|
||||
import io.papermc.paperweight.tasks.packaging.CreatePaperclipJar
|
||||
import io.papermc.paperweight.util.*
|
||||
import io.papermc.paperweight.util.constants.*
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
|
@ -76,6 +78,19 @@ class BundlerJarTasks(
|
|||
vanillaJar,
|
||||
reobfJar.flatMap { it.outputJar },
|
||||
)
|
||||
createReobfBundlerJar {
|
||||
remapLibraries.configureEach {
|
||||
mappingsFile.set(reobfJar.flatMap { it.mappingsFile })
|
||||
fromNamespace.set(reobfJar.flatMap { it.fromNamespace })
|
||||
toNamespace.set(reobfJar.flatMap { it.toNamespace })
|
||||
remapClasspath.from(reobfJar.map { it.remapClasspath })
|
||||
// add mc to remap classpath
|
||||
remapClasspath.from(reobfJar.flatMap { it.inputJar })
|
||||
remapper.setFrom(reobfJar.map { it.remapper })
|
||||
remapperArgs.set(reobfJar.flatMap { it.remapperArgs })
|
||||
jvmArgs.set(reobfJar.flatMap { it.jvmArgs })
|
||||
}
|
||||
}
|
||||
|
||||
createPaperclipJar.configureWith(vanillaJar, createBundlerJar, mcVersion)
|
||||
createReobfPaperclipJar.configureWith(vanillaJar, createReobfBundlerJar, mcVersion)
|
||||
|
|
|
@ -25,6 +25,8 @@ package io.papermc.paperweight.taskcontainers
|
|||
import io.papermc.paperweight.extension.RelocationExtension
|
||||
import io.papermc.paperweight.taskcontainers.BundlerJarTasks.Companion.registerVersionArtifact
|
||||
import io.papermc.paperweight.tasks.*
|
||||
import io.papermc.paperweight.tasks.packaging.CreateBundlerJar
|
||||
import io.papermc.paperweight.tasks.packaging.CreatePaperclipJar
|
||||
import io.papermc.paperweight.util.*
|
||||
import io.papermc.paperweight.util.constants.*
|
||||
import java.nio.file.Path
|
||||
|
|
|
@ -36,36 +36,13 @@ import org.gradle.api.tasks.*
|
|||
import org.gradle.jvm.toolchain.JavaLauncher
|
||||
|
||||
@CacheableTask
|
||||
abstract class RemapJar : JavaLauncherTask() {
|
||||
|
||||
abstract class RemapJar : JavaLauncherTask(), RemapJarParams {
|
||||
@get:Classpath
|
||||
abstract val inputJar: RegularFileProperty
|
||||
|
||||
@get:InputFile
|
||||
@get:PathSensitive(PathSensitivity.NONE)
|
||||
abstract val mappingsFile: RegularFileProperty
|
||||
|
||||
@get:Input
|
||||
abstract val fromNamespace: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val toNamespace: Property<String>
|
||||
|
||||
@get:CompileClasspath
|
||||
abstract val remapClasspath: ConfigurableFileCollection
|
||||
|
||||
@get:Classpath
|
||||
abstract val remapper: ConfigurableFileCollection
|
||||
|
||||
@get:Input
|
||||
abstract val remapperArgs: ListProperty<String>
|
||||
|
||||
@get:OutputFile
|
||||
abstract val outputJar: RegularFileProperty
|
||||
|
||||
@get:Internal
|
||||
abstract val jvmArgs: ListProperty<String>
|
||||
|
||||
override fun init() {
|
||||
super.init()
|
||||
|
||||
|
@ -76,24 +53,41 @@ abstract class RemapJar : JavaLauncherTask() {
|
|||
|
||||
@TaskAction
|
||||
fun run() {
|
||||
val logFile = layout.cache.resolve(paperTaskOutput("log"))
|
||||
TinyRemapper.run(
|
||||
argsList = remapperArgs.get(),
|
||||
logFile = logFile,
|
||||
inputJar = inputJar.path,
|
||||
mappingsFile = mappingsFile.path,
|
||||
fromNamespace = fromNamespace.get(),
|
||||
toNamespace = toNamespace.get(),
|
||||
remapClasspath = remapClasspath.files.map { it.toPath() },
|
||||
remapper = remapper,
|
||||
outputJar = outputJar.path,
|
||||
launcher = launcher.get(),
|
||||
workingDir = layout.cache,
|
||||
jvmArgs = jvmArgs.get()
|
||||
inputJar.path,
|
||||
outputJar.path,
|
||||
this,
|
||||
launcher.get(),
|
||||
layout.cache.resolve(paperTaskOutput("log")),
|
||||
layout.cache
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
interface RemapJarParams {
|
||||
@get:InputFile
|
||||
@get:PathSensitive(PathSensitivity.NONE)
|
||||
val mappingsFile: RegularFileProperty
|
||||
|
||||
@get:Input
|
||||
val fromNamespace: Property<String>
|
||||
|
||||
@get:Input
|
||||
val toNamespace: Property<String>
|
||||
|
||||
@get:CompileClasspath
|
||||
val remapClasspath: ConfigurableFileCollection
|
||||
|
||||
@get:Classpath
|
||||
val remapper: ConfigurableFileCollection
|
||||
|
||||
@get:Input
|
||||
val remapperArgs: ListProperty<String>
|
||||
|
||||
@get:Internal
|
||||
val jvmArgs: ListProperty<String>
|
||||
}
|
||||
|
||||
object TinyRemapper {
|
||||
private const val minecraftLvPattern = "\\$\\$\\d+"
|
||||
private const val fixPackageAccessArg = "--fixpackageaccess"
|
||||
|
@ -177,6 +171,30 @@ object TinyRemapper {
|
|||
return args
|
||||
}
|
||||
|
||||
fun run(
|
||||
inputJar: Path,
|
||||
outputJar: Path,
|
||||
params: RemapJarParams,
|
||||
launcher: JavaLauncher,
|
||||
logFile: Path,
|
||||
workingDir: Path,
|
||||
) {
|
||||
run(
|
||||
argsList = params.remapperArgs.get(),
|
||||
logFile = logFile,
|
||||
inputJar = inputJar,
|
||||
mappingsFile = params.mappingsFile.path,
|
||||
fromNamespace = params.fromNamespace.get(),
|
||||
toNamespace = params.toNamespace.get(),
|
||||
remapClasspath = params.remapClasspath.files.map { it.toPath() },
|
||||
remapper = params.remapper,
|
||||
outputJar = outputJar,
|
||||
launcher = launcher,
|
||||
workingDir = workingDir,
|
||||
jvmArgs = params.jvmArgs.get()
|
||||
)
|
||||
}
|
||||
|
||||
fun run(
|
||||
argsList: List<String>,
|
||||
logFile: Path,
|
||||
|
|
|
@ -20,13 +20,16 @@
|
|||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
package io.papermc.paperweight.tasks.packaging
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.tasks.*
|
||||
import io.papermc.paperweight.util.*
|
||||
import io.papermc.paperweight.util.constants.*
|
||||
import io.papermc.paperweight.util.data.*
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.*
|
||||
import org.gradle.api.Named
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
||||
|
@ -39,7 +42,7 @@ import org.gradle.api.tasks.*
|
|||
import org.gradle.kotlin.dsl.*
|
||||
|
||||
@CacheableTask
|
||||
abstract class CreateBundlerJar : ZippedTask() {
|
||||
abstract class CreateBundlerJar : JavaLauncherZippedTask() {
|
||||
|
||||
interface VersionArtifact {
|
||||
@get:Input
|
||||
|
@ -75,6 +78,14 @@ abstract class CreateBundlerJar : ZippedTask() {
|
|||
@get:OutputFile
|
||||
abstract val libraryChangesJson: RegularFileProperty
|
||||
|
||||
interface LibraryRemap : RemapJarParams, Named {
|
||||
@Input
|
||||
override fun getName(): String
|
||||
}
|
||||
|
||||
@get:Nested
|
||||
abstract val remapLibraries: NamedDomainObjectContainer<LibraryRemap>
|
||||
|
||||
private fun createVersionArtifactContainer(): NamedDomainObjectContainer<VersionArtifact> =
|
||||
objects.domainObjectContainer(VersionArtifact::class) { objects.newInstance(it) }
|
||||
|
||||
|
@ -122,6 +133,8 @@ abstract class CreateBundlerJar : ZippedTask() {
|
|||
|
||||
val outputDir = rootDir.resolve("META-INF/libraries")
|
||||
|
||||
val workingDir = createTempDirectory("paperweight-bundler-remap")
|
||||
|
||||
val dependencies = collectDependencies()
|
||||
for (dep in dependencies) {
|
||||
val serverLibrary = serverLibraryEntries.firstOrNull {
|
||||
|
@ -129,29 +142,65 @@ abstract class CreateBundlerJar : ZippedTask() {
|
|||
it.id.name == dep.module.name &&
|
||||
it.id.classifier == dep.module.classifier
|
||||
}
|
||||
val remapInfo = remapLibraries.findByName(dep.module.group + ':' + dep.module.name)
|
||||
if (serverLibrary != null) {
|
||||
if (serverLibrary.id.version == dep.module.version) {
|
||||
// nothing to do
|
||||
if (serverLibrary.id.version == dep.module.version && remapInfo == null) {
|
||||
// nothing to do (no remap or version change)
|
||||
libraries += serverLibrary
|
||||
|
||||
dep.copyTo(outputDir.resolve(dep.module.toPath()))
|
||||
} else {
|
||||
// we have a different version of this library
|
||||
val newId = dep.module
|
||||
val newPath = newId.toPath()
|
||||
changedLibraries += LibraryChange(serverLibrary.id, serverLibrary.path, newId, newPath)
|
||||
if (remapInfo != null) {
|
||||
// we are remapping this library, may or may not be a different version
|
||||
val newId = dep.module.copy(version = dep.module.version + "-remapped")
|
||||
val newPath = newId.toPath()
|
||||
changedLibraries += LibraryChange(serverLibrary.id, serverLibrary.path, newId, newPath)
|
||||
|
||||
val jarFile = dep.copyTo(outputDir.resolve(newPath))
|
||||
TinyRemapper.run(
|
||||
dep.file.toPath(),
|
||||
outputDir.resolve(newPath),
|
||||
remapInfo,
|
||||
launcher.get(),
|
||||
layout.cache.resolve(paperTaskOutput("remap${remapInfo.name.capitalized()}.log")),
|
||||
workingDir
|
||||
)
|
||||
|
||||
libraries += FileEntry(jarFile.sha256asHex(), newId, newPath)
|
||||
libraries += FileEntry(outputDir.resolve(newPath).sha256asHex(), newId, newPath)
|
||||
} else {
|
||||
// we have a different version of this library (not remapped)
|
||||
val newId = dep.module
|
||||
val newPath = newId.toPath()
|
||||
changedLibraries += LibraryChange(serverLibrary.id, serverLibrary.path, newId, newPath)
|
||||
|
||||
val jarFile = dep.copyTo(outputDir.resolve(newPath))
|
||||
|
||||
libraries += FileEntry(jarFile.sha256asHex(), newId, newPath)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// New dependency
|
||||
val id = dep.module
|
||||
val path = id.toPath()
|
||||
val jarFile = dep.copyTo(outputDir.resolve(path))
|
||||
if (remapInfo != null) {
|
||||
// New dependency, remapped
|
||||
val id = dep.module.copy(version = dep.module.version + "-remapped")
|
||||
val path = id.toPath()
|
||||
|
||||
libraries += FileEntry(jarFile.sha256asHex(), id, path)
|
||||
TinyRemapper.run(
|
||||
dep.file.toPath(),
|
||||
outputDir.resolve(path),
|
||||
remapInfo,
|
||||
launcher.get(),
|
||||
layout.cache.resolve(paperTaskOutput("remap${remapInfo.name.capitalized()}.log")),
|
||||
workingDir
|
||||
)
|
||||
|
||||
libraries += FileEntry(outputDir.resolve(path).sha256asHex(), id, path)
|
||||
} else {
|
||||
// New dependency, not remapped
|
||||
val id = dep.module
|
||||
val path = id.toPath()
|
||||
val jarFile = dep.copyTo(outputDir.resolve(path))
|
||||
|
||||
libraries += FileEntry(jarFile.sha256asHex(), id, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,6 +253,7 @@ abstract class CreateBundlerJar : ZippedTask() {
|
|||
val version = capability.version ?: throw PaperweightException("Unknown version for ${capability.group}:${capability.name}")
|
||||
ModuleId(capability.group, capability.name, version)
|
||||
}
|
||||
|
||||
else -> throw PaperweightException("Unknown artifact result type: ${ident::class.java.name}")
|
||||
}
|
||||
}
|
|
@ -20,9 +20,10 @@
|
|||
* USA
|
||||
*/
|
||||
|
||||
package io.papermc.paperweight.tasks
|
||||
package io.papermc.paperweight.tasks.packaging
|
||||
|
||||
import io.papermc.paperweight.PaperweightException
|
||||
import io.papermc.paperweight.tasks.*
|
||||
import io.papermc.paperweight.util.*
|
||||
import io.papermc.paperweight.util.data.*
|
||||
import io.sigpipe.jbsdiff.Diff
|
Loading…
Reference in a new issue