Add diff task for paperweight development

This commit is contained in:
Kyle Wood 2021-11-24 00:03:44 -06:00
parent 6bc03c39d9
commit 782dec5128
No known key found for this signature in database
GPG key ID: 86AF5613ACA30CC5
3 changed files with 74 additions and 6 deletions

View file

@ -62,6 +62,16 @@ class PaperweightCore : Plugin<Project> {
target.configurations.create(DECOMPILER_CONFIG)
target.configurations.create(PAPERCLIP_CONFIG)
if (target.providers.gradleProperty("paperweight.dev").forUseAtConfigurationTime().orNull == "true") {
target.tasks.register<CreateDiffOutput>("diff") {
inputDir.convention(ext.paper.paperServerDir.map { it.dir("src/main/java") })
val prop = target.providers.gradleProperty("paperweight.diff.output").forUseAtConfigurationTime()
if (prop.isPresent) {
baseDir.convention(target.layout.projectDirectory.dir(prop))
}
}
}
val tasks = AllTasks(target)
val devBundleTasks = DevBundleTasks(target)

View file

@ -0,0 +1,63 @@
/*
* paperweight is a Gradle plugin for the PaperMC project.
*
* Copyright (c) 2021 Kyle Wood (DenWav)
* Contributors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 only, no later versions.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package io.papermc.paperweight.tasks
import io.papermc.paperweight.util.*
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.UntrackedTask
import org.gradle.api.tasks.options.Option
@UntrackedTask(because = "Always copy files")
abstract class CreateDiffOutput : BaseTask() {
@get:InputDirectory
abstract val inputDir: DirectoryProperty
@get:OutputDirectory
abstract val outputDir: DirectoryProperty
@get:Internal
abstract val baseDir: DirectoryProperty
@get:Internal
@get:Option(option = "target", description = "Directory name of the diff output")
abstract val target: Property<String>
override fun init() {
baseDir.convention(layout.cacheDir("paperweight/diff"))
outputDir.convention(baseDir.flatMap { it.dir(target) })
}
@TaskAction
fun run() {
val output = outputDir.path
output.deleteRecursively()
inputDir.path.copyRecursivelyTo(output)
}
}

View file

@ -45,8 +45,6 @@ import java.util.Optional
import java.util.concurrent.ThreadLocalRandom
import kotlin.io.path.*
import org.cadixdev.lorenz.merge.MergeResult
import org.cadixdev.lorenz.model.ClassMapping
import org.cadixdev.lorenz.model.MemberMapping
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.FileCollection
@ -81,7 +79,7 @@ inline fun <reified T> Gson.fromJson(any: Any): T = when (any) {
}
val ProjectLayout.cache: Path
get() = projectDirectory.file(".gradle/$CACHE_PATH").path
get() = projectDirectory.dir(".gradle/$CACHE_PATH").path
fun ProjectLayout.cacheDir(path: String) = projectDirectory.dir(".gradle/$CACHE_PATH").dir(path)
fun ProjectLayout.initSubmodules() {
@ -238,9 +236,6 @@ fun findOutputDir(baseFile: Path): Path {
return dir
}
val MemberMapping<*, *>.parentClass: ClassMapping<*, *>
get() = parent as ClassMapping<*, *>
private val emptyMergeResult = MergeResult(null)
fun <T> emptyMergeResult(): MergeResult<T?> {
@Suppress("UNCHECKED_CAST")