Skip to content

Commit 703cf83

Browse files
authored
Use distinct branding for tasks when they're being used as part of NeoDev (#186)
1 parent 12ce9e2 commit 703cf83

File tree

8 files changed

+51
-34
lines changed

8 files changed

+51
-34
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.neoforged.moddevgradle.internal;
2+
3+
/**
4+
* Used to customize the groups of tasks generated by MDG.
5+
*
6+
* @param publicTaskGroup Use this group for tasks that are considered to be part of the user-interface of MDG.
7+
* @param internalTaskGroup Use this group for tasks that are considered to be an implementation detail of MDG.
8+
*/
9+
record Branding(String publicTaskGroup, String internalTaskGroup) {
10+
public static final Branding MDG = new Branding("mod development", "mod development/internal");
11+
public static final Branding NEODEV = new Branding("neoforge development", "neoforge development/internal");
12+
}

src/main/java/net/neoforged/moddevgradle/internal/EclipseIntegration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ sealed class EclipseIntegration extends IdeIntegration permits VsCodeIntegration
4040

4141
protected final EclipseModel eclipseModel;
4242

43-
protected EclipseIntegration(Project project) {
44-
super(project);
43+
protected EclipseIntegration(Project project, Branding branding) {
44+
super(project, branding);
4545
this.eclipseModel = getOrCreateEclipseModel(project);
4646
LOG.debug("Configuring Eclipse model for Eclipse project '{}'.", eclipseModel.getProject().getName());
4747

src/main/java/net/neoforged/moddevgradle/internal/IdeIntegration.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,36 @@ sealed abstract class IdeIntegration permits IntelliJIntegration, EclipseIntegra
3131

3232
protected final Project project;
3333

34-
public IdeIntegration(Project project) {
34+
public IdeIntegration(Project project, Branding branding) {
3535
this.project = project;
3636
this.ideSyncTask = project.getTasks().register("neoForgeIdeSync", task -> {
37-
task.setGroup(ModDevPlugin.INTERNAL_TASK_GROUP);
37+
task.setGroup(branding.internalTaskGroup());
3838
task.setDescription("A utility task that is used to create necessary files when the Gradle project is synchronized with the IDE project.");
3939
});
4040
}
4141

42-
public static IdeIntegration of(Project project) {
42+
public static IdeIntegration of(Project project, Branding branding) {
4343
var ideIntegration = ExtensionUtils.findExtension(project, "mdgInternalIdeIntegration", IdeIntegration.class);
4444
if (ideIntegration == null) {
45-
ideIntegration = createForProject(project);
45+
ideIntegration = createForProject(project, branding);
4646
project.getExtensions().add(IdeIntegration.class, "mdgInternalIdeIntegration", ideIntegration);
4747
}
4848
return ideIntegration;
4949
}
5050

51-
private static IdeIntegration createForProject(Project project) {
51+
private static IdeIntegration createForProject(Project project, Branding branding) {
5252
if (IdeDetection.isVsCode()) {
5353
// VSCode internally uses Eclipse and as such, we need to prioritize it over the pure Eclipse integration
5454
LOG.debug("Activating VSCode integration for project {}.", project.getPath());
55-
return new VsCodeIntegration(project);
55+
return new VsCodeIntegration(project, branding);
5656
} else if (IdeDetection.isEclipse()) {
5757
LOG.debug("Activating Eclipse integration for project {}.", project.getPath());
58-
return new EclipseIntegration(project);
58+
return new EclipseIntegration(project, branding);
5959
} else if (IdeDetection.isIntelliJSync()) {
6060
LOG.debug("Activating IntelliJ integration for project {}.", project.getPath());
61-
return new IntelliJIntegration(project);
61+
return new IntelliJIntegration(project, branding);
6262
} else {
63-
return new NoIdeIntegration(project);
63+
return new NoIdeIntegration(project, branding);
6464
}
6565
}
6666

src/main/java/net/neoforged/moddevgradle/internal/IntelliJIntegration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ final class IntelliJIntegration extends IdeIntegration {
4646

4747
private final IdeaModel rootIdeaModel;
4848

49-
IntelliJIntegration(Project project) {
50-
super(project);
49+
IntelliJIntegration(Project project, Branding branding) {
50+
super(project, branding);
5151

5252
// While the IDEA model on the root project is the only sensible place to adjust IntelliJ project-wide settings
5353
// such as run configurations.

src/main/java/net/neoforged/moddevgradle/internal/ModDevPlugin.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ public class ModDevPlugin implements Plugin<Project> {
6767
*/
6868
static final String JUNIT_GAME_DIR = "build/minecraft-junit";
6969

70-
private static final String TASK_GROUP = "mod development";
71-
static final String INTERNAL_TASK_GROUP = "mod development/internal";
72-
7370
/**
7471
* Name of the configuration in which we place the required dependencies to develop mods for use in the runtime-classpath.
7572
* We cannot use "runtimeOnly", since the contents of that are published.
@@ -110,7 +107,7 @@ public void apply(Project project) {
110107
var layout = project.getLayout();
111108
var tasks = project.getTasks();
112109

113-
var ideIntegration = IdeIntegration.of(project);
110+
var ideIntegration = IdeIntegration.of(project, Branding.MDG);
114111

115112
// We use this directory to store intermediate files used during moddev
116113
var modDevBuildDir = layout.getBuildDirectory().dir("moddev");
@@ -182,7 +179,7 @@ public void apply(Project project) {
182179

183180
// it has to contain client-extra to be loaded by FML, and it must be added to the legacy CP
184181
var createArtifacts = tasks.register("createMinecraftArtifacts", CreateMinecraftArtifacts.class, task -> {
185-
task.setGroup(INTERNAL_TASK_GROUP);
182+
task.setGroup(Branding.MDG.internalTaskGroup());
186183
task.setDescription("Creates the NeoForge and Minecraft artifacts by invoking NFRT.");
187184
for (var configuration : createManifestConfigurations) {
188185
task.addArtifactsToManifest(configuration);
@@ -215,7 +212,7 @@ public void apply(Project project) {
215212

216213
var downloadAssets = tasks.register("downloadAssets", DownloadAssets.class, task -> {
217214
// Not in the internal group in case someone wants to "preload" the asset before they go offline
218-
task.setGroup(TASK_GROUP);
215+
task.setGroup(Branding.MDG.publicTaskGroup());
219216
task.setDescription("Downloads the Minecraft assets and asset index needed to run a Minecraft client or generate client-side resources.");
220217
// While downloadAssets does not require *all* of the dependencies, it does need NeoForge/NeoForm to benefit
221218
// from any caching/overrides applied to these dependencies in Gradle
@@ -306,6 +303,7 @@ public void apply(Project project) {
306303

307304
setupRuns(
308305
project,
306+
Branding.MDG,
309307
modDevBuildDir,
310308
extension.getRuns(),
311309
userDevConfigOnly,
@@ -342,6 +340,7 @@ public void apply(Project project) {
342340

343341
setupTestTask(
344342
project,
343+
Branding.MDG,
345344
userDevConfigOnly,
346345
tasks.named("test", Test.class),
347346
extension.getUnitTest().getLoadedMods(),
@@ -473,14 +472,15 @@ private List<Configuration> configureArtifactManifestConfigurations(Project proj
473472
}
474473

475474
static void setupRuns(Project project,
475+
Branding branding,
476476
Provider<Directory> argFileDir,
477477
DomainObjectCollection<RunModel> runs,
478478
Object runTemplatesSourceFile,
479479
Consumer<Configuration> configureModulePath,
480480
Consumer<Configuration> configureLegacyClasspath,
481481
Provider<RegularFile> assetPropertiesFile
482482
) {
483-
var ideIntegration = IdeIntegration.of(project);
483+
var ideIntegration = IdeIntegration.of(project, branding);
484484

485485
// Create a configuration to resolve DevLaunch without leaking it to consumers
486486
var devLaunchConfig = project.getConfigurations().create("devLaunchConfig", spec -> {
@@ -492,6 +492,7 @@ static void setupRuns(Project project,
492492
runs.all(run -> {
493493
var prepareRunTask = setupRunInGradle(
494494
project,
495+
branding,
495496
argFileDir,
496497
run,
497498
runTemplatesSourceFile,
@@ -513,6 +514,7 @@ static void setupRuns(Project project,
513514
*/
514515
private static TaskProvider<PrepareRun> setupRunInGradle(
515516
Project project,
517+
Branding branding,
516518
Provider<Directory> argFileDir,
517519
RunModel run,
518520
Object runTemplatesFile,
@@ -521,7 +523,7 @@ private static TaskProvider<PrepareRun> setupRunInGradle(
521523
Provider<RegularFile> assetPropertiesFile,
522524
Configuration devLaunchConfig
523525
) {
524-
var ideIntegration = IdeIntegration.of(project);
526+
var ideIntegration = IdeIntegration.of(project, branding);
525527
var configurations = project.getConfigurations();
526528
var javaExtension = ExtensionUtils.getExtension(project, "java", JavaPluginExtension.class);
527529
var tasks = project.getTasks();
@@ -561,14 +563,14 @@ private static TaskProvider<PrepareRun> setupRunInGradle(
561563
});
562564

563565
var writeLcpTask = tasks.register(InternalModelHelper.nameOfRun(run, "write", "legacyClasspath"), WriteLegacyClasspath.class, writeLcp -> {
564-
writeLcp.setGroup(INTERNAL_TASK_GROUP);
566+
writeLcp.setGroup(branding.internalTaskGroup());
565567
writeLcp.setDescription("Writes the legacyClasspath file for the " + run.getName() + " Minecraft run, containing all dependencies that shouldn't be considered boot modules.");
566568
writeLcp.getLegacyClasspathFile().set(argFileDir.map(dir -> dir.file(InternalModelHelper.nameOfRun(run, "", "legacyClasspath") + ".txt")));
567569
writeLcp.addEntries(legacyClasspathConfiguration);
568570
});
569571

570572
var prepareRunTask = tasks.register(InternalModelHelper.nameOfRun(run, "prepare", "run"), PrepareRun.class, task -> {
571-
task.setGroup(INTERNAL_TASK_GROUP);
573+
task.setGroup(branding.internalTaskGroup());
572574
task.setDescription("Prepares all files needed to launch the " + run.getName() + " Minecraft run.");
573575

574576
task.getGameDirectory().set(run.getGameDirectory());
@@ -592,7 +594,7 @@ private static TaskProvider<PrepareRun> setupRunInGradle(
592594
ideIntegration.runTaskOnProjectSync(prepareRunTask);
593595

594596
var createLaunchScriptTask = tasks.register(InternalModelHelper.nameOfRun(run, "create", "launchScript"), CreateLaunchScriptTask.class, task -> {
595-
task.setGroup(INTERNAL_TASK_GROUP);
597+
task.setGroup(branding.internalTaskGroup());
596598
task.setDescription("Creates a bash/shell-script to launch the " + run.getName() + " Minecraft run from outside Gradle or your IDE.");
597599

598600
task.getWorkingDirectory().set(run.getGameDirectory().map(d -> d.getAsFile().getAbsolutePath()));
@@ -619,7 +621,7 @@ private static TaskProvider<PrepareRun> setupRunInGradle(
619621
ideIntegration.runTaskOnProjectSync(createLaunchScriptTask);
620622

621623
tasks.register(InternalModelHelper.nameOfRun(run, "run", ""), RunGameTask.class, task -> {
622-
task.setGroup(TASK_GROUP);
624+
task.setGroup(branding.publicTaskGroup());
623625
task.setDescription("Runs the " + run.getName() + " Minecraft run configuration.");
624626

625627
// Launch with the Java version used in the project
@@ -656,6 +658,7 @@ public void setupTestTask() {
656658
* @see #setupRunInGradle for a description of the parameters
657659
*/
658660
static void setupTestTask(Project project,
661+
Branding branding,
659662
Object runTemplatesSourceFile,
660663
TaskProvider<Test> testTask,
661664
SetProperty<ModModel> loadedMods,
@@ -667,7 +670,7 @@ static void setupTestTask(Project project,
667670
) {
668671
var gameDirectory = new File(project.getProjectDir(), JUNIT_GAME_DIR);
669672

670-
var ideIntegration = IdeIntegration.of(project);
673+
var ideIntegration = IdeIntegration.of(project, branding);
671674

672675
var tasks = project.getTasks();
673676
var configurations = project.getConfigurations();
@@ -698,7 +701,7 @@ static void setupTestTask(Project project,
698701
var runArgsDir = argFileDir.map(dir -> dir.dir("junit"));
699702

700703
var writeLcpTask = tasks.register("writeNeoForgeTestClasspath", WriteLegacyClasspath.class, writeLcp -> {
701-
writeLcp.setGroup(INTERNAL_TASK_GROUP);
704+
writeLcp.setGroup(branding.internalTaskGroup());
702705
writeLcp.setDescription("Writes the legacyClasspath file for the test run, containing all dependencies that shouldn't be considered boot modules.");
703706
writeLcp.getLegacyClasspathFile().convention(runArgsDir.map(dir -> dir.file("legacyClasspath.txt")));
704707
writeLcp.addEntries(legacyClasspathConfiguration);
@@ -708,7 +711,7 @@ static void setupTestTask(Project project,
708711
var programArgsFile = runArgsDir.map(dir -> dir.file("programArgs.txt"));
709712
var log4j2ConfigFile = runArgsDir.map(dir -> dir.file("log4j2.xml"));
710713
var prepareTask = tasks.register("prepareNeoForgeTestFiles", PrepareTest.class, task -> {
711-
task.setGroup(INTERNAL_TASK_GROUP);
714+
task.setGroup(branding.internalTaskGroup());
712715
task.setDescription("Prepares all files needed to run the JUnit test task.");
713716
task.getGameDirectory().set(gameDirectory);
714717
task.getVmArgsFile().set(vmArgsFile);
@@ -748,7 +751,7 @@ private static void setupJarJar(Project project) {
748751
SourceSetContainer sourceSets = ExtensionUtils.getExtension(project, "sourceSets", SourceSetContainer.class);
749752
sourceSets.all(sourceSet -> {
750753
var jarJarTask = JarJar.registerWithConfiguration(project, sourceSet.getTaskName(null, "jarJar"));
751-
jarJarTask.configure(task -> task.setGroup(INTERNAL_TASK_GROUP));
754+
jarJarTask.configure(task -> task.setGroup(Branding.MDG.internalTaskGroup()));
752755

753756
// The target jar task for this source set might not exist, and #named(String) requires the task to exist
754757
var jarTaskName = sourceSet.getJarTaskName();

src/main/java/net/neoforged/moddevgradle/internal/NeoDevFacade.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static void setupRuns(Project project,
3636
) {
3737
ModDevPlugin.setupRuns(
3838
project,
39+
Branding.NEODEV,
3940
argFileDir,
4041
runs,
4142
runTemplatesSourceFile,
@@ -57,6 +58,7 @@ public static void setupTestTask(Project project,
5758
) {
5859
ModDevPlugin.setupTestTask(
5960
project,
61+
Branding.NEODEV,
6062
runTemplatesSourceFile,
6163
testTask,
6264
loadedMods,
@@ -69,6 +71,6 @@ public static void setupTestTask(Project project,
6971
}
7072

7173
public static void runTaskOnProjectSync(Project project, Object task) {
72-
IdeIntegration.of(project).runTaskOnProjectSync(task);
74+
IdeIntegration.of(project, Branding.NEODEV).runTaskOnProjectSync(task);
7375
}
7476
}

src/main/java/net/neoforged/moddevgradle/internal/NoIdeIntegration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* This implementation of {@link IdeIntegration} is used when no IDE was detected to host Gradle.
77
*/
88
final class NoIdeIntegration extends IdeIntegration {
9-
public NoIdeIntegration(Project project) {
10-
super(project);
9+
public NoIdeIntegration(Project project, Branding branding) {
10+
super(project, branding);
1111
}
1212
}

src/main/java/net/neoforged/moddevgradle/internal/VsCodeIntegration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
final class VsCodeIntegration extends EclipseIntegration {
2323
private static final Logger LOG = LoggerFactory.getLogger(VsCodeIntegration.class);
2424

25-
VsCodeIntegration(Project project) {
26-
super(project);
25+
VsCodeIntegration(Project project, Branding branding) {
26+
super(project, branding);
2727
}
2828

2929
@Override

0 commit comments

Comments
 (0)