List<Module> (final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider, final ModifiableArtifactModel artifactModel) { project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE); final DataNode<ProjectData> externalProjectNode = getExternalProjectNode(); if (externalProjectNode != null) { beforeCommit(externalProjectNode, project); } final boolean isFromUI = model != null; final List<Module> modules = new SmartList<>(); final Map<ModifiableRootModel, Module> moduleMap = new IdentityHashMap<>(); final IdeModifiableModelsProvider modelsProvider = isFromUI ? new IdeUIModifiableModelsProvider( project, model, (ModulesConfigurator)modulesProvider, artifactModel) { @Override protected ModifiableRootModel doGetModifiableRootModel(Module module) { ModifiableRootModel modifiableRootModel = super.doGetModifiableRootModel(module); moduleMap.put(modifiableRootModel, module); return modifiableRootModel; } @Override public void commit() { super.commit(); for (Map.Entry<ModifiableRootModel, Module> moduleEntry : moduleMap.entrySet()) { modules.add(moduleEntry.getValue()); } } } : new IdeModifiableModelsProviderImpl(project){ @NotNull @Override protected ModifiableRootModel doGetModifiableRootModel(@NotNull Module module) { ModifiableRootModel modifiableRootModel = super.doGetModifiableRootModel(module); moduleMap.put(modifiableRootModel, module); return modifiableRootModel; } @Override public void commit() { super.commit(); for (Map.Entry<ModifiableRootModel, Module> moduleEntry : moduleMap.entrySet()) { if (!moduleEntry.getKey().isWritable()) { modules.add(moduleEntry.getValue()); } } } }; AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId); final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings(); //noinspection unchecked Set<ExternalProjectSettings> projects = new HashSet<ExternalProjectSettings>(systemSettings.getLinkedProjectsSettings()); // add current importing project settings to linked projects settings or replace if similar already exist projects.remove(projectSettings); projects.add(projectSettings); //noinspection unchecked systemSettings.copyFrom(getControl().getSystemSettings()); //noinspection unchecked systemSettings.setLinkedProjectsSettings(projects); if (externalProjectNode != null) { if (systemSettings.showSelectiveImportDialogOnInitialImport() && !ApplicationManager.getApplication().isHeadlessEnvironment()) { ExternalProjectDataSelectorDialog dialog = new ExternalProjectDataSelectorDialog( project, new InternalExternalProjectInfo(myExternalSystemId, projectSettings.getExternalProjectPath(), externalProjectNode)); if (dialog.hasMultipleDataToSelect()) { dialog.showAndGet(); } else { Disposer.dispose(dialog.getDisposable()); } } if (!project.isInitialized()) { StartupManager.getInstance(project).runWhenProjectIsInitialized( () -> finishImport(project, externalProjectNode, isFromUI, modules, modelsProvider, projectSettings)); } else finishImport(project, externalProjectNode, isFromUI, modules, modelsProvider, projectSettings); } return modules; }