From 509266ce158451da1754d3736e77efb50aded8a9 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 16 Dec 2023 13:48:48 +0000 Subject: [PATCH] Allow disabling RunConfig appending project path Add a `appendConfigNameWithPath` property to `RunConfigSettings` controlling whether to append the path for non-root projects. Default behaviour is unchanged. --- .../loom/configuration/ide/RunConfig.java | 10 +++++++--- .../configuration/ide/RunConfigSettings.java | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java b/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java index 1783e903a..233f00a3c 100644 --- a/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java +++ b/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java @@ -111,8 +111,11 @@ public Element addXml(Node parent, String name, Map values) { return e; } - private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String environment) { - runConfig.configName += extension.isRootProject() ? "" : " (" + project.getPath() + ")"; + private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String environment, boolean appendProjectPath) { + if (appendProjectPath && !extension.isRootProject()) { + runConfig.configName += " (" + project.getPath() + ")"; + } + runConfig.eclipseProjectName = project.getExtensions().getByType(EclipseModel.class).getProject().getName(); runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main"; @@ -167,9 +170,10 @@ public static RunConfig runConfig(Project project, RunConfigSettings settings) { runDir = "run"; } + boolean appendProjectPath = settings.getAppendProjectPathToConfigName(); RunConfig runConfig = new RunConfig(); runConfig.configName = configName; - populate(project, extension, runConfig, environment); + populate(project, extension, runConfig, environment, appendProjectPath); runConfig.ideaModuleName = IdeaUtils.getIdeaModuleName(new SourceSetReference(sourceSet, project)); runConfig.runDirIdeaUrl = "file://$PROJECT_DIR$/" + runDir; runConfig.runDir = runDir; diff --git a/src/main/java/net/fabricmc/loom/configuration/ide/RunConfigSettings.java b/src/main/java/net/fabricmc/loom/configuration/ide/RunConfigSettings.java index e7d3b39b8..151254ce5 100644 --- a/src/main/java/net/fabricmc/loom/configuration/ide/RunConfigSettings.java +++ b/src/main/java/net/fabricmc/loom/configuration/ide/RunConfigSettings.java @@ -67,9 +67,20 @@ public class RunConfigSettings implements Named { * The full name of the run configuration, i.e. 'Minecraft Client'. * *

By default this is determined from the base name. + * + *

Note: unless the project is the root project (or {@link #appendProjectPathToConfigName} is disabled), + * the project path will be appended automatically, e.g. 'Minecraft Client (:some:project)'. */ private String configName; + /** + * Whether to append the project path to the {@link #configName} when {@code project} isn't the root project. + * + *

Warning: could produce ambiguous run config names if disabled, unless used carefully in conjunction with + * {@link #configName}. + */ + private boolean appendProjectPathToConfigName; + /** * The default main class of the run configuration. * @@ -117,6 +128,7 @@ public class RunConfigSettings implements Named { public RunConfigSettings(Project project, String name) { this.name = name; this.project = project; + this.appendProjectPathToConfigName = true; this.extension = LoomGradleExtension.get(project); this.ideConfigGenerated = extension.isRootProject(); this.mainClass = project.getObjects().property(String.class).convention(project.provider(() -> { @@ -174,6 +186,14 @@ public void setConfigName(String name) { this.configName = name; } + public boolean getAppendProjectPathToConfigName() { + return appendProjectPathToConfigName; + } + + public void setAppendProjectPathToConfigName(boolean append) { + appendProjectPathToConfigName = append; + } + public String getDefaultMainClass() { return defaultMainClass; }