Skip to content

Commit

Permalink
return task provider, better dependsOn
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Nov 26, 2024
1 parent c143a6b commit cfede99
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskProvider
import org.intellij.lang.annotations.Language
import org.jetbrains.annotations.ApiStatus
import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree
Expand Down Expand Up @@ -226,39 +227,39 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) :
}
}

fun remap(task: Task) {
remap(task) {}
fun remap(task: Task): TaskProvider<RemapJarTask> {
return remap(task) {}
}

fun remap(task: Task, action: RemapJarTask.() -> Unit) {
remap(task, "remap${task.name.capitalized()}", action)
fun remap(task: Task, action: RemapJarTask.() -> Unit): TaskProvider<RemapJarTask> {
return remap(task, "remap${task.name.capitalized()}", action)
}

fun remap(
task: Task,
@DelegatesTo(value = RemapJarTask::class, strategy = Closure.DELEGATE_FIRST)
action: Closure<*>
) {
remap(task) {
): TaskProvider<RemapJarTask> {
return remap(task) {
action.delegate = this
action.resolveStrategy = Closure.DELEGATE_FIRST
action.call()
}
}

fun remap(task: Task, name: String) {
remap(task, name) {}
fun remap(task: Task, name: String): TaskProvider<RemapJarTask> {
return remap(task, name) {}
}

abstract fun remap(task: Task, name: String, action: RemapJarTask.() -> Unit)
abstract fun remap(task: Task, name: String, action: RemapJarTask.() -> Unit): TaskProvider<RemapJarTask>

fun remap(
task: Task,
name: String,
@DelegatesTo(value = RemapJarTask::class, strategy = Closure.DELEGATE_FIRST)
action: Closure<*>
) {
remap(task, name) {
): TaskProvider<RemapJarTask> {
return remap(task, name) {
action.delegate = this
action.resolveStrategy = Closure.DELEGATE_FIRST
action.call()
Expand All @@ -268,15 +269,15 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) :
/**
* @since 1.3.10
*/
fun remapSources(task: Task) {
remapSources(task) {}
fun remapSources(task: Task): TaskProvider<RemapSourcesJarTask> {
return remapSources(task) {}
}

/**
* @since 1.3.10
*/
fun remapSources(task: Task, action: RemapSourcesJarTask.() -> Unit) {
remapSources(task, "remap${task.name.capitalized()}", action)
fun remapSources(task: Task, action: RemapSourcesJarTask.() -> Unit): TaskProvider<RemapSourcesJarTask> {
return remapSources(task, "remap${task.name.capitalized()}", action)
}

/**
Expand All @@ -286,8 +287,8 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) :
task: Task,
@DelegatesTo(value = RemapSourcesJarTask::class, strategy = Closure.DELEGATE_FIRST)
action: Closure<*>
) {
remapSources(task) {
): TaskProvider<RemapSourcesJarTask> {
return remapSources(task) {
action.delegate = this
action.resolveStrategy = Closure.DELEGATE_FIRST
action.call()
Expand All @@ -297,14 +298,14 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) :
/**
* @since 1.3.10
*/
fun remapSources(task: Task, name: String) {
remapSources(task, name) {}
fun remapSources(task: Task, name: String): TaskProvider<RemapSourcesJarTask> {
return remapSources(task, name) {}
}

/**
* @since 1.3.10
*/
abstract fun remapSources(task: Task, name: String, action: RemapSourcesJarTask.() -> Unit)
abstract fun remapSources(task: Task, name: String, action: RemapSourcesJarTask.() -> Unit): TaskProvider<RemapSourcesJarTask>

/**
* @since 1.3.10
Expand All @@ -314,8 +315,8 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) :
name: String,
@DelegatesTo(value = RemapSourcesJarTask::class, strategy = Closure.DELEGATE_FIRST)
action: Closure<*>
) {
remapSources(task, name) {
): TaskProvider<RemapSourcesJarTask> {
return remapSources(task, name) {
action.delegate = this
action.resolveStrategy = Closure.DELEGATE_FIRST
action.call()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.tasks.Jar
import org.intellij.lang.annotations.Language
import org.jetbrains.annotations.ApiStatus
Expand Down Expand Up @@ -137,7 +138,7 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft
// remove unimined deps
}

override fun remap(task: Task, name: String, action: RemapJarTask.() -> Unit) {
override fun remap(task: Task, name: String, action: RemapJarTask.() -> Unit): TaskProvider<RemapJarTask> {
val remapTask = project.tasks.register(name, RemapJarTaskImpl::class.java, this)
remapTask.configure {
it.dependsOn(task)
Expand All @@ -147,9 +148,10 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft
it.action()
mcPatcher.configureRemapJar(it)
}
return remapTask as TaskProvider<RemapJarTask>
}

override fun remapSources(task: Task, name: String, action: RemapSourcesJarTask.() -> Unit) {
override fun remapSources(task: Task, name: String, action: RemapSourcesJarTask.() -> Unit): TaskProvider<RemapSourcesJarTask> {
val remapTask = project.tasks.register(name, RemapSourcesJarTaskImpl::class.java, this)
remapTask.configure {
it.dependsOn(task)
Expand All @@ -159,6 +161,7 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft
it.action()
mcPatcher.configureRemapJar(it)
}
return remapTask as TaskProvider<RemapSourcesJarTask>
}

override val mergedOfficialMinecraftFile: File? by lazy {
Expand Down Expand Up @@ -452,7 +455,7 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft

private inline fun <reified T> applyDefaultRemapJar(
inputTaskName: String,
remappingFunction: (Task, JarInterface<AbstractRemapJarTask>.() -> Unit) -> Unit,
remappingFunction: (Task, JarInterface<AbstractRemapJarTask>.() -> Unit) -> TaskProvider<*>,
crossinline defaultTaskConfiguration: Jar.() -> Unit
) where T : AbstractRemapJarTask, T : JarInterface<AbstractRemapJarTask> {
val inputTaskNameSS = inputTaskName.withSourceSet(sourceSet)
Expand Down Expand Up @@ -482,12 +485,12 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft
archiveClassifier.set(if(!oldClassifier.isNullOrEmpty()) "$oldClassifier-dev" else "dev")
}

remappingFunction(inputTask) {
val taskProvider = remappingFunction(inputTask) {
group = "unimined"
description = "Remaps $inputTask's output jar"
asJar.archiveClassifier.set(oldClassifier)
project.tasks.getByName("build").dependsOn(this)
}
project.tasks.getByName("build").dependsOn(taskProvider)
}

fun applyRunConfigs() {
Expand Down

0 comments on commit cfede99

Please sign in to comment.