-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to the runtime builder to customize individual tasks …
…in addition to manipulating the task tree.
- Loading branch information
Showing
9 changed files
with
197 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...on/src/main/groovy/net/neoforged/gradle/dsl/common/runtime/tasks/tree/TaskCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package net.neoforged.gradle.dsl.common.runtime.tasks.tree; | ||
|
||
import net.neoforged.gradle.dsl.common.runtime.tasks.Runtime; | ||
import org.gradle.api.Task; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Encapsulates a task customizer that changes the configuration of a Gradle Task encapsulating a Neoform step. | ||
*/ | ||
public final class TaskCustomizer<T extends Task> { | ||
private final Class<T> taskClass; | ||
private final Consumer<T> taskCustomizer; | ||
|
||
public TaskCustomizer(Class<T> taskClass, Consumer<T> taskCustomizer) { | ||
this.taskClass = taskClass; | ||
this.taskCustomizer = taskCustomizer; | ||
} | ||
|
||
/** | ||
* @return The expected task type. This will be validated to avoid unchecked casts. | ||
*/ | ||
public Class<T> getTaskClass() { | ||
return taskClass; | ||
} | ||
|
||
/** | ||
* @return The function that will be applied to the task using {@link Task#configure}. | ||
*/ | ||
public Consumer<T> getTaskCustomizer() { | ||
return taskCustomizer; | ||
} | ||
|
||
public void apply(Runtime task) { | ||
if (!taskClass.isInstance(task)) { | ||
throw new IllegalArgumentException("Customization for step " + task.getStepName() | ||
+ " requires task type " + taskClass + " but actual task is " + task.getClass()); | ||
} | ||
taskCustomizer.accept(taskClass.cast(task)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.