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.util.List;
import java.util.Map;
import java.util.Objects;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
@ -103,7 +104,7 @@ public class RunConfig {
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.eclipseProjectName = project.getExtensions().getByType(EclipseModel.class).getProject().getName();
runConfig.vmArgs = "";
@ -111,10 +112,10 @@ public class RunConfig {
if ("launchwrapper".equals(extension.getLoaderLaunchMethod())) {
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 {
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")) {
@ -122,7 +123,7 @@ public class RunConfig {
JsonObject installerJson = extension.getInstallerJson();
if (installerJson != null) {
List<String> sideKeys = ImmutableList.of(mode, "common");
List<String> sideKeys = ImmutableList.of(environment, "common");
// copy launchwrapper tweakers
if (installerJson.has("launchwrapper")) {
@ -162,7 +163,7 @@ public class RunConfig {
String name = settings.getName();
String configName = settings.getConfigName();
String mode = settings.getMode();
String environment = settings.getEnvironment();
SourceSet sourceSet = settings.getSource(project);
String defaultMain = settings.getDefaultMainClass();
@ -182,9 +183,7 @@ public class RunConfig {
configName += "Minecraft " + capitalizeCamelCaseName(name);
}
if (mode == null) {
mode = name;
}
Objects.requireNonNull(environment, "No environment set for run config");
String runDir = settings.getRunDir();
@ -194,7 +193,7 @@ public class RunConfig {
RunConfig runConfig = new RunConfig();
runConfig.configName = configName;
populate(project, extension, runConfig, mode);
populate(project, extension, runConfig, environment);
runConfig.ideaModuleName = getIdeaModuleName(project, sourceSet);
runConfig.runDirIdeaUrl = "file://$PROJECT_DIR$/" + runDir;
runConfig.runDir = runDir;
@ -208,7 +207,7 @@ public class RunConfig {
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
runConfig.programArgs = runConfig.programArgs.trim();

View File

@ -58,9 +58,9 @@ public final class RunConfigSettings implements Named {
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'.
@ -100,7 +100,6 @@ public final class RunConfigSettings implements Named {
this.project = project;
this.extension = project.getExtensions().getByType(LoomGradleExtension.class);
mode(baseName);
source("main");
runDir("run");
}
@ -126,12 +125,12 @@ public final class RunConfigSettings implements Named {
return programArgs;
}
public String getMode() {
return mode;
public String getEnvironment() {
return environment;
}
public void setMode(String mode) {
this.mode = mode;
public void setEnvironment(String environment) {
this.environment = environment;
}
public String getConfigName() {
@ -170,8 +169,8 @@ public final class RunConfigSettings implements Named {
this.source = sourceFn;
}
public void mode(String mode) {
setMode(mode);
public void environment(String environment) {
setEnvironment(environment);
}
public void name(String name) {
@ -255,7 +254,7 @@ public final class RunConfigSettings implements Named {
*/
public void client() {
startFirstThread();
mode("client");
environment("client");
defaultMainClass(Constants.Knot.KNOT_CLIENT);
}
@ -264,7 +263,7 @@ public final class RunConfigSettings implements Named {
*/
public void server() {
programArg("nogui");
mode("server");
environment("server");
defaultMainClass(Constants.Knot.KNOT_SERVER);
}
@ -275,7 +274,7 @@ public final class RunConfigSettings implements Named {
vmArgs.addAll(0, parent.vmArgs);
programArgs.addAll(0, parent.programArgs);
mode = parent.mode;
environment = parent.environment;
name = parent.name;
defaultMainClass = parent.defaultMainClass;
source = parent.source;

View File

@ -32,6 +32,7 @@ import java.util.List;
import java.util.function.Function;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.JavaExec;
import net.fabricmc.loom.LoomGradleExtension;
@ -46,7 +47,7 @@ public abstract class AbstractRunTask extends JavaExec {
setGroup("fabric");
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());
}

View File

@ -24,6 +24,7 @@
package net.fabricmc.loom.task;
import com.google.common.base.Preconditions;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskContainer;
@ -85,20 +86,24 @@ public final class LoomTasks {
private static void registerRunTasks(TaskContainer tasks, Project project) {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
extension.getRuns().create("client", RunConfigSettings::client);
extension.getRuns().create("server", RunConfigSettings::server);
Preconditions.checkArgument(extension.getRuns().size() == 0, "Run configurations must not be registered before loom");
project.afterEvaluate(p -> {
for (RunConfigSettings config : extension.getRuns()) {
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("server", RunConfigSettings::server);
}
private static void registerDecompileTasks(TaskContainer tasks, Project project) {