Skip to content

Commit e8d66e8

Browse files
committed
Disable preprocessVersion being able to run in root project
1 parent 1dfadbf commit e8d66e8

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/main/java/com/minecrafttas/discombobulator/Discombobulator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import com.minecrafttas.discombobulator.extensions.PreprocessingConfiguration;
1818
import com.minecrafttas.discombobulator.tasks.TaskCollectBuilds;
1919
import com.minecrafttas.discombobulator.tasks.TaskPreprocessBase;
20+
import com.minecrafttas.discombobulator.tasks.TaskPreprocessVersion;
21+
import com.minecrafttas.discombobulator.tasks.TaskPreprocessVersionError;
2022
import com.minecrafttas.discombobulator.tasks.TaskPreprocessWatch;
2123

2224
/**
@@ -64,9 +66,18 @@ public void apply(Project project) {
6466
List<Task> compileTasks = new ArrayList<>();
6567
for (Project subProject : project.getSubprojects()) {
6668
compileTasks.add(subProject.getTasksByName("remapJar", false).iterator().next());
69+
// Register preprocessVersion task in subProjects
70+
TaskPreprocessVersion versionTask = subProject.getTasks().register("preprocessVersion", TaskPreprocessVersion.class).get();
71+
versionTask.setGroup("discombobulator");
72+
versionTask.setDescription("Preprocesses this version back to the base folder and to versions other than this one");
6773
}
6874
collectBuilds.updateCompileTasks(compileTasks);
6975

76+
// Register preprocessVersion task in root
77+
TaskPreprocessVersionError versionTaskRoot = project.getTasks().register("preprocessVersion", TaskPreprocessVersionError.class).get();
78+
versionTaskRoot.setGroup("discombobulator");
79+
versionTaskRoot.setDescription("Do not use this task! Use it in subprojects!");
80+
7081
project.afterEvaluate(_project -> {
7182
boolean inverted = config.getInverted().getOrElse(false);
7283
PORT_LOCK = config.getPort().getOrElse(8762);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.minecrafttas.discombobulator.tasks;
2+
3+
import org.gradle.api.DefaultTask;
4+
import org.gradle.api.tasks.TaskAction;
5+
6+
public class TaskPreprocessVersion extends DefaultTask {
7+
8+
@TaskAction
9+
public void preprocessVersion() {
10+
System.out.println("Test");
11+
}
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.minecrafttas.discombobulator.tasks;
2+
3+
import org.gradle.api.DefaultTask;
4+
import org.gradle.api.tasks.TaskAction;
5+
6+
/**
7+
* <p>Task class for stopping a task.
8+
* <p>{@link TaskPreprocessVersion} is intended for <strong>subprojects only!</strong><br>
9+
* And since gradle is such a cool program, it automatically creates a task in the root project as well,<br>
10+
* that you can not disable apparently.
11+
* <p>But you can register separate tasks to the root project, that will execute before everything else, so to stop it,<br>
12+
* we just need to throw an exception and it will stop all following tasks. Thanks Gradle!
13+
*/
14+
public class TaskPreprocessVersionError extends DefaultTask {
15+
16+
@TaskAction
17+
public void preprocessVersion() throws Exception {
18+
throw new Exception("\n\n!!!!!!!!!! Do not use this task on the root project !!!!!!!!!!\n\n"
19+
+ "This task is intended for subprojects only,\n"
20+
+ "so this exception will stop it from running on all subprojects.\n"
21+
+ "This was the only way I could find to disable the task for the root project, thanks Gradle!\n");
22+
}
23+
}

0 commit comments

Comments
 (0)