mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Gradle: fix test open and import project in headless mode.
Run forceLoadSchemes before project startup activities because one of them can define default inspection profile and forceLoadSchemes will do nothing later
This commit is contained in:
+27
-8
@@ -26,6 +26,8 @@ import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataImp
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ProjectManagerListener;
|
||||
import com.intellij.openapi.project.impl.ProjectLifecycleListener;
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil;
|
||||
@@ -196,23 +198,40 @@ public class GradleProjectOpenProcessorTest extends GradleImportingTestCase {
|
||||
" </settings>\n" +
|
||||
"</component>");
|
||||
|
||||
Project fooProject = executeOnEdt(() -> {
|
||||
Project project = ProjectUtil.openOrImport(foo.getPath(), null, true);
|
||||
ProjectInspectionProfileManager projectInspectionProfileManager = ProjectInspectionProfileManager.getInstance(project);
|
||||
projectInspectionProfileManager.forceLoadSchemes();
|
||||
return project;
|
||||
// run forceLoadSchemes before project startup activities
|
||||
// because one of them can define default inspection profile and forceLoadSchemes will do nothing later
|
||||
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(myProject);
|
||||
connection.subscribe(ProjectLifecycleListener.TOPIC, new ProjectLifecycleListener() {
|
||||
@Override
|
||||
public void beforeProjectLoaded(@NotNull Project project) {
|
||||
MessageBusConnection busConnection = project.getMessageBus().connect();
|
||||
busConnection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
|
||||
@Override
|
||||
public void projectOpened(Project project) {
|
||||
ProjectInspectionProfileManager.getInstance(project).forceLoadSchemes();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Project fooProject = null;
|
||||
try {
|
||||
fooProject = executeOnEdt(() -> ProjectUtil.openOrImport(foo.getPath(), null, true));
|
||||
assertTrue(fooProject.isOpen());
|
||||
edt(() -> UIUtil.dispatchAllInvocationEvents());
|
||||
InspectionProfileImpl currentProfile = getCurrentProfile(fooProject);
|
||||
assertEquals("myInspections", currentProfile.getName());
|
||||
ScopeToolState toolState = currentProfile.getToolDefaultState("MultipleRepositoryUrls", fooProject);
|
||||
assertEquals(HighlightDisplayLevel.ERROR, toolState.getLevel());
|
||||
assertModules(fooProject, "foo", "foo_main", "foo_test");
|
||||
|
||||
// Gradle import will fail because of classloading limitation of the test mode since wrong guava pollute the classpath
|
||||
// assertModules(fooProject, "foo", "foo_main", "foo_test");
|
||||
}
|
||||
finally {
|
||||
edt(() -> closeProject(fooProject));
|
||||
connection.disconnect();
|
||||
if (fooProject != null) {
|
||||
Project finalFooProject = fooProject;
|
||||
edt(() -> closeProject(finalFooProject));
|
||||
}
|
||||
}
|
||||
assertFalse(fooProject.isOpen());
|
||||
assertTrue(fooProject.isDisposed());
|
||||
|
||||
Reference in New Issue
Block a user