Skip to content

Commit 7049571

Browse files
authored
Support adding run configs in folders (#318)
1 parent d698cef commit 7049571

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/main/java/net/neoforged/moddevgradle/dsl/RunModel.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public RunModel(String name, Project project, Iterable<ModModel> defaultMods) {
6565
ideName = project.getName() + " - " + ideName;
6666
}
6767
getIdeName().convention(ideName);
68+
getIdeFolderName().convention("");
6869

6970
getSourceSet().convention(ExtensionUtils.getSourceSets(project).getByName(SourceSet.MAIN_SOURCE_SET_NAME));
7071
}
@@ -80,6 +81,12 @@ public String getName() {
8081
*/
8182
public abstract Property<String> getIdeName();
8283

84+
/**
85+
* Name for the folder the run configuration is contained by in the IDE.
86+
* If this is set to {@code ""}, no folder will be used.
87+
*/
88+
public abstract Property<String> getIdeFolderName();
89+
8390
/**
8491
* Directory that the game will run in. Defaults to {@code run/}.
8592
*/

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.IOException;
55
import java.nio.file.Files;
66
import java.util.ArrayList;
7+
import java.util.HashMap;
78
import java.util.List;
89
import java.util.Map;
910
import java.util.Set;
@@ -175,7 +176,7 @@ private static void addIntelliJRunConfiguration(Project project,
175176
@Nullable Function<Project, File> outputDirectory,
176177
RunModel run,
177178
PrepareRun prepareTask) {
178-
var appRun = new Application(run.getIdeName().get(), project);
179+
var appRun = new ExtendedApplication(run.getIdeName().get(), project, getExtraIntelijRunProperties(run));
179180
var sourceSets = ExtensionUtils.getSourceSets(project);
180181
var sourceSet = run.getSourceSet().get();
181182
// Validate that the source set is part of this project
@@ -269,4 +270,29 @@ private static String getIntellijModuleName(Project project, SourceSet sourceSet
269270
moduleName.append(sourceSet.getName());
270271
return moduleName.toString();
271272
}
273+
274+
private static Map<String, Object> getExtraIntelijRunProperties(RunModel run) {
275+
var extraProperties = new HashMap<String, Object>();
276+
if (!run.getIdeFolderName().get().isEmpty()) {
277+
extraProperties.put("folderName", run.getIdeFolderName().get());
278+
}
279+
return extraProperties;
280+
}
281+
282+
private static class ExtendedApplication extends Application {
283+
private final Map<String, Object> extraProperties;
284+
285+
public ExtendedApplication(String name, Project project, Map<String, Object> extraProperties) {
286+
super(name, project);
287+
this.extraProperties = extraProperties;
288+
}
289+
290+
@Override
291+
public Map<String, ?> toMap() {
292+
@SuppressWarnings("unchecked")
293+
var m = (Map<String, Object>) super.toMap();
294+
m.putAll(extraProperties);
295+
return m;
296+
}
297+
}
272298
}

testproject/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ neoForge {
5656
client()
5757
programArguments.addAll('--username', 'Dev2')
5858
}
59+
folderedClient {
60+
client()
61+
ideFolderName = "Neo Test Folder"
62+
}
5963
clientAuth {
6064
client()
6165
devLogin = true

0 commit comments

Comments
 (0)