List<MavenProjectsProcessorTask> () { MavenLog.LOG.info("Importing Maven project using Legacy API"); List<MavenProjectsProcessorTask> postTasks = new ArrayList<>(); boolean hasChanges; StructuredIdeActivity activity = MavenImportCollector.LEGACY_IMPORT.started(myProject); // in the case projects are changed during importing we must memorise them myAllProjects = new LinkedHashSet<>(myProjectsTree.getProjects()); myAllProjects.addAll(myProjectsToImportWithChanges.keySet()); // some projects may already have been removed from the tree hasChanges = deleteIncompatibleModules(); myProjectsToImportWithChanges = collectProjectsToImport(myProjectsToImportWithChanges); mapMavenProjectsToModulesAndNames(); if (myProject.isDisposed()) return null; final boolean projectsHaveChanges = projectsToImportHaveChanges(myProjectsToImportWithChanges.values()); final List<MavenLegacyModuleImporter.ExtensionImporter> extensionImporters = new ArrayList<>(); if (projectsHaveChanges) { hasChanges = true; StructuredIdeActivity createModulesPhase = MavenImportCollector.LEGACY_CREATE_MODULES_PHASE.startedWithParent(myProject, activity); extensionImporters.addAll(importModules()); if (!MavenUtil.isMavenUnitTestModeEnabled()) { scheduleRefreshResolvedArtifacts(postTasks, myProjectsToImportWithChanges.keySet()); } createModulesPhase.finished(); } if (myProject.isDisposed()) return null; List<Module> obsoleteModules = collectObsoleteModules(); boolean isDeleteObsoleteModules = isDeleteObsoleteModules(obsoleteModules); hasChanges |= isDeleteObsoleteModules; if (hasChanges) { StructuredIdeActivity deleteObsoletePhase = MavenImportCollector.LEGACY_DELETE_OBSOLETE_PHASE.startedWithParent(myProject, activity); MavenUtil.invokeAndWaitWriteAction(myProject, () -> { ProjectRootManagerEx.getInstanceEx(myProject).mergeRootsChangesDuring(() -> { setMavenizedModules(obsoleteModules, false); List<Module> toDelete = new ArrayList<>(); if (myPreviewModule != null) { toDelete.add(myPreviewModule); myPreviewModule = null; } if (isDeleteObsoleteModules) { toDelete.addAll(obsoleteModules); } deleteModules(toDelete); removeUnusedProjectLibraries(); myModelsProvider.commit(); if (projectsHaveChanges) { removeOutdatedCompilerConfigSettings(myProject); } if (projectsHaveChanges) { setMavenizedModules(ContainerUtil.map(myProjectsToImportWithChanges.keySet(), myMavenProjectToModule::get), true); } }); }); deleteObsoletePhase.finished(); StructuredIdeActivity importersPhase = MavenImportCollector.LEGACY_IMPORTERS_PHASE.startedWithParent(myProject, activity); importExtensions(myProject, myIdeModifiableModelsProvider, extensionImporters, postTasks, importersPhase); importersPhase.finished(); } else { finalizeImport(obsoleteModules); } activity.finished(() -> List.of(MavenImportCollector.NUMBER_OF_MODULES.with(myMavenProjectToModule.size()))); return postTasks; }