Skip to content
Open
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 @@ -3,12 +3,12 @@
import static org.mockito.Mockito.when;

import java.io.File;
import java.lang.reflect.InvocationTargetException;

import org.assertj.core.api.WithAssertions;
import org.eclipse.core.runtime.CoreException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -92,7 +92,7 @@ void injects_resolved_scripts(String identifier, Class<?> expectedClass) {
else
script = language.resolveCondition(identifier, context);

assertThat((Injectable) script).matches(r -> r.hasBeenInjected());
assertThat((Injectable) script).matches(r -> r.hasBeenInjected(), "has been injected");
}

@Nested @DisplayName("when the bundle does not exist")
Expand Down Expand Up @@ -179,13 +179,6 @@ void does_not_inject_resolved_scripts(String identifier, Class<?> expectedClass)

}

@Disabled // Following tests have a strange behavior :
// - they pass most of the time when executed from Eclipse IDE,
// - they fail most of the time when executed from local Maven
// - they fail all the time when executed from the headless CI
//
// As manual testing has shown that the code seems to work in a real situation,
// the tests are disabled for the moment.
@TestInstance(Lifecycle.PER_CLASS)
@Nested @DisplayName("when resolving from a workspace project")
class WhenResolvingFromAWorkspaceProject implements ProjectProvider { // ProjectProvider provides some constants
Expand All @@ -198,11 +191,10 @@ void createJavaLanguage(@Mock Events events, @Mock ExecutionStatus status) {
}

@BeforeAll
void importFakeProjectInWorkspace() throws CoreException {
void importFakeProjectInWorkspace() throws CoreException, InvocationTargetException, InterruptedException {
File fakeProjectPath = new File("./rsc/some.workspace.project/");
ImportableProject fakeProject = new ImportableProject(fakeProjectPath);

// Causes exceptions at runtime **on Eclipse IDE**, but I don't know how to avoid them
fakeProject.importInWorkspace();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package fr.kazejiyu.ekumi.languages.java.test;

import java.io.File;
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;

/**
* Represents an Eclipse project that can be imported in the workspace.
Expand All @@ -16,7 +21,6 @@
public class ImportableProject {

private final File location;
private IProject project;

/**
* Creates a new importable project.
Expand All @@ -32,26 +36,38 @@ public ImportableProject(File location) {
* Imports the project in the workspace.
*
* @throws CoreException if the project cannot be imported.
* @throws InterruptedException
* @throws InvocationTargetException
*/
public void importInWorkspace() throws CoreException {
public void importInWorkspace() throws CoreException, InvocationTargetException, InterruptedException {
IProjectDescription description = ResourcesPlugin
.getWorkspace()
.loadProjectDescription(projectFile());

project = ResourcesPlugin
IProject project = ResourcesPlugin
.getWorkspace()
.getRoot()
.getProject(description.getName());

// Works most of the time when executed from Eclipse IDE
// Prevent runtime errors when importing the project
description.setLocation(ResourcesPlugin.getWorkspace().getRoot().getLocation().append(project.getName()));

// Create the project in the workspace
project.create(description, null);
project.open(null);

// Import the content of the project
IOverwriteQuery overwriteQuery = file -> IOverwriteQuery.ALL;

ImportOperation importOperation = new ImportOperation(
project.getFullPath(),
new File(location.getAbsolutePath()),
FileSystemStructureProvider.INSTANCE,
overwriteQuery
);

// Bad attempt to make the import works from Maven
// Still works from Eclipse IDE, but causes Maven tests
// to fail all the time
// project.refreshLocal(IResource.DEPTH_INFINITE, null);
// project.build(IncrementalProjectBuilder.FULL_BUILD, null);
importOperation.setCreateContainerStructure(false);
importOperation.run(new NullProgressMonitor());
}

/** @return the path toward the location/.project file */
Expand Down