Rename mode -> environment + Hopefully fix a regression with the run tasks

dev/0.11
modmuss50 2021-01-31 00:09:40 +00:00
parent 6a315be278
commit 5b3222e9b9
4 changed files with 39 additions and 35 deletions

View File

@ -29,6 +29,7 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -103,7 +104,7 @@ public class RunConfig {
return module; return module;
} }
private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String mode) { private static void populate(Project project, LoomGradleExtension extension, RunConfig runConfig, String environment) {
runConfig.configName += extension.isRootProject() ? "" : " (" + project.getPath() + ")"; runConfig.configName += extension.isRootProject() ? "" : " (" + project.getPath() + ")";
runConfig.eclipseProjectName = project.getExtensions().getByType(EclipseModel.class).getProject().getName(); runConfig.eclipseProjectName = project.getExtensions().getByType(EclipseModel.class).getProject().getName();
runConfig.vmArgs = ""; runConfig.vmArgs = "";
@ -111,10 +112,10 @@ public class RunConfig {
if ("launchwrapper".equals(extension.getLoaderLaunchMethod())) { if ("launchwrapper".equals(extension.getLoaderLaunchMethod())) {
runConfig.mainClass = "net.minecraft.launchwrapper.Launch"; // TODO What about custom tweakers for run configs? runConfig.mainClass = "net.minecraft.launchwrapper.Launch"; // TODO What about custom tweakers for run configs?
runConfig.programArgs += "--tweakClass " + ("client".equals(mode) ? Constants.LaunchWrapper.DEFAULT_FABRIC_CLIENT_TWEAKER : Constants.LaunchWrapper.DEFAULT_FABRIC_SERVER_TWEAKER); runConfig.programArgs += "--tweakClass " + ("client".equals(environment) ? Constants.LaunchWrapper.DEFAULT_FABRIC_CLIENT_TWEAKER : Constants.LaunchWrapper.DEFAULT_FABRIC_SERVER_TWEAKER);
} else { } else {
runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main"; runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main";
runConfig.vmArgs = "-Dfabric.dli.config=" + encodeEscaped(extension.getDevLauncherConfig().getAbsolutePath()) + " -Dfabric.dli.env=" + mode.toLowerCase(); runConfig.vmArgs = "-Dfabric.dli.config=" + encodeEscaped(extension.getDevLauncherConfig().getAbsolutePath()) + " -Dfabric.dli.env=" + environment.toLowerCase();
} }
if (extension.getLoaderLaunchMethod().equals("launchwrapper")) { if (extension.getLoaderLaunchMethod().equals("launchwrapper")) {
@ -122,7 +123,7 @@ public class RunConfig {
JsonObject installerJson = extension.getInstallerJson(); JsonObject installerJson = extension.getInstallerJson();
if (installerJson != null) { if (installerJson != null) {
List<String> sideKeys = ImmutableList.of(mode, "common"); List<String> sideKeys = ImmutableList.of(environment, "common");
// copy launchwrapper tweakers // copy launchwrapper tweakers
if (installerJson.has("launchwrapper")) { if (installerJson.has("launchwrapper")) {
@ -162,7 +163,7 @@ public class RunConfig {
String name = settings.getName(); String name = settings.getName();
String configName = settings.getConfigName(); String configName = settings.getConfigName();
String mode = settings.getMode(); String environment = settings.getEnvironment();
SourceSet sourceSet = settings.getSource(project); SourceSet sourceSet = settings.getSource(project);
String defaultMain = settings.getDefaultMainClass(); String defaultMain = settings.getDefaultMainClass();
@ -182,9 +183,7 @@ public class RunConfig {
configName += "Minecraft " + capitalizeCamelCaseName(name); configName += "Minecraft " + capitalizeCamelCaseName(name);
} }
if (mode == null) { Objects.requireNonNull(environment, "No environment set for run config");
mode = name;
}
String runDir = settings.getRunDir(); String runDir = settings.getRunDir();
@ -194,7 +193,7 @@ public class RunConfig {
RunConfig runConfig = new RunConfig(); RunConfig runConfig = new RunConfig();
runConfig.configName = configName; runConfig.configName = configName;
populate(project, extension, runConfig, mode); populate(project, extension, runConfig, environment);
runConfig.ideaModuleName = getIdeaModuleName(project, sourceSet); runConfig.ideaModuleName = getIdeaModuleName(project, sourceSet);
runConfig.runDirIdeaUrl = "file://$PROJECT_DIR$/" + runDir; runConfig.runDirIdeaUrl = "file://$PROJECT_DIR$/" + runDir;
runConfig.runDir = runDir; runConfig.runDir = runDir;
@ -208,7 +207,7 @@ public class RunConfig {
runConfig.vmArgs += " " + vmArg; runConfig.vmArgs += " " + vmArg;
} }
runConfig.vmArgs += " -Dfabric.dli.main=" + getMainClass(mode, extension, defaultMain); runConfig.vmArgs += " -Dfabric.dli.main=" + getMainClass(environment, extension, defaultMain);
// Remove unnecessary leading/trailing whitespaces we might have generated // Remove unnecessary leading/trailing whitespaces we might have generated
runConfig.programArgs = runConfig.programArgs.trim(); runConfig.programArgs = runConfig.programArgs.trim();

View File

@ -58,9 +58,9 @@ public final class RunConfigSettings implements Named {
private final List<String> programArgs = new ArrayList<>(); private final List<String> programArgs = new ArrayList<>();
/** /**
* The mode to run, which is the name of the run config in {@code fabric_installer.[method].json}. * The environment (or side) to run, usually client or server.
*/ */
private String mode; private String environment;
/** /**
* The full name of the run configuration, i.e. 'Minecraft Client'. * The full name of the run configuration, i.e. 'Minecraft Client'.
@ -100,7 +100,6 @@ public final class RunConfigSettings implements Named {
this.project = project; this.project = project;
this.extension = project.getExtensions().getByType(LoomGradleExtension.class); this.extension = project.getExtensions().getByType(LoomGradleExtension.class);
mode(baseName);
source("main"); source("main");
runDir("run"); runDir("run");
} }
@ -126,12 +125,12 @@ public final class RunConfigSettings implements Named {
return programArgs; return programArgs;
} }
public String getMode() { public String getEnvironment() {
return mode; return environment;
} }
public void setMode(String mode) { public void setEnvironment(String environment) {
this.mode = mode; this.environment = environment;
} }
public String getConfigName() { public String getConfigName() {
@ -170,8 +169,8 @@ public final class RunConfigSettings implements Named {
this.source = sourceFn; this.source = sourceFn;
} }
public void mode(String mode) { public void environment(String environment) {
setMode(mode); setEnvironment(environment);
} }
public void name(String name) { public void name(String name) {
@ -255,7 +254,7 @@ public final class RunConfigSettings implements Named {
*/ */
public void client() { public void client() {
startFirstThread(); startFirstThread();
mode("client"); environment("client");
defaultMainClass(Constants.Knot.KNOT_CLIENT); defaultMainClass(Constants.Knot.KNOT_CLIENT);
} }
@ -264,7 +263,7 @@ public final class RunConfigSettings implements Named {
*/ */
public void server() { public void server() {
programArg("nogui"); programArg("nogui");
mode("server"); environment("server");
defaultMainClass(Constants.Knot.KNOT_SERVER); defaultMainClass(Constants.Knot.KNOT_SERVER);
} }
@ -275,7 +274,7 @@ public final class RunConfigSettings implements Named {
vmArgs.addAll(0, parent.vmArgs); vmArgs.addAll(0, parent.vmArgs);
programArgs.addAll(0, parent.programArgs); programArgs.addAll(0, parent.programArgs);
mode = parent.mode; environment = parent.environment;
name = parent.name; name = parent.name;
defaultMainClass = parent.defaultMainClass; defaultMainClass = parent.defaultMainClass;
source = parent.source; source = parent.source;

View File

@ -32,6 +32,7 @@ import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.JavaExec; import org.gradle.api.tasks.JavaExec;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
@ -46,7 +47,7 @@ public abstract class AbstractRunTask extends JavaExec {
setGroup("fabric"); setGroup("fabric");
this.configProvider = config; this.configProvider = config;
classpath(getProject().getConfigurations().getByName("runtimeClasspath")); setClasspath(getProject().getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
classpath(this.getProject().getExtensions().getByType(LoomGradleExtension.class).getUnmappedModCollection()); classpath(this.getProject().getExtensions().getByType(LoomGradleExtension.class).getUnmappedModCollection());
} }

View File

@ -24,6 +24,7 @@
package net.fabricmc.loom.task; package net.fabricmc.loom.task;
import com.google.common.base.Preconditions;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.TaskContainer;
@ -85,20 +86,24 @@ public final class LoomTasks {
private static void registerRunTasks(TaskContainer tasks, Project project) { private static void registerRunTasks(TaskContainer tasks, Project project) {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
Preconditions.checkArgument(extension.getRuns().size() == 0, "Run configurations must not be registered before loom");
extension.getRuns().whenObjectAdded(config -> {
String configName = config.getName();
String taskName = "run" + configName.substring(0, 1).toUpperCase() + configName.substring(1);
tasks.register(taskName, RunGameTask.class, config).configure(t -> {
t.setDescription("Starts the '" + config.getConfigName() + "' run configuration");
t.setGroup("fabric");
if (config.getEnvironment().equals("client")) {
t.dependsOn("downloadAssets");
}
});
});
extension.getRuns().create("client", RunConfigSettings::client); extension.getRuns().create("client", RunConfigSettings::client);
extension.getRuns().create("server", RunConfigSettings::server); extension.getRuns().create("server", RunConfigSettings::server);
project.afterEvaluate(p -> {
for (RunConfigSettings config : extension.getRuns()) {
String configName = config.getName();
String taskName = "run" + configName.substring(0, 1).toUpperCase() + configName.substring(1);
tasks.register(taskName, RunGameTask.class, config).configure(t -> {
t.setDescription("Starts the '" + config.getConfigName() + "' run configuration");
t.setGroup("fabric");
});
}
});
} }
private static void registerDecompileTasks(TaskContainer tasks, Project project) { private static void registerDecompileTasks(TaskContainer tasks, Project project) {