Search in sources :

Example 1 with MavenModuleConfigurer

use of org.jetbrains.idea.maven.importing.configurers.MavenModuleConfigurer in project intellij-community by JetBrains.

the class MavenProjectImporter method importProject.

@Nullable
public List<MavenProjectsProcessorTask> importProject() {
    List<MavenProjectsProcessorTask> postTasks = new ArrayList<>();
    boolean hasChanges;
    // in the case projects are changed during importing we must memorise them
    myAllProjects = new LinkedHashSet<>(myProjectsTree.getProjects());
    // some projects may already have been removed from the tree
    myAllProjects.addAll(myProjectsToImportWithChanges.keySet());
    hasChanges = deleteIncompatibleModules();
    myProjectsToImportWithChanges = collectProjectsToImport(myProjectsToImportWithChanges);
    mapMavenProjectsToModulesAndNames();
    if (myProject.isDisposed())
        return null;
    final boolean projectsHaveChanges = projectsToImportHaveChanges();
    if (projectsHaveChanges) {
        hasChanges = true;
        importModules(postTasks);
        scheduleRefreshResolvedArtifacts(postTasks);
    }
    if (projectsHaveChanges || myImportModuleGroupsRequired) {
        hasChanges = true;
        configModuleGroups();
    }
    if (myProject.isDisposed())
        return null;
    try {
        boolean modulesDeleted = deleteObsoleteModules();
        hasChanges |= modulesDeleted;
        if (hasChanges) {
            removeUnusedProjectLibraries();
        }
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (Exception e) {
        disposeModifiableModels();
        LOG.error(e);
        return null;
    }
    if (hasChanges) {
        MavenUtil.invokeAndWaitWriteAction(myProject, () -> {
            myModelsProvider.commit();
            if (projectsHaveChanges) {
                removeOutdatedCompilerConfigSettings();
                for (MavenProject mavenProject : myAllProjects) {
                    Module module = myMavenProjectToModule.get(mavenProject);
                    if (module != null && module.isDisposed()) {
                        module = null;
                    }
                    for (MavenModuleConfigurer configurer : MavenModuleConfigurer.getConfigurers()) {
                        configurer.configure(mavenProject, myProject, module);
                    }
                }
            }
        });
    } else {
        disposeModifiableModels();
    }
    return postTasks;
}
Also used : Module(com.intellij.openapi.module.Module) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) MavenModuleConfigurer(org.jetbrains.idea.maven.importing.configurers.MavenModuleConfigurer) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Module (com.intellij.openapi.module.Module)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 IOException (java.io.IOException)1 Nullable (org.jetbrains.annotations.Nullable)1 MavenModuleConfigurer (org.jetbrains.idea.maven.importing.configurers.MavenModuleConfigurer)1 MavenProcessCanceledException (org.jetbrains.idea.maven.utils.MavenProcessCanceledException)1