Skip to content

Commit 5758c05

Browse files
committed
Fix run config argument inheritance. Fixes #1015
1 parent ef7581e commit 5758c05

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ gradle-app.setting
7070
# Eclipse Gradle plugin generated files
7171
# Eclipse Core
7272
.project
73+
.settings
74+
.classpath
75+
bin/
7376
# JDT-specific (Eclipse Java Development Tools)
7477
.classpath
7578

src/main/java/net/minecraftforge/gradle/SlimeLauncherOptionsNested.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ public interface SlimeLauncherOptionsNested {
2424
/// @return A property for the main class
2525
@Input @Optional Property<String> getMainClass();
2626

27+
/// Wither or not to inherit arguments from the UserDev provided run configs.
28+
///
29+
/// If you set this to false you must specify all arguments to start the process manually.
30+
///
31+
/// @return A property controlling inheritance of arguments from UserDev config file.
32+
@Input @Optional Property<Boolean> getInheritArgs();
33+
2734
/// The arguments to pass to the main class.
2835
///
2936
/// This is the arguments that will be passed to the main class through Slime Launcher, **not** the arguments for
@@ -32,6 +39,13 @@ public interface SlimeLauncherOptionsNested {
3239
/// @return A property for the arguments to pass to the main class
3340
@Input @Optional ListProperty<String> getArgs();
3441

42+
/// Wither or not to inherit JVM arguments from the UserDev provided run configs.
43+
///
44+
/// If you set this to false you must specify all JVM arguments to start the process manually.
45+
///
46+
/// @return A property controlling inheritance of JVM arguments from UserDev config file.
47+
@Input @Optional Property<Boolean> getInheritJvmArgs();
48+
3549
/// The JVM arguments to use.
3650
///
3751
/// These are applied immediately when Slime Launcher is executed. A reminder that Slime Launcher is not a

src/main/java/net/minecraftforge/gradle/internal/SlimeLauncherOptionsImpl.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.gradle.api.provider.Property;
1717
import org.gradle.api.provider.Provider;
1818
import org.gradle.api.provider.ProviderFactory;
19-
2019
import javax.inject.Inject;
2120
import java.util.ArrayList;
2221
import java.util.HashMap;
@@ -27,7 +26,9 @@ public abstract class SlimeLauncherOptionsImpl implements SlimeLauncherOptionsIn
2726
private final String name;
2827

2928
private final Property<String> mainClass = this.getObjects().property(String.class);
29+
private final Property<Boolean> inheritArgs = this.getObjects().property(Boolean.class);
3030
private final ListProperty<String> args = this.getObjects().listProperty(String.class);
31+
private final Property<Boolean> inheritJvmArgs = this.getObjects().property(Boolean.class);
3132
private final ListProperty<String> jvmArgs = this.getObjects().listProperty(String.class);
3233
private final ConfigurableFileCollection classpath = this.getObjects().fileCollection();
3334
private final Property<String> minHeapSize = this.getObjects().property(String.class);
@@ -61,11 +62,21 @@ public Property<String> getMainClass() {
6162
return this.mainClass;
6263
}
6364

65+
@Override
66+
public Property<Boolean> getInheritArgs() {
67+
return this.inheritArgs;
68+
}
69+
6470
@Override
6571
public ListProperty<String> getArgs() {
6672
return this.args;
6773
}
6874

75+
@Override
76+
public Property<Boolean> getInheritJvmArgs() {
77+
return this.inheritJvmArgs;
78+
}
79+
6980
@Override
7081
public ListProperty<String> getJvmArgs() {
7182
return this.jvmArgs;
@@ -263,7 +274,9 @@ public void environment(Provider<? extends Map<String, ?>> properties) {
263274
public SlimeLauncherOptionsInternal inherit(Map<String, RunConfig> configs, String sourceSetName, String name) {
264275
var target = getObjects().newInstance(SlimeLauncherOptionsImpl.class, name);
265276
target.getMainClass().convention(this.getMainClass());
277+
target.getInheritArgs().convention(this.getInheritArgs());
266278
target.getArgs().convention(this.getArgs());
279+
target.getInheritJvmArgs().convention(this.getInheritJvmArgs());
267280
target.getJvmArgs().convention(this.getJvmArgs());
268281
target.getClasspath().convention(this.getClasspath());
269282
target.getMinHeapSize().convention(this.getMinHeapSize());
@@ -284,11 +297,21 @@ private SlimeLauncherOptionsInternal inherit(SlimeLauncherOptionsInternal target
284297
if (config.main != null)
285298
target.getMainClass().convention(config.main);
286299

287-
if (config.args != null && !config.args.isEmpty())
288-
target.getArgs().convention(List.copyOf(config.args));
300+
if (config.args != null && !config.args.isEmpty()) {
301+
if (target.getInheritArgs().getOrElse(Boolean.TRUE)) {
302+
var args = new ArrayList<>(config.args);
303+
args.addAll(target.getArgs().get());
304+
target.getArgs().convention(args);
305+
}
306+
}
289307

290-
if (config.jvmArgs != null && !config.jvmArgs.isEmpty())
291-
target.jvmArgs(config.jvmArgs);
308+
if (config.jvmArgs != null && !config.jvmArgs.isEmpty()) {
309+
if (target.getInheritJvmArgs().getOrElse(Boolean.TRUE)) {
310+
var args = new ArrayList<>(config.jvmArgs);
311+
args.addAll(target.getJvmArgs().get());
312+
target.getJvmArgs().convention(args);
313+
}
314+
}
292315

293316
target.getClient().convention(config.client);
294317

0 commit comments

Comments
 (0)