List<Module> (final Project project, ModifiableModuleModel model, ModulesProvider modulesProvider, ModifiableArtifactModel artifactModel) { final Collection<@NlsSafe String> unknownLibraries = new TreeSet<>(); final Collection<String> unknownJdks = new TreeSet<>(); final Set<String> refsToModules = new HashSet<>(); final List<Module> result = new ArrayList<>(); final Map<Module, Set<String>> module2NatureNames = new HashMap<>(); try { final ModifiableModuleModel moduleModel = model != null ? model : ModuleManager.getInstance(project).getModifiableModel(); final ModifiableRootModel[] rootModels = new ModifiableRootModel[getParameters().projectsToConvert.size()]; final Set<File> files = new HashSet<>(); final Set<String> moduleNames = new HashSet<>(getParameters().projectsToConvert.size()); for (String path : getParameters().projectsToConvert) { String modulesDirectory = getParameters().converterOptions.commonModulesDirectory; if (modulesDirectory == null) { modulesDirectory = path; } final String moduleName = EclipseProjectFinder.findProjectName(path); moduleNames.add(moduleName); final File imlFile = new File(modulesDirectory + File.separator + moduleName + ModuleManagerEx.IML_EXTENSION); if (imlFile.isFile()) { files.add(imlFile); } final File emlFile = new File(modulesDirectory + File.separator + moduleName + EclipseXml.IDEA_SETTINGS_POSTFIX); if (emlFile.isFile()) { files.add(emlFile); } } if (!files.isEmpty()) { final int resultCode = Messages.showYesNoCancelDialog(EclipseBundle.message( "dialog.message.0.module.files.found.1.would.you.like.to.reuse.them", ApplicationNamesInfo.getInstance().getFullProductName(), StringUtil.join(files, file -> file.getPath(), "\n")), EclipseBundle.message("dialog.title.module.files.found"), Messages.getQuestionIcon()); if (resultCode != Messages.YES) { if (resultCode == Messages.NO) { final LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); for (File file : files) { final VirtualFile virtualFile = localFileSystem.findFileByIoFile(file); if (virtualFile != null) { ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<Void, IOException>() { @Override public Void compute() throws IOException { virtualFile.delete(this); return null; } }); } else { FileUtil.delete(file); } } } else { return result; } } } int idx = 0; for (String path : getParameters().projectsToConvert) { String modulesDirectory = getParameters().converterOptions.commonModulesDirectory; if (modulesDirectory == null) { modulesDirectory = path; } final Module module = moduleModel.newModule(modulesDirectory + "/" + EclipseProjectFinder.findProjectName(path) + ModuleManagerEx.IML_EXTENSION, StdModuleTypes.JAVA.getId()); result.add(module); final Set<String> natures = collectNatures(path); if (natures.size() > 0) { module2NatureNames.put(module, natures); } final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); rootModels[idx++] = rootModel; final File classpathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT); final EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, project, getParameters().projectsToConvert, moduleNames); classpathReader.init(rootModel); if (classpathFile.exists()) { Element classpathElement = JDOMUtil.load(classpathFile); classpathReader.readClasspath(rootModel, unknownLibraries, unknownJdks, refsToModules, getParameters().converterOptions.testPattern, classpathElement); } else { EclipseClasspathReader.setOutputUrl(rootModel, path + "/bin"); } ClasspathStorage.setStorageType(rootModel, getParameters().linkConverted ? JpsEclipseClasspathSerializer.CLASSPATH_STORAGE_ID : ClassPathStorageUtil.DEFAULT_STORAGE); if (model != null) { ApplicationManager.getApplication().runWriteAction(() -> rootModel.commit()); } } if (model == null) { ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(rootModels, moduleModel)); } } catch (Exception e) { LOG.error(e); } scheduleNaturesImporting(project, module2NatureNames); createEclipseLibrary(project, unknownLibraries, IdeaXml.ECLIPSE_LIBRARY); refsToModules.removeAll(getParameters().existingModuleNames); for (String path : getParameters().projectsToConvert) { final String projectName = EclipseProjectFinder.findProjectName(path); if (projectName != null) { refsToModules.remove(projectName); getParameters().existingModuleNames.add(projectName); } } @Nls StringBuilder message = new StringBuilder(); if (!refsToModules.isEmpty()) { message.append(EclipseBundle.message("unknown.modules.detected.dialog.message", StringUtil.join(refsToModules, "\n"))); } if (!unknownJdks.isEmpty()) { message.append(EclipseBundle.message("unknown.jdks.detected.message", message.length() > 0 ? 0 : 1, StringUtil.join(unknownJdks, "\n"))); } if (!unknownLibraries.isEmpty()) { final HtmlBuilder buf = new HtmlBuilder(); buf.append(EclipseBundle.message("eclipse.import.warning.undefinded.libraries")); for (@NlsSafe String name : unknownLibraries) { buf.br().append(name); } if (model == null) { buf.br().append(HtmlChunk.text(EclipseBundle.message("unknown.libraries.dialog.description")).bold()); final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false) { @Override public boolean isFileSelectable(@Nullable VirtualFile file) { return super.isFileSelectable(file) && Comparing.strEqual(file.getExtension(), "userlibraries"); } }; descriptor.setDescription(buf.wrapWithHtmlBody().toString()); descriptor.setTitle(getTitle()); final VirtualFile selectedFile = FileChooser.chooseFile(descriptor, project, project.getBaseDir()); if (selectedFile != null) { try { EclipseUserLibrariesHelper.readProjectLibrariesContent(selectedFile, project, unknownLibraries); } catch (Exception e) { LOG.error(e); } } } } setupProjectCodeStyle(project, message); if (message.length() > 0) { Messages.showErrorDialog(project, message.toString(), getTitle()); } return result; }