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

Fix synchronisation for Eclipse/VSCode #174

Merged
merged 1 commit into from
Oct 14, 2024
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 @@ -44,6 +44,9 @@ protected EclipseIntegration(Project project) {
super(project);
this.eclipseModel = getOrCreateEclipseModel(project);
LOG.debug("Configuring Eclipse model for Eclipse project '{}'.", eclipseModel.getProject().getName());

// Make sure our post-sync task runs on Eclipse project reload
eclipseModel.synchronizationTasks(ideSyncTask);
}

/**
Expand All @@ -70,12 +73,6 @@ public void attachSources(Map<Provider<RegularFile>, Provider<RegularFile>> jarT
});
}

@Override
protected void registerProjectSyncTask(TaskProvider<?> task) {
// Make sure our post-sync task runs on Eclipse
eclipseModel.synchronizationTasks(task);
}

@Override
public void configureRuns(Map<RunModel, TaskProvider<PrepareRun>> prepareRunTasks,
Iterable<RunModel> runs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
import java.io.File;
import java.util.Map;

/**
* Implementing classes are responsible for registering {@code ideSyncTask} with their IDE.
*/
sealed abstract class IdeIntegration permits IntelliJIntegration, EclipseIntegration, NoIdeIntegration {
private static final Logger LOG = LoggerFactory.getLogger(IdeIntegration.class);

/**
* A task we attach other tasks to that should run when the IDE reloads the projects.
*/
private final TaskProvider<Task> ideSyncTask;
protected final TaskProvider<Task> ideSyncTask;

protected final Project project;

Expand All @@ -34,7 +37,6 @@ public IdeIntegration(Project project) {
task.setGroup(ModDevPlugin.INTERNAL_TASK_GROUP);
task.setDescription("A utility task that is used to create necessary files when the Gradle project is synchronized with the IDE project.");
});
this.registerProjectSyncTask(ideSyncTask);
}

public static IdeIntegration of(Project project) {
Expand Down Expand Up @@ -90,14 +92,6 @@ public final void runTaskOnProjectSync(TaskProvider<?> task) {
ideSyncTask.configure(ideSyncTask -> ideSyncTask.dependsOn(task));
}

/**
* To be implemented by specific IDE integrations to register a task to be run on reload with the IDE.
* Internally, a dummy task is registered with Gradle. All tasks that should run on project sync are then
* added as dependencies to that task using {@link #runTaskOnProjectSync}. This method is used to register
* the dummy task with the IDE itself.
*/
protected abstract void registerProjectSyncTask(TaskProvider<?> task);

void configureRuns(Map<RunModel, TaskProvider<PrepareRun>> prepareRunTasks, Iterable<RunModel> runs) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.gradle.api.Project;
import org.gradle.api.file.Directory;
import org.gradle.api.file.RegularFile;
import org.gradle.api.logging.Logging;
import org.gradle.api.plugins.ExtensionAware;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
Expand Down Expand Up @@ -63,6 +62,19 @@ final class IntelliJIntegration extends IdeIntegration {
if (!rootProject.getPlugins().hasPlugin(IdeaExtPlugin.class)) {
rootProject.getPlugins().apply(IdeaExtPlugin.class);
}

// Since this does not just configure a data model but actually runs an additional task, we only do this
// when IntelliJ is actually reloading the Gradle project right now.
if (IdeDetection.isIntelliJSync()) {
project.afterEvaluate(ignored -> {
// Also run the sync task directly as part of the sync. (Thanks Loom).
var startParameter = project.getGradle().getStartParameter();
var taskRequests = new ArrayList<>(startParameter.getTaskRequests());

taskRequests.add(new DefaultTaskExecutionRequest(List.of(ideSyncTask.getName())));
startParameter.setTaskRequests(taskRequests);
});
}
}

@Override
Expand Down Expand Up @@ -95,25 +107,6 @@ public void configureRuns(Map<RunModel, TaskProvider<PrepareRun>> prepareRunTask
});
}

@Override
protected void registerProjectSyncTask(TaskProvider<?> task) {
// Since this does not just configure a data model but actually runs an additional task, we only do this
// when IntelliJ is actually reloading the Gradle project right now.
if (!IdeDetection.isIntelliJSync()) {
return;
}

project.afterEvaluate(ignored -> {
// Also run the sync task directly as part of the sync. (Thanks Loom).
var startParameter = project.getGradle().getStartParameter();
var taskRequests = new ArrayList<>(startParameter.getTaskRequests());

taskRequests.add(new DefaultTaskExecutionRequest(List.of(task.getName())));
startParameter.setTaskRequests(taskRequests);

});
}

@Override
public void configureTesting(SetProperty<ModModel> loadedMods,
Property<ModModel> testedMod,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.neoforged.moddevgradle.internal;

import org.gradle.api.Project;
import org.gradle.api.tasks.TaskProvider;

/**
* This implementation of {@link IdeIntegration} is used when no IDE was detected to host Gradle.
Expand All @@ -10,9 +9,4 @@ final class NoIdeIntegration extends IdeIntegration {
public NoIdeIntegration(Project project) {
super(project);
}

@Override
protected void registerProjectSyncTask(TaskProvider<?> task) {
// No IDE
}
}
1 change: 0 additions & 1 deletion testproject/jijtest/src/test/java/jijtest/CoreModTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class CoreModTest {
Expand Down