Skip to content

Commit

Permalink
Allow disabling RunConfig appending project path
Browse files Browse the repository at this point in the history
Add a `appendConfigNameWithPath` property to `RunConfigSettings` controlling whether to append the path for non-root projects.

Default behaviour is unchanged.
  • Loading branch information
MattSturgeon committed Dec 16, 2023
1 parent d9a436c commit 509266c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ public Element addXml(Node parent, String name, Map<String, String> 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";
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,20 @@ public class RunConfigSettings implements Named {
* The full name of the run configuration, i.e. 'Minecraft Client'.
*
* <p>By default this is determined from the base name.
*
* <p>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.
*
* <p>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.
*
Expand Down Expand Up @@ -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(() -> {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 509266c

Please sign in to comment.