Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two run fixes #68

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ public void idea(Project project, IdeaModel idea, ProjectSettings ideaExtension)
final RunConfigurationContainer ideaRuns = ((ExtensionAware) ideaExtension).getExtensions().getByType(RunConfigurationContainer.class);

project.getExtensions().configure(RunsConstants.Extensions.RUNS, (Action<NamedDomainObjectContainer<Run>>) runs -> runs.getAsMap().forEach((name, run) -> {
final String runName = StringUtils.capitalize(project.getName() + ": " + StringUtils.capitalize(name.replace(" ", "-")));
final String nameWithoutSpaces = name.replace(" ", "-");
final String runName = StringUtils.capitalize(project.getName() + ": " + StringUtils.capitalize(nameWithoutSpaces));

final RunImpl runImpl = (RunImpl) run;
final IdeaRunExtension runIdeaConfig = run.getExtensions().getByType(IdeaRunExtension.class);
final TaskProvider<?> ideBeforeRunTask = createIdeBeforeRunTask(project, name, run, runImpl);
final TaskProvider<?> ideBeforeRunTask = createIdeBeforeRunTask(project, nameWithoutSpaces, run, runImpl);

ideaRuns.register(runName, Application.class, ideaRun -> {
runImpl.getWorkingDirectory().get().getAsFile().mkdirs();
Expand Down Expand Up @@ -194,19 +195,7 @@ private static String quote(String arg) {

private TaskProvider<?> createIdeBeforeRunTask(Project project, String name, Run run, RunImpl runImpl) {
final TaskProvider<?> ideBeforeRunTask = project.getTasks().register(CommonRuntimeUtils.buildTaskName("ideBeforeRun", name), task -> {
for (SourceSet sourceSet : run.getModSources().get()) {
final Project sourceSetProject = SourceSetUtils.getProject(sourceSet);

//The following tasks are not guaranteed to be in the source sets build dependencies
//We however need at least the classes as well as the resources of the source set to be run
task.dependsOn(sourceSetProject.getTasks().named(sourceSet.getProcessResourcesTaskName()));
task.dependsOn(sourceSetProject.getTasks().named(sourceSet.getCompileJavaTaskName()));

//There might be additional tasks that are needed to configure and run a source set.
//Also run those
sourceSet.getOutput().getBuildDependencies().getDependencies(null)
.forEach(task::dependsOn);
}
RunsUtil.addRunSourcesDependenciesToTask(task, run);
});

if (!runImpl.getTaskDependencies().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.neoforged.gradle.dsl.common.runs.run.Run;
import net.neoforged.gradle.util.StringCapitalizationUtils;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.plugins.ExtensionAware;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Provider;
Expand Down Expand Up @@ -45,9 +46,7 @@ public static Run create(final Project project, final String name) {
});

project.afterEvaluate(evaluatedProject -> runTask.configure(task -> {
task.getRun().get().getModSources().get().stream().map(SourceSet::getClassesTaskName)
.map(classTaskName -> evaluatedProject.getTasks().named(classTaskName))
.forEach(task::dependsOn);
addRunSourcesDependenciesToTask(task, run);

run.getTaskDependencies().forEach(task::dependsOn);
}));
Expand All @@ -56,6 +55,22 @@ public static Run create(final Project project, final String name) {

return run;
}

public static void addRunSourcesDependenciesToTask(Task task, Run run) {
for (SourceSet sourceSet : run.getModSources().get()) {
final Project sourceSetProject = SourceSetUtils.getProject(sourceSet);

//The following tasks are not guaranteed to be in the source sets build dependencies
//We however need at least the classes as well as the resources of the source set to be run
task.dependsOn(sourceSetProject.getTasks().named(sourceSet.getProcessResourcesTaskName()));
task.dependsOn(sourceSetProject.getTasks().named(sourceSet.getCompileJavaTaskName()));

//There might be additional tasks that are needed to configure and run a source set.
//Also run those
sourceSet.getOutput().getBuildDependencies().getDependencies(null)
.forEach(task::dependsOn);
}
}

public static Provider<String> buildGradleModClasses(final ListProperty<SourceSet> sourceSetsProperty) {
return buildGradleModClasses(
Expand Down