use of org.jetbrains.idea.maven.importing.MavenProjectImporter in project intellij-community by JetBrains.
the class MavenProjectsManager method importProjects.
public List<Module> importProjects(final IdeModifiableModelsProvider modelsProvider) {
final Map<MavenProject, MavenProjectChanges> projectsToImportWithChanges;
final boolean importModuleGroupsRequired;
synchronized (myImportingDataLock) {
projectsToImportWithChanges = new LinkedHashMap<>(myProjectsToImport);
myProjectsToImport.clear();
importModuleGroupsRequired = myImportModuleGroupsRequired;
myImportModuleGroupsRequired = false;
}
final Ref<MavenProjectImporter> importer = new Ref<>();
final Ref<List<MavenProjectsProcessorTask>> postTasks = new Ref<>();
final Runnable r = () -> {
MavenProjectImporter projectImporter = new MavenProjectImporter(myProject, myProjectsTree, getFileToModuleMapping(new MavenModelsProvider() {
@Override
public Module[] getModules() {
return modelsProvider.getModules();
}
@Override
public VirtualFile[] getContentRoots(Module module) {
return modelsProvider.getContentRoots(module);
}
}), projectsToImportWithChanges, importModuleGroupsRequired, modelsProvider, getImportingSettings());
importer.set(projectImporter);
postTasks.set(projectImporter.importProject());
};
// called from wizard or ui
if (ApplicationManager.getApplication().isDispatchThread()) {
r.run();
} else {
MavenUtil.runInBackground(myProject, ProjectBundle.message("maven.project.importing"), false, new MavenTask() {
@Override
public void run(MavenProgressIndicator indicator) throws MavenProcessCanceledException {
r.run();
}
}).waitFor();
}
VirtualFileManager fm = VirtualFileManager.getInstance();
if (isNormalProject()) {
fm.asyncRefresh(null);
} else {
fm.syncRefresh();
}
if (postTasks.get() != null) /*may be null if importing is cancelled*/
{
schedulePostImportTasks(postTasks.get());
}
// do not block user too often
myImportingQueue.restartTimer();
MavenProjectImporter projectImporter = importer.get();
if (projectImporter == null)
return Collections.emptyList();
return projectImporter.getCreatedModules();
}
Aggregations