Skip to content

Commit

Permalink
chore: Remove unused code, move legacy code only used by userdev to u…
Browse files Browse the repository at this point in the history
…serdev
  • Loading branch information
jpenilla committed Dec 30, 2024
1 parent f2cc105 commit 787f10e
Show file tree
Hide file tree
Showing 21 changed files with 224 additions and 640 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import io.papermc.paperweight.core.tasks.SetupPaperScript
import io.papermc.paperweight.core.util.coreExt
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.tasks.mache.DecompileJar
import io.papermc.paperweight.tasks.mache.RemapJar
import io.papermc.paperweight.tasks.mache.RunCodebook
import io.papermc.paperweight.util.*
import io.papermc.paperweight.util.constants.*
import io.papermc.paperweight.util.data.mache.*
Expand All @@ -45,7 +45,7 @@ class CoreTasks(
val mache: Property<MacheMeta>,
tasks: TaskContainer = project.tasks
) : AllTasks(project) {
val macheRemapJar by tasks.registering(RemapJar::class) {
val macheRemapJar by tasks.registering(RunCodebook::class) {
serverJar.set(extractFromBundler.flatMap { it.serverJar })
serverMappings.set(downloadMappings.flatMap { it.outputFile })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

package io.papermc.paperweight.core.tasks.patching

import io.papermc.paperweight.PaperweightException
import io.papermc.paperweight.tasks.*
import io.papermc.paperweight.util.*
import kotlin.io.path.createDirectories
import java.nio.file.Path
import kotlin.io.path.*
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
Expand Down Expand Up @@ -89,4 +91,65 @@ abstract class ApplyFeaturePatches : ControllableOutputTask() {

applyGitPatches(git, "server repo", repoPath, patches.path, printOutput.get(), verbose.get())
}

private fun applyGitPatches(
git: Git,
target: String,
outputDir: Path,
patchDir: Path?,
printOutput: Boolean,
verbose: Boolean,
) {
if (printOutput) {
logger.lifecycle("Applying patches to $target...")
}

val statusFile = outputDir.resolve(".git/patch-apply-failed")
statusFile.deleteForcefully()

git("am", "--abort").runSilently(silenceErr = true)

val patches = patchDir?.useDirectoryEntries("*.patch") { it.toMutableList() } ?: mutableListOf()
if (patches.isEmpty()) {
if (printOutput) {
logger.lifecycle("No patches found")
}
return
}

// This prevents the `git am` command line from getting too big with too many patches
// mostly an issue with Windows
layout.cache.createDirectories()
val tempDir = createTempDirectory(layout.cache, "paperweight")
try {
val mailDir = tempDir.resolve("new")
mailDir.createDirectories()

for (patch in patches) {
patch.copyTo(mailDir.resolve(patch.fileName))
}

val gitOut = printOutput && verbose
val result = git("am", "--3way", "--ignore-whitespace", tempDir.absolutePathString()).captureOut(gitOut)
if (result.exit != 0) {
statusFile.writeText("1")

if (!gitOut) {
// Log the output anyway on failure
logger.lifecycle(result.out)
}
logger.error("*** Please review above details and finish the apply then")
logger.error("*** save the changes with `./gradlew rebuildPatches`")

throw PaperweightException("Failed to apply patches")
} else {
statusFile.deleteForcefully()
if (printOutput) {
logger.lifecycle("${patches.size} patches applied cleanly to $target")
}
}
} finally {
tempDir.deleteRecursive()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,23 @@ abstract class ApplyFilePatches : BaseTask() {
}
}

private fun recreateCloneDirectory(target: Path) {
if (target.exists()) {
if (target.resolve(".git").isDirectory()) {
val git = Git(target)
git("clean", "-fxd").runSilently(silenceErr = true)
git("reset", "--hard", "HEAD").runSilently(silenceErr = true)
} else {
for (entry in target.listDirectoryEntries()) {
entry.deleteRecursive()
}
target.createDirectories()
}
} else {
target.createDirectories()
}
}

private fun tagBase() {
val git = Git.open(output.path.toFile())
val ident = PersonIdent("base", "[email protected]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fun Project.createBuildTasks(
}
}

val reobfJar by tasks.registering<RemapJar> {
val reobfJar by tasks.registering<RemapJarTiny> {
group = "build"
description = "Re-obfuscate the built jar to obf mappings"

Expand Down Expand Up @@ -102,5 +102,5 @@ fun Task.reobfRequiresDebug() {

data class ServerBuildTasks(
val includeMappings: TaskProvider<IncludeMappings>,
val reobfJar: TaskProvider<RemapJar>,
val reobfJar: TaskProvider<RemapJarTiny>,
)

This file was deleted.

Loading

0 comments on commit 787f10e

Please sign in to comment.