Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Dec 1, 2024
1 parent f586cdd commit 13a0a6b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void addEclipseLaunchConfiguration(Project project,
RunUtils.escapeJvmArg(modFoldersProvider.getArgument())
)
.args(RunUtils.escapeJvmArg(RunUtils.getArgFileParameter(prepareTask.getProgramArgsFile().get())))
.envVar(RunUtils.replaceModClassesEnv(run, () -> modFoldersProvider))
.envVar(RunUtils.replaceModClassesEnv(run, modFoldersProvider))
.workingDirectory(run.getGameDirectory().get().getAsFile().getAbsolutePath())
.build(RunUtils.DEV_LAUNCH_MAIN_CLASS);
writeEclipseLaunchConfig(project, launchConfigName, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private static void addIntelliJRunConfiguration(Project project,
appRun.setModuleName(getIntellijModuleName(project, sourceSet));
appRun.setWorkingDirectory(run.getGameDirectory().get().getAsFile().getAbsolutePath());
var modFoldersProvider = getModFoldersProvider(project, outputDirectory, run.getLoadedMods(), null);
appRun.setEnvs(RunUtils.replaceModClassesEnv(run, () -> modFoldersProvider));
appRun.setEnvs(RunUtils.replaceModClassesEnv(run, modFoldersProvider));
appRun.setJvmArgs(
RunUtils.escapeJvmArg(RunUtils.getArgFileParameter(prepareTask.getVmArgsFile().get()))
+ " "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.gradle.api.Named;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.ConfigurablePublishArtifact;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ExternalModuleDependency;
Expand Down Expand Up @@ -212,7 +213,7 @@ public void apply(Project project) {
return split[2] + "-" + split[1];
})
.orElse(extension.getNeoFormArtifact().map(v -> "vanilla-" + v.split(":", 3)[2])),
// To support older versions of FML, that pick up the Minecraft jar by looking on the LCP for "forge-<version>",
// To support older versions of FML, which pick up the Minecraft jar by looking on the LCP for "forge-<version>",
// we have to ensure client-extra does *not* start with "forge-".
(dir, prefix) -> dir.file("client-extra-aka-minecraft-resources-" + prefix + ".jar")
));
Expand Down Expand Up @@ -503,6 +504,12 @@ static void setupRuns(Project project,
spec.getDependencies().add(project.getDependencyFactory().create(RunUtils.DEV_LAUNCH_GAV));
});

// Create an empty task similar to "assemble" which can be used to generate all launch scripts at once
var createLaunchScriptsTask= project.getTasks().register("createLaunchScripts", Task.class, task -> {
task.setGroup(branding.publicTaskGroup());
task.setDescription("Creates batch files/shell scripts to launch the game from outside of Gradle (i.e. Renderdoc, NVidia Nsight, etc.)");
});

Map<RunModel, TaskProvider<PrepareRun>> prepareRunTasks = new IdentityHashMap<>();
runs.all(run -> {
var prepareRunTask = setupRunInGradle(
Expand All @@ -515,7 +522,8 @@ static void setupRuns(Project project,
configureLegacyClasspath,
assetPropertiesFile,
devLaunchConfig,
neoFormVersion
neoFormVersion,
createLaunchScriptsTask
);
prepareRunTasks.put(run, prepareRunTask);
});
Expand All @@ -527,6 +535,7 @@ static void setupRuns(Project project,
* to a single file that is
* @param configureLegacyClasspath Callback to add entries to the legacy classpath.
* @param assetPropertiesFile File that contains the asset properties file produced by NFRT.
* @param createLaunchScriptsTask
*/
private static TaskProvider<PrepareRun> setupRunInGradle(
Project project,
Expand All @@ -538,8 +547,8 @@ private static TaskProvider<PrepareRun> setupRunInGradle(
Consumer<Configuration> configureLegacyClasspath, // TODO: can be removed in favor of directly passing a configuration for the moddev libraries
Provider<RegularFile> assetPropertiesFile,
Configuration devLaunchConfig,
Provider<String> neoFormVersion
) {
Provider<String> neoFormVersion,
TaskProvider<Task> createLaunchScriptsTask) {
var ideIntegration = IdeIntegration.of(project, branding);
var configurations = project.getConfigurations();
var javaExtension = ExtensionUtils.getExtension(project, "java", JavaPluginExtension.class);
Expand Down Expand Up @@ -611,7 +620,7 @@ private static TaskProvider<PrepareRun> setupRunInGradle(
});
ideIntegration.runTaskOnProjectSync(prepareRunTask);

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

Expand All @@ -624,6 +633,7 @@ private static TaskProvider<PrepareRun> setupRunInGradle(
task.getEnvironment().set(run.getEnvironment());
task.getModFolders().set(RunUtils.getGradleModFoldersProvider(project, run.getLoadedMods(), null));
});
createLaunchScriptsTask.configure(task -> task.dependsOn(launchScriptTask));

tasks.register(InternalModelHelper.nameOfRun(run, "run", ""), RunGameTask.class, task -> {
task.setGroup(branding.publicTaskGroup());
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/net/neoforged/moddevgradle/internal/RunUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,17 @@ public static Project findSourceSetProject(Project someProject, SourceSet source
throw new IllegalArgumentException("Could not find project for source set " + someProject);
}

public static Map<String, String> replaceModClassesEnv(RunModel model, Supplier<ModFoldersProvider> newProvider) {
/**
* In the run model, the environment variable "MOD_CLASSES" is set to the gradle output folders by the legacy plugin,
* since MDG itself completely ignores run-type specific environment variables.
* To ensure that in IDE runs, the IDE output folders are used, we replace the MOD_CLASSES environment variable
* explicitly.
*/
public static Map<String, String> replaceModClassesEnv(RunModel model, ModFoldersProvider modFoldersProvider) {
var vars = model.getEnvironment().get();
if (vars.containsKey("MOD_CLASSES")) {
final var copy = new HashMap<>(vars);
copy.put("MOD_CLASSES", newProvider.get().getClassesArgument().get());
copy.put("MOD_CLASSES", modFoldersProvider.getClassesArgument().get());
return copy;
}
return vars;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void addVscodeLaunchConfiguration(Project project,
.withArguments(List.of(RunUtils.getArgFileParameter(prepareTask.getProgramArgsFile().get())))
.withAdditionalJvmArgs(List.of(RunUtils.getArgFileParameter(prepareTask.getVmArgsFile().get()),
modFoldersProvider.getArgument()))
.withEnvironmentVariables(RunUtils.replaceModClassesEnv(run, () -> modFoldersProvider))
.withEnvironmentVariables(RunUtils.replaceModClassesEnv(run, modFoldersProvider))
.withMainClass(RunUtils.DEV_LAUNCH_MAIN_CLASS)
.withShortenCommandLine(ShortCmdBehaviour.NONE)
.withConsoleType(ConsoleType.INTERNAL_CONSOLE)
Expand Down

0 comments on commit 13a0a6b

Please sign in to comment.