mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 13:37:45 -05:00
Merge with Fabric 0.13, stage 4
This commit is contained in:
@@ -30,13 +30,14 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -64,7 +65,6 @@ public class RunConfig {
|
||||
public String configName;
|
||||
public String eclipseProjectName;
|
||||
public String ideaModuleName;
|
||||
public String vscodeProjectName;
|
||||
public String mainClass;
|
||||
public String runDirIdeaUrl;
|
||||
public String runDir;
|
||||
@@ -72,8 +72,9 @@ public class RunConfig {
|
||||
public List<String> vmArgs = new ArrayList<>();
|
||||
public List<String> programArgs = new ArrayList<>();
|
||||
public List<String> vscodeBeforeRun = new ArrayList<>();
|
||||
public final Map<String, String> envVariables = new HashMap<>();
|
||||
public SourceSet sourceSet;
|
||||
public Map<String, Object> environmentVariables;
|
||||
public String projectName;
|
||||
|
||||
public Element genRuns(Element doc) {
|
||||
Element root = this.addXml(doc, "component", ImmutableMap.of("name", "ProjectRunConfigurationManager"));
|
||||
@@ -91,14 +92,6 @@ public class RunConfig {
|
||||
this.addXml(root, "option", ImmutableMap.of("name", "PROGRAM_PARAMETERS", "value", joinArguments(programArgs)));
|
||||
}
|
||||
|
||||
if (!envVariables.isEmpty()) {
|
||||
Element envs = this.addXml(root, "envs", ImmutableMap.of());
|
||||
|
||||
for (Map.Entry<String, String> envEntry : envVariables.entrySet()) {
|
||||
this.addXml(envs, "env", ImmutableMap.of("name", envEntry.getKey(), "value", envEntry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -122,7 +115,6 @@ public class RunConfig {
|
||||
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.vscodeProjectName = extension.isRootProject() ? "" : StringUtils.removePrefix(project.getPath(), ":");
|
||||
|
||||
runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main";
|
||||
runConfig.vmArgs.add("-Dfabric.dli.config=" + encodeEscaped(extension.getFiles().getDevLauncherConfig().getAbsolutePath()));
|
||||
@@ -178,7 +170,6 @@ public class RunConfig {
|
||||
}
|
||||
|
||||
RunConfig runConfig = new RunConfig();
|
||||
runConfig.envVariables.putAll(settings.envVariables);
|
||||
runConfig.configName = configName;
|
||||
populate(project, extension, runConfig, environment);
|
||||
runConfig.ideaModuleName = IdeaUtils.getIdeaModuleName(new SourceSetReference(sourceSet, project));
|
||||
@@ -191,6 +182,9 @@ public class RunConfig {
|
||||
runConfig.programArgs.addAll(settings.getProgramArgs());
|
||||
runConfig.vmArgs.addAll(settings.getVmArgs());
|
||||
runConfig.vmArgs.add("-Dfabric.dli.main=" + getMainClass(environment, extension, defaultMain));
|
||||
runConfig.environmentVariables = new HashMap<>();
|
||||
runConfig.environmentVariables.putAll(settings.getEnvironmentVariables());
|
||||
runConfig.projectName = project.getName();
|
||||
|
||||
for (Consumer<RunConfig> consumer : extension.getSettingsPostEdit()) {
|
||||
consumer.accept(runConfig);
|
||||
@@ -223,29 +217,19 @@ public class RunConfig {
|
||||
dummyConfig = dummyConfig.replace("%RUN_DIRECTORY%", runDir);
|
||||
dummyConfig = dummyConfig.replace("%PROGRAM_ARGS%", joinArguments(programArgs).replaceAll("\"", """));
|
||||
dummyConfig = dummyConfig.replace("%VM_ARGS%", joinArguments(vmArgs).replaceAll("\"", """));
|
||||
|
||||
String envs = "";
|
||||
|
||||
if (!envVariables.isEmpty()) {
|
||||
StringBuilder builder = new StringBuilder("<envs>");
|
||||
|
||||
for (Map.Entry<String, String> env : envVariables.entrySet()) {
|
||||
builder.append("<env name=\"");
|
||||
builder.append(env.getKey().replaceAll("\"", """));
|
||||
builder.append("\" value=\"");
|
||||
builder.append(env.getValue().replaceAll("\"", """));
|
||||
builder.append("\"/>");
|
||||
}
|
||||
|
||||
builder.append("</envs>");
|
||||
envs = builder.toString();
|
||||
}
|
||||
|
||||
dummyConfig = dummyConfig.replace("%ENVS%", envs);
|
||||
dummyConfig = dummyConfig.replace("%IDEA_ENV_VARS%", getEnvVars("<env name=\"%s\" value=\"%s\"/>"));
|
||||
dummyConfig = dummyConfig.replace("%ECLIPSE_ENV_VARS%", getEnvVars("<mapEntry key=\"%s\" value=\"%s\"/>"));
|
||||
|
||||
return dummyConfig;
|
||||
}
|
||||
|
||||
private String getEnvVars(String pattern) {
|
||||
return environmentVariables.entrySet().stream()
|
||||
.map(entry ->
|
||||
pattern.formatted(entry.getKey(), entry.getValue().toString())
|
||||
).collect(Collectors.joining());
|
||||
}
|
||||
|
||||
public static String joinArguments(List<String> args) {
|
||||
final var sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
|
||||
@@ -97,6 +97,8 @@ public final class RunConfigSettings implements Named {
|
||||
*/
|
||||
private boolean ideConfigGenerated;
|
||||
|
||||
private final Map<String, Object> environmentVariables = new HashMap<>();
|
||||
|
||||
private final Project project;
|
||||
private final LoomGradleExtension extension;
|
||||
public final Map<String, String> envVariables = new HashMap<>();
|
||||
@@ -259,6 +261,14 @@ public final class RunConfigSettings implements Named {
|
||||
this.ideConfigGenerated = ideConfigGenerated;
|
||||
}
|
||||
|
||||
public Map<String, Object> getEnvironmentVariables() {
|
||||
return environmentVariables;
|
||||
}
|
||||
|
||||
public void environmentVariable(String name, Object value) {
|
||||
environmentVariables.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the {@code -XstartOnFirstThread} JVM argument when on OSX.
|
||||
*/
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class AbstractRunTask extends JavaExec {
|
||||
@Override
|
||||
public void exec() {
|
||||
setWorkingDir(new File(getProject().getProjectDir(), config.runDir));
|
||||
environment(config.envVariables);
|
||||
environment(config.environmentVariables);
|
||||
|
||||
super.exec();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -187,10 +188,10 @@ public class GenVsCodeProjectTask extends AbstractLoomTask {
|
||||
public String mainClass;
|
||||
public String vmArgs;
|
||||
public String args;
|
||||
public Map<String, String> env = new LinkedHashMap<>();
|
||||
public Map<String, Object> env;
|
||||
public String projectName;
|
||||
public transient List<String> tasksBeforeRun = new ArrayList<>();
|
||||
public String preLaunchTask = null;
|
||||
public String projectName = null;
|
||||
|
||||
VsCodeConfiguration(Project project, RunConfig runConfig) {
|
||||
this.name = runConfig.configName;
|
||||
@@ -198,8 +199,8 @@ public class GenVsCodeProjectTask extends AbstractLoomTask {
|
||||
this.vmArgs = RunConfig.joinArguments(runConfig.vmArgs);
|
||||
this.args = RunConfig.joinArguments(runConfig.programArgs);
|
||||
this.cwd = "${workspaceFolder}/" + runConfig.runDir;
|
||||
this.projectName = runConfig.vscodeProjectName;
|
||||
this.env.putAll(runConfig.envVariables);
|
||||
this.env = new HashMap<>(runConfig.environmentVariables);
|
||||
this.projectName = runConfig.projectName;
|
||||
this.tasksBeforeRun.addAll(runConfig.vscodeBeforeRun);
|
||||
|
||||
if (project.getRootProject() != project) {
|
||||
|
||||
Reference in New Issue
Block a user