Skip to content

Commit

Permalink
Fix eclipse not loading due to referencing of projects across threads…
Browse files Browse the repository at this point in the history
… in its loading and parsing thread (#253)
  • Loading branch information
marchermans authored Nov 14, 2024
1 parent 7ba0e47 commit e8cbd63
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ public void eclipse(Project project, EclipseModel eclipse) {
.mode(LaunchGroup.Mode.DEBUG)
.action(LaunchGroup.Action.none()))
.build());
} catch (IllegalStateException e) {
final Thread currentThread = Thread.currentThread();
project.getLogger().error("Failed to write launch files: {}", runName, e);
project.getLogger().error("Thread: {} - {}", currentThread.getName(), currentThread.getId());
throw new GradleException("Failed to write launch files: " + runName + ". Current Thread: " + currentThread.getName(), e);
} catch (Exception e) {
throw new RuntimeException("Failed to write launch files: " + runName, e);
}
Expand Down Expand Up @@ -425,7 +430,7 @@ private List<TaskProvider<?>> createEclipseCopyResourcesTasks(Run run) {
eclipseResourcesTask = sourceSetProject.getTasks().register(taskName, Copy.class, task -> {
final TaskProvider<ProcessResources> defaultProcessResources = sourceSetProject.getTasks().named(sourceSet.getProcessResourcesTaskName(), ProcessResources.class);
task.from(defaultProcessResources.map(ProcessResources::getDestinationDir));
Path outputDir = sourceSetProject.getExtensions().getByType(IdeManagementExtension.class).getEclipseModel().getClasspath().getDefaultOutputDir().toPath();
Path outputDir = getEclipseOutputDirectory(sourceSetProject);
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
Expand All @@ -443,6 +448,19 @@ private List<TaskProvider<?>> createEclipseCopyResourcesTasks(Run run) {
return copyProcessResources;
}

private static @NotNull Path getEclipseOutputDirectory(Project sourceSetProject) {
if (sourceSetProject.getExtensions().findByType(IdeManagementExtension.class) == null) {
if (sourceSetProject.getExtensions().findByType(EclipseModel.class) == null) {
throw new IllegalStateException("EclipseModel not found in project: " + sourceSetProject);
}

return sourceSetProject.getExtensions().getByType(EclipseModel.class).getClasspath().getDefaultOutputDir().toPath();
}

return sourceSetProject.getExtensions().getByType(IdeManagementExtension.class).getEclipseModel().getClasspath().getDefaultOutputDir().toPath();
}


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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void doDownload() throws IOException {
if (outputRoot.exists() && outputRoot.isDirectory()) {
final File renderDocLibraryFile = getOSSpecificRenderDocLibraryFile(outputRoot);
if (renderDocLibraryFile.exists() && renderDocLibraryFile.isFile()) {
//setDidWork(false);
//return;
setDidWork(false);
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import net.neoforged.gradle.common.extensions.problems.IProblemReporter;
import net.neoforged.gradle.common.runs.run.RunImpl;
import net.neoforged.gradle.common.tasks.RenderDocDownloaderTask;
import net.neoforged.gradle.common.util.ClasspathUtils;
import net.neoforged.gradle.common.util.ConfigurationUtils;
import net.neoforged.gradle.common.util.SourceSetUtils;
import net.neoforged.gradle.common.util.VersionJson;
import net.neoforged.gradle.common.util.*;
import net.neoforged.gradle.dsl.common.extensions.subsystems.*;
import net.neoforged.gradle.dsl.common.extensions.subsystems.conventions.Runs;
import net.neoforged.gradle.dsl.common.extensions.subsystems.tools.RenderDocTools;
Expand Down Expand Up @@ -226,24 +223,16 @@ public static void setupRenderDocSupport(Project project, Run run) {

run.getDependsOn().add(setupRenderDoc);

Configuration renderNurse = null;
if (run.getModSources().getPrimary().isPresent()) {
renderNurse = addLocalRenderNurse(run.getModSources().getPrimary().get(), run);
}

if (renderNurse == null) {
//This happens when no primary source set is set, and the renderNurse configuration is not added to the runtime classpath.
renderNurse = registerRenderNurse(run.getProject());
}
//We need the renderNurse path resolved here, because eclipse resolves the run tasks in a place that is not compatible with late resolve of configurations
//Idea has no such issues, but the problem remains that if we don't get the actuall file and delay the configuration resolve untill import time, it will crash.
File renderNurse = ToolUtilities.resolveTool(project, renderDocTools.getRenderNurse()).get();

//Add the relevant properties, so that render nurse can be used, see its readme for the required values.
run.getEnvironmentVariables().put("LD_PRELOAD", setupRenderDoc.flatMap(RenderDocDownloaderTask::getRenderDocLibraryFile).map(RegularFile::getAsFile).map(File::getAbsolutePath));
run.getSystemProperties().put(
"neoforge.rendernurse.renderdoc.library", setupRenderDoc.flatMap(RenderDocDownloaderTask::getRenderDocLibraryFile).map(RegularFile::getAsFile).map(File::getAbsolutePath)
);
run.getJvmArguments().add(renderNurse.getIncoming().getArtifacts().getResolvedArtifacts()
.map(artifactView -> artifactView.iterator().next())
.map(resolvedArtifact -> "-javaagent:%s".formatted(resolvedArtifact.getFile().getAbsolutePath())));
run.getJvmArguments().add("-javaagent:%s".formatted(renderNurse.getAbsolutePath()));
run.getJvmArguments().add("--enable-preview");
run.getJvmArguments().add("--enable-native-access=ALL-UNNAMED");
}
Expand Down

0 comments on commit e8cbd63

Please sign in to comment.