mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 13:37:45 -05:00
Add environment variable support for idea run configs
This commit is contained in:
@@ -30,6 +30,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -57,6 +58,7 @@ public class RunConfig {
|
||||
public String runDir;
|
||||
public String vmArgs;
|
||||
public String programArgs;
|
||||
public final Map<String, String> envVariables = new HashMap<>();
|
||||
|
||||
public Element genRuns(Element doc) {
|
||||
Element root = this.addXml(doc, "component", ImmutableMap.of("name", "ProjectRunConfigurationManager"));
|
||||
@@ -74,6 +76,14 @@ public class RunConfig {
|
||||
this.addXml(root, "option", ImmutableMap.of("name", "PROGRAM_PARAMETERS", "value", 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;
|
||||
}
|
||||
|
||||
@@ -193,6 +203,25 @@ public class RunConfig {
|
||||
dummyConfig = dummyConfig.replace("%PROGRAM_ARGS%", programArgs.replaceAll("\"", """));
|
||||
dummyConfig = dummyConfig.replace("%VM_ARGS%", 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);
|
||||
|
||||
return dummyConfig;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="%NAME%" type="Application" factoryName="Application">
|
||||
%ENVS%
|
||||
<option name="MAIN_CLASS_NAME" value="%MAIN_CLASS%" />
|
||||
<module name="%IDEA_MODULE%" />
|
||||
<option name="PROGRAM_PARAMETERS" value="%PROGRAM_ARGS%" />
|
||||
@@ -9,4 +10,4 @@
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
</component>
|
||||
|
||||
Reference in New Issue
Block a user