diff --git a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt index 53628220..0b7b31e8 100644 --- a/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt +++ b/paperweight-core/src/main/kotlin/io/papermc/paperweight/core/taskcontainers/AllTasks.kt @@ -82,7 +82,7 @@ open class AllTasks( if (project.isBaseExecution) { doNotTrackState("$name should always run when requested as part of the base execution.") } - printOutput.set(project.printApplyPatchesOutput()) + printOutput.set(project.isBaseExecution) branch.set("HEAD") upstreamBranch.set("upstream") @@ -110,7 +110,7 @@ open class AllTasks( if (project.isBaseExecution) { doNotTrackState("$name should always run when requested as part of the base execution.") } - printOutput.set(project.printApplyPatchesOutput()) + printOutput.set(project.isBaseExecution) patchDir.set(extension.paper.spigotServerPatchDir) remappedSource.set(remapSpigotSources.flatMap { it.sourcesOutputZip }) @@ -140,7 +140,6 @@ open class AllTasks( baseRef.set("base") patchDir.set(extension.paper.spigotApiPatchDir) - printOutput.set(project.printRebuildPatchesOutput()) } val rebuildServerPatches by tasks.registering { @@ -150,7 +149,6 @@ open class AllTasks( baseRef.set("base") patchDir.set(extension.paper.spigotServerPatchDir) - printOutput.set(project.printRebuildPatchesOutput()) } @Suppress("unused") diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ApplyGitPatches.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ApplyGitPatches.kt index d0b98caa..9bc3ab13 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ApplyGitPatches.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ApplyGitPatches.kt @@ -71,9 +71,13 @@ abstract class ApplyGitPatches : ControllableOutputTask() { @get:Inject abstract val providers: ProviderFactory + @get:Input + abstract val verbose: Property + override fun init() { printOutput.convention(false).finalizeValueOnRead() ignoreGitIgnore.convention(Git.ignoreProperty(providers)).finalizeValueOnRead() + verbose.convention(providers.verboseApplyPatches()) } @TaskAction @@ -91,7 +95,7 @@ abstract class ApplyGitPatches : ControllableOutputTask() { val target = outputPath.name if (printOutput.get()) { - println(" Resetting $target to ${upstream.path.name}...") + logger.lifecycle("Resetting $target to ${upstream.path.name}...") } val rootPatchDir = patchDir.pathOrNull ?: patchZip.path.let { unzip(it, findOutputDir(it)) } @@ -102,14 +106,14 @@ abstract class ApplyGitPatches : ControllableOutputTask() { if (unneededFiles.isPresent && unneededFiles.get().size > 0) { unneededFiles.get().forEach { path -> outputDir.path.resolve(path).deleteRecursive() } - git(*Git.add(ignoreGitIgnore, ".")).setupOut().run() - git("commit", "-m", "Initial", "--author=Initial Source ").setupOut().run() + git(*Git.add(ignoreGitIgnore, ".")).executeSilently() + git("commit", "-m", "Initial", "--author=Initial Source ").executeSilently() } git("tag", "-d", "base").runSilently(silenceErr = true) git("tag", "base").executeSilently(silenceErr = true) - applyGitPatches(git, target, outputDir.path, rootPatchDir, printOutput.get()) + applyGitPatches(git, target, outputDir.path, rootPatchDir, printOutput.get(), verbose.get()) } } finally { if (rootPatchDir != patchDir.pathOrNull) { @@ -124,10 +128,11 @@ fun ControllableOutputTask.applyGitPatches( target: String, outputDir: Path, patchDir: Path?, - printOutput: Boolean + printOutput: Boolean, + verbose: Boolean, ) { if (printOutput) { - println(" Applying patches to $target...") + logger.lifecycle("Applying patches to $target...") } val statusFile = outputDir.resolve(".git/patch-apply-failed") @@ -138,7 +143,7 @@ fun ControllableOutputTask.applyGitPatches( val patches = patchDir?.useDirectoryEntries("*.patch") { it.toMutableList() } ?: mutableListOf() if (patches.isEmpty()) { if (printOutput) { - println("No patches found") + logger.lifecycle("No patches found") } return } @@ -155,11 +160,12 @@ fun ControllableOutputTask.applyGitPatches( patch.copyTo(mailDir.resolve(patch.fileName)) } - val result = git("am", "--3way", "--ignore-whitespace", tempDir.absolutePathString()).captureOut() + val gitOut = printOutput && verbose + val result = git("am", "--3way", "--ignore-whitespace", tempDir.absolutePathString()).captureOut(gitOut) if (result.exit != 0) { statusFile.writeText("1") - if (!printOutput) { + if (!gitOut) { // Log the output anyway on failure logger.lifecycle(result.out) } @@ -170,7 +176,7 @@ fun ControllableOutputTask.applyGitPatches( } else { statusFile.deleteForcefully() if (printOutput) { - println(" Patches applied cleanly to $target") + logger.lifecycle("${patches.size} patches applied cleanly to $target") } } } finally { diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ApplyPaperPatches.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ApplyPaperPatches.kt index 7d1300ad..c45df651 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ApplyPaperPatches.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ApplyPaperPatches.kt @@ -89,9 +89,13 @@ abstract class ApplyPaperPatches : ControllableOutputTask() { @get:OutputDirectory abstract val mcDevSources: DirectoryProperty + @get:Input + abstract val verbose: Property + override fun init() { upstreamBranch.convention("master") ignoreGitIgnore.convention(Git.ignoreProperty(providers)).finalizeValueOnRead() + verbose.convention(providers.verboseApplyPatches()) } @TaskAction @@ -114,7 +118,7 @@ abstract class ApplyPaperPatches : ControllableOutputTask() { val target = outputFile.name if (printOutput.get()) { - println(" Creating $target from remapped source...") + logger.lifecycle("Creating $target from remapped source...") } Git(outputFile).let { git -> @@ -161,7 +165,7 @@ abstract class ApplyPaperPatches : ControllableOutputTask() { git("tag", "-d", "base").runSilently(silenceErr = true) git("tag", "base").executeSilently() - applyGitPatches(git, target, outputFile, patchDir.path, printOutput.get()) + applyGitPatches(git, target, outputFile, patchDir.path, printOutput.get(), verbose.get()) makeMcDevSrc(layout.cache, sourceMcDevJar.path, mcDevSources.path, outputDir.path, sourceDir, mcDataDir) } diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ControllableOutputTask.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ControllableOutputTask.kt index d47406c5..87e7185e 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ControllableOutputTask.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/ControllableOutputTask.kt @@ -23,8 +23,6 @@ package io.papermc.paperweight.tasks import io.papermc.paperweight.util.* -import java.io.ByteArrayOutputStream -import java.io.OutputStream import org.gradle.api.provider.Property import org.gradle.api.tasks.Console @@ -49,21 +47,4 @@ abstract class ControllableOutputTask : BaseTask() { setup(UselessOutputStream, System.out) } } - - class Result(val exit: Int, val out: String) - - fun Command.captureOut(): Result = run { - val out = ByteArrayOutputStream() - if (printOutput.get()) { - val combined = System.out + out - setup(combined, combined) - } else { - setup(out, out) - } - Result(run(), String(out.toByteArray())) - } - - private operator fun OutputStream.plus(out: OutputStream): OutputStream { - return DelegatingOutputStream(this, out) - } } diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RebuildGitPatches.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RebuildGitPatches.kt index d72b4f2e..e09fb89c 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RebuildGitPatches.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/RebuildGitPatches.kt @@ -70,13 +70,13 @@ abstract class RebuildGitPatches : ControllableOutputTask() { } if (printOutput.get()) { - println("Formatting patches for $what...") + logger.lifecycle("Formatting patches for $what...") } if (inputDir.path.resolve(".git/rebase-apply").exists()) { // in middle of a rebase, be smarter if (printOutput.get()) { - println("REBASE DETECTED - PARTIAL SAVE") + logger.lifecycle("REBASE DETECTED - PARTIAL SAVE") val last = inputDir.path.resolve(".git/rebase-apply/last").readText().trim().toInt() val next = inputDir.path.resolve(".git/rebase-apply/next").readText().trim().toInt() val orderedFiles = patchFolder.useDirectoryEntries("*.patch") { it.toMutableList() } @@ -106,10 +106,12 @@ abstract class RebuildGitPatches : ControllableOutputTask() { if (filterPatches.get()) { cleanupPatches(patchDirGit) - } + } else { + if (printOutput.get()) { + val saved = patchFolder.listDirectoryEntries("*.patch").size - if (printOutput.get()) { - println(" Patches saved for $what to ${patchFolder.name}/") + logger.lifecycle("Saved $saved patches for $what to ${layout.projectDirectory.path.relativize(patchFolder)}/") + } } } @@ -153,9 +155,9 @@ abstract class RebuildGitPatches : ControllableOutputTask() { } if (printOutput.get()) { - for (patch in patchFiles) { - println(patch.name) - } + val saved = patchFiles.size - noChangesPatches.size + val relDir = layout.projectDirectory.path.relativize(patchDir.path) + logger.lifecycle("Saved modified patches ($saved/${patchFiles.size}) for ${inputDir.path.name} to $relDir/") } } } diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/McDev.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/McDev.kt index 8f80675b..b7f7db83 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/McDev.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/McDev.kt @@ -101,7 +101,7 @@ object McDev { if (dataTargetDir != null) { logger.log( if (printOutput) LogLevel.LIFECYCLE else LogLevel.DEBUG, - "Importing {} data files from vanilla data...", + "Importing {} data files from vanilla...", dataImportMcDev.size ) diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt index 4e9ee692..3e64dca4 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/constants/constants.kt @@ -29,8 +29,7 @@ import org.gradle.api.Task const val PAPERWEIGHT_EXTENSION = "paperweight" const val PAPERWEIGHT_DEBUG = "paperweight.debug" -const val PAPERWEIGHT_PRINT_APPLY_PATCHES_OUTPUT = "paperweight.printBaseExecutionApplyPatchesOutput" -const val PAPERWEIGHT_PRINT_REBUILD_PATCHES_OUTPUT = "paperweight.printRebuildPatchesOutput" +const val PAPERWEIGHT_VERBOSE_APPLY_PATCHES = "paperweight.verboseApplyPatches" const val MC_LIBRARY_URL = "https://libraries.minecraft.net/" diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/git.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/git.kt index 26fdd1fa..71c9beee 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/git.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/git.kt @@ -199,4 +199,17 @@ class Command(private val processBuilder: ProcessBuilder, private val command: S setup(out, System.err) return if (run() == 0) String(out.toByteArray(), Charset.defaultCharset()) else null } + + class Result(val exit: Int, val out: String) + + fun captureOut(logOut: Boolean): Result = run { + val out = ByteArrayOutputStream() + if (logOut) { + val combined = DelegatingOutputStream(System.out, out) + setup(combined, combined) + } else { + setup(out, out) + } + Result(run(), String(out.toByteArray())) + } } diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt index 5f70a3c7..8b131d59 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt @@ -124,29 +124,18 @@ fun commentRegex(): Regex { return Regex("\\s*#.*") } -val Project.isBaseExecutionProvider: Provider - get() = providers.gradleProperty(PAPERWEIGHT_DOWNSTREAM_FILE_PROPERTY) +val ProviderFactory.isBaseExecution: Provider + get() = gradleProperty(PAPERWEIGHT_DOWNSTREAM_FILE_PROPERTY) .orElse(provider { "false" }) .map { it == "false" } val Project.isBaseExecution: Boolean - get() = isBaseExecutionProvider.get() + get() = providers.isBaseExecution.get() -fun Project.printApplyPatchesOutput(): Provider { - val base = isBaseExecutionProvider - val showOutput = providers.gradleProperty(PAPERWEIGHT_PRINT_APPLY_PATCHES_OUTPUT) +fun ProviderFactory.verboseApplyPatches(): Provider = + gradleProperty(PAPERWEIGHT_VERBOSE_APPLY_PATCHES) .map { it.toBoolean() } .orElse(false) - return base.zip(showOutput) { baseExecution, showOutputProp -> - return@zip baseExecution && showOutputProp - } -} - -fun Project.printRebuildPatchesOutput(): Provider { - return providers.gradleProperty(PAPERWEIGHT_PRINT_REBUILD_PATCHES_OUTPUT) - .map { it.toBoolean() } - .orElse(false) -} val redirectThreadCount: AtomicLong = AtomicLong(0) diff --git a/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt b/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt index 847a7b55..e6ebc9bf 100644 --- a/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt +++ b/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/PaperweightPatcher.kt @@ -261,7 +261,7 @@ class PaperweightPatcher : Plugin { if (isBaseExecution) { doNotTrackState("$name should always run when requested as part of the base execution.") } - printOutput.set(printApplyPatchesOutput()) + printOutput.set(isBaseExecution) val (cloneTask, upstreamDataTask) = upstreamTaskPair dependsOn(upstreamDataTask) @@ -295,7 +295,6 @@ class PaperweightPatcher : Plugin { patchDir.convention(config.patchDir) inputDir.convention(config.outputDir) baseRef.convention("base") - printOutput.set(project.printRebuildPatchesOutput()) } rebuildPatches { diff --git a/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/tasks/PatcherApplyGitPatches.kt b/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/tasks/PatcherApplyGitPatches.kt index 8610117a..3107d846 100644 --- a/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/tasks/PatcherApplyGitPatches.kt +++ b/paperweight-patcher/src/main/kotlin/io/papermc/paperweight/patcher/tasks/PatcherApplyGitPatches.kt @@ -85,11 +85,15 @@ abstract class PatcherApplyGitPatches : ControllableOutputTask() { @get:OutputDirectory abstract val mcDevSources: DirectoryProperty + @get:Input + abstract val verbose: Property + override fun init() { upstreamBranch.convention("master") importMcDev.convention(false) printOutput.convention(true).finalizeValueOnRead() ignoreGitIgnore.convention(Git.ignoreProperty(providers)).finalizeValueOnRead() + verbose.convention(providers.verboseApplyPatches()) } @TaskAction @@ -112,7 +116,7 @@ abstract class PatcherApplyGitPatches : ControllableOutputTask() { val target = output.name if (printOutput.get()) { - println(" Creating $target from patch source...") + logger.lifecycle("Creating $target from patch source...") } if (bareDirectory.get()) { @@ -157,7 +161,7 @@ abstract class PatcherApplyGitPatches : ControllableOutputTask() { git("tag", "-d", "base").runSilently(silenceErr = true) git("tag", "base").executeSilently() - applyGitPatches(git, target, output, patchDir.pathOrNull, printOutput.get()) + applyGitPatches(git, target, output, patchDir.pathOrNull, printOutput.get(), verbose.get()) makeMcDevSrc(layout.cache, sourceMcDevJar.path, mcDevSources.path, outputDir.path, srcDir, dataDir) }