From 98c5ca67c8707dd459d21739376a61cb4e285004 Mon Sep 17 00:00:00 2001 From: Nightenom <17338378+Nightenom@users.noreply.github.com> Date: Tue, 6 Feb 2024 12:02:07 +0100 Subject: [PATCH] Add sync tasks for eclipse resources (#108) * Add sync tasks for eclipse resources Update IdeRunIntegrationManager.java * Add comment to edge case * Add to debug task, not exactly correct, but should work ~= logically same as fg solution --- .gitignore | 1 + .../runs/ide/IdeRunIntegrationManager.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/.gitignore b/.gitignore index b6e6335b8..66ea833ed 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ repo .classpath .project bin +/.vscode/ # intellij out diff --git a/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java b/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java index 07a74d3ef..9921c45b6 100644 --- a/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java +++ b/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java @@ -22,8 +22,10 @@ import org.gradle.api.plugins.ExtensionAware; import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.Copy; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskProvider; +import org.gradle.language.jvm.tasks.ProcessResources; import org.gradle.plugins.ide.eclipse.model.EclipseModel; import org.gradle.plugins.ide.idea.model.IdeaModel; import org.gradle.plugins.ide.idea.model.IdeaProject; @@ -34,9 +36,11 @@ import java.io.FileWriter; import java.io.IOException; import java.io.UncheckedIOException; +import java.nio.file.Path; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -133,6 +137,7 @@ public void eclipse(Project project, EclipseModel eclipse) { final RunImpl runImpl = (RunImpl) run; final TaskProvider ideBeforeRunTask = createIdeBeforeRunTask(project, name, run, runImpl); + ideBeforeRunTask.configure(task -> addEclipseCopyResourcesTasks(eclipse, run, t -> task.dependsOn(t))); try { final GradleLaunchConfig idePreRunTask = GradleLaunchConfig.builder(eclipse.getProject().getName()) @@ -210,6 +215,37 @@ private TaskProvider createIdeBeforeRunTask(Project project, String name, Run return ideBeforeRunTask; } + private void addEclipseCopyResourcesTasks(EclipseModel eclipse, Run run, Consumer> tasksConsumer) { + for (SourceSet sourceSet : run.getModSources().get()) { + final Project sourceSetProject = SourceSetUtils.getProject(sourceSet); + + final String taskName = CommonRuntimeUtils.buildTaskName("eclipseCopy", sourceSet.getProcessResourcesTaskName()); + final TaskProvider eclipseResourcesTask; + + if (sourceSetProject.getTasks().findByName(taskName) != null) { + eclipseResourcesTask = sourceSetProject.getTasks().named(taskName); + } + else { + eclipseResourcesTask = sourceSetProject.getTasks().register(taskName, Copy.class, task -> { + final TaskProvider defaultProcessResources = sourceSetProject.getTasks().named(sourceSet.getProcessResourcesTaskName(), ProcessResources.class); + task.from(defaultProcessResources.get().getDestinationDir()); + Path outputDir = eclipse.getClasspath().getDefaultOutputDir().toPath(); + if (outputDir.endsWith("default")) { + // sometimes it has default value from org.gradle.plugins.ide.eclipse.internal.EclipsePluginConstants#DEFAULT_PROJECT_OUTPUT_PATH + // which has /default on end that is not present in the final outputDir in eclipse/buildship + // (output of getDefaultOutputDir() should be just project/bin/) + outputDir = outputDir.getParent(); + } + task.into(outputDir.resolve(sourceSet.getName())); + + task.dependsOn(defaultProcessResources); + }); + } + + tasksConsumer.accept(eclipseResourcesTask); + } + } + private static void writeLaunchToFile(Project project, String fileName, LaunchConfig config) { final File file = project.file(String.format(".eclipse/configurations/%s.launch", fileName)); file.getParentFile().mkdirs();