Fix custom sourceset not being correctly set for runconfig tasks (#357)

dev/0.11
modmuss50 2021-03-03 21:22:10 +00:00 committed by GitHub
parent b7eba8b093
commit d02055eb23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 24 deletions

View File

@ -57,6 +57,7 @@ public class RunConfig {
public String runDir; public String runDir;
public String vmArgs; public String vmArgs;
public String programArgs; public String programArgs;
public SourceSet sourceSet;
public Element genRuns(Element doc) { public Element genRuns(Element doc) {
Element root = this.addXml(doc, "component", ImmutableMap.of("name", "ProjectRunConfigurationManager")); Element root = this.addXml(doc, "component", ImmutableMap.of("name", "ProjectRunConfigurationManager"));
@ -197,6 +198,7 @@ public class RunConfig {
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;
runConfig.sourceSet = sourceSet;
// Custom parameters // Custom parameters
for (String progArg : settings.getProgramArgs()) { for (String progArg : settings.getProgramArgs()) {

View File

@ -32,31 +32,23 @@ 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.configuration.ide.RunConfig; import net.fabricmc.loom.configuration.ide.RunConfig;
public abstract class AbstractRunTask extends JavaExec { public abstract class AbstractRunTask extends JavaExec {
private final Function<Project, RunConfig> configProvider; private final RunConfig config;
private RunConfig config;
public AbstractRunTask(Function<Project, RunConfig> config) { public AbstractRunTask(Function<Project, RunConfig> configProvider) {
super(); super();
setGroup("fabric"); setGroup("fabric");
this.configProvider = config; this.config = configProvider.apply(getProject());
setClasspath(getProject().getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)); setClasspath(config.sourceSet.getRuntimeClasspath());
classpath(this.getProject().getExtensions().getByType(LoomGradleExtension.class).getUnmappedModCollection());
} }
@Override @Override
public void exec() { public void exec() {
if (config == null) {
config = configProvider.apply(getProject());
}
List<String> argsSplit = new ArrayList<>(); List<String> argsSplit = new ArrayList<>();
String[] args = config.programArgs.split(" "); String[] args = config.programArgs.split(" ");
int partPos = -1; int partPos = -1;
@ -93,10 +85,6 @@ public abstract class AbstractRunTask extends JavaExec {
@Override @Override
public void setWorkingDir(File dir) { public void setWorkingDir(File dir) {
if (config == null) {
config = configProvider.apply(getProject());
}
if (!dir.exists()) { if (!dir.exists()) {
dir.mkdirs(); dir.mkdirs();
} }
@ -106,19 +94,11 @@ public abstract class AbstractRunTask extends JavaExec {
@Override @Override
public String getMain() { public String getMain() {
if (config == null) {
config = configProvider.apply(getProject());
}
return config.mainClass; return config.mainClass;
} }
@Override @Override
public List<String> getJvmArgs() { public List<String> getJvmArgs() {
if (config == null) {
config = configProvider.apply(getProject());
}
List<String> superArgs = super.getJvmArgs(); List<String> superArgs = super.getJvmArgs();
List<String> args = new ArrayList<>(superArgs != null ? superArgs : Collections.emptyList()); List<String> args = new ArrayList<>(superArgs != null ? superArgs : Collections.emptyList());
args.addAll(Arrays.asList(config.vmArgs.split(" "))); args.addAll(Arrays.asList(config.vmArgs.split(" ")));