Skip to content

Commit

Permalink
Fix first integration test that failed because of a difference with h…
Browse files Browse the repository at this point in the history
…ow Ingredients are constructed.
  • Loading branch information
marchermans committed Nov 2, 2024
1 parent e6f6b78 commit 65b70de
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import org.gradle.plugins.ide.idea.model.IdeaModel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.gradle.ext.IdeaExtPlugin;
import org.jetbrains.gradle.ext.ProjectSettings;
import org.jetbrains.gradle.ext.TaskTriggersConfig;
Expand Down Expand Up @@ -261,22 +262,30 @@ private void onCommonEclipse(final BiConsumer<Project, EclipseModel> toPerform)
if (!isEclipseImport()) {
return;
}

//Grab the eclipse model so we can extend it. -> Done on the root project so that the model is available to all subprojects.
//And so that post sync tasks are only ran once for all subprojects.
EclipseModel model = project.getExtensions().findByType(EclipseModel.class);
if (model == null) {
model = rootProject.getExtensions().findByType(EclipseModel.class);
if (model == null) {
return;
}
}


EclipseModel model = getEclipseModel();
if (model == null) return;

//Configure the project, passing the model and the relevant project. Which does not need to be the root, but can be.
toPerform.accept(project, model);
});
}


/**
* Get the eclipse model from the extensions project.
*
* @return the eclipse model, or {@code null} if not found
*/
public @Nullable EclipseModel getEclipseModel() {
//Grab the eclipse model so we can extend it. -> Done on the root project so that the model is available to all subprojects.
//And so that post sync tasks are only ran once for all subprojects.
EclipseModel model = project.getExtensions().findByType(EclipseModel.class);
if (model == null) {
model = project.getRootProject().getExtensions().findByType(EclipseModel.class);
}
return model;
}

/**
* Applies the specified configuration action to configure gradle run projects only.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void eclipse(Project project, EclipseModel eclipse) {
return;

final TaskProvider<?> ideBeforeRunTask = getOrCreateIdeBeforeRunTask(project, runImpl);
final List<TaskProvider<?>> copyProcessResourcesTasks = createEclipseCopyResourcesTasks(eclipse, run);
final List<TaskProvider<?>> copyProcessResourcesTasks = createEclipseCopyResourcesTasks(run);
ideBeforeRunTask.configure(task -> copyProcessResourcesTasks.forEach(task::dependsOn));

try {
Expand Down Expand Up @@ -327,7 +327,7 @@ public void vscode(Project project, EclipseModel eclipse)
final RunImpl runImpl = (RunImpl) run;
final TaskProvider<?> ideBeforeRunTask = getOrCreateIdeBeforeRunTask(project, runImpl);

final List<TaskProvider<?>> copyProcessResourcesTasks = createEclipseCopyResourcesTasks(eclipse, run);
final List<TaskProvider<?>> copyProcessResourcesTasks = createEclipseCopyResourcesTasks(run);
ideBeforeRunTask.configure(task -> copyProcessResourcesTasks.forEach(task::dependsOn));

final LaunchConfiguration cfg = launchWriter.createGroup("NG - " + project.getName(), WritingMode.REMOVE_EXISTING)
Expand Down Expand Up @@ -410,7 +410,7 @@ private List<TaskProvider<?>> createIntelliJCopyResourcesTasks(Run run) {
return intelliJResourcesTask;
}

private List<TaskProvider<?>> createEclipseCopyResourcesTasks(EclipseModel eclipse, Run run) {
private List<TaskProvider<?>> createEclipseCopyResourcesTasks(Run run) {
final List<TaskProvider<?>> copyProcessResources = new ArrayList<>();
for (SourceSet sourceSet : run.getModSources().all().get().values()) {
final Project sourceSetProject = SourceSetUtils.getProject(sourceSet);
Expand All @@ -425,7 +425,7 @@ private List<TaskProvider<?>> createEclipseCopyResourcesTasks(EclipseModel eclip
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 = eclipse.getClasspath().getDefaultOutputDir().toPath();
Path outputDir = sourceSetProject.getExtensions().getByType(IdeManagementExtension.class).getEclipseModel().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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,14 @@ class RunTests extends BuilderBasedTestSpecification {
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import net.minecraft.core.registries.Registries;
@ExtendWith(EphemeralTestServerProvider.class)
public class TestTest {
@Test
public void testIngredient(MinecraftServer server) { // required to load tags
Assertions.assertTrue(
Ingredient.of(ItemTags.AXES).test(Items.DIAMOND_AXE.getDefaultInstance())
Ingredient.of(server.registryAccess().lookupOrThrow(Registries.ITEM).getOrThrow(ItemTags.AXES)).test(Items.DIAMOND_AXE.getDefaultInstance())
);
}
}
Expand Down

0 comments on commit 65b70de

Please sign in to comment.