Search in sources :

Example 11 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class MavenProjectImporter method collectIncompatibleModulesWithProjects.

/**
   * Collects modules that need to change module type
   * @return the first List in returned Pair contains already mavenized modules, the second List - not mavenized
   */
private Pair<List<Pair<MavenProject, Module>>, List<Pair<MavenProject, Module>>> collectIncompatibleModulesWithProjects() {
    List<Pair<MavenProject, Module>> incompatibleMavenized = new ArrayList<>();
    List<Pair<MavenProject, Module>> incompatibleNotMavenized = new ArrayList<>();
    MavenProjectsManager manager = MavenProjectsManager.getInstance(myProject);
    for (MavenProject each : myAllProjects) {
        Module module = myFileToModuleMapping.get(each.getFile());
        if (module == null)
            continue;
        if (shouldCreateModuleFor(each) && !(ModuleType.get(module).equals(each.getModuleType()))) {
            (manager.isMavenizedModule(module) ? incompatibleMavenized : incompatibleNotMavenized).add(Pair.create(each, module));
        }
    }
    return Pair.create(incompatibleMavenized, incompatibleNotMavenized);
}
Also used : Module(com.intellij.openapi.module.Module) Pair(com.intellij.openapi.util.Pair)

Example 12 with Module

use of com.intellij.openapi.module.Module 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)

Example 13 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class MavenProjectImporter method formatProjectsWithModules.

private static String formatProjectsWithModules(List<Pair<MavenProject, Module>> projectsWithModules) {
    return StringUtil.join(projectsWithModules, each -> {
        MavenProject project = each.first;
        Module module = each.second;
        return ModuleType.get(module).getName() + " '" + module.getName() + "' for Maven project " + project.getMavenId().getDisplayString();
    }, "<br>");
}
Also used : Module(com.intellij.openapi.module.Module)

Example 14 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class SelectInMavenNavigatorTarget method getMavenProject.

private static MavenProject getMavenProject(SelectInContext context) {
    VirtualFile file = context.getVirtualFile();
    MavenProjectsManager manager = MavenProjectsManager.getInstance(context.getProject());
    Module module = ProjectRootManager.getInstance(context.getProject()).getFileIndex().getModuleForFile(file);
    return module == null ? null : manager.findProject(module);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Module(com.intellij.openapi.module.Module)

Example 15 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class TestNGTestDiscoveryRunnableState method createSearchingForTestsTask.

@Override
public SearchingForTestsTask createSearchingForTestsTask() {
    return new SearchingForTestsTask(myServerSocket, getConfiguration(), myTempFile) {

        @Override
        protected void search() throws CantRunException {
            myClasses.clear();
            final TestData data = getConfiguration().getPersistantData();
            final Pair<String, String> position = data.TEST_OBJECT.equals(TestType.SOURCE.getType()) ? Pair.create(data.getMainClassName(), data.getMethodName()) : null;
            final Set<String> patterns = TestDiscoverySearchHelper.search(getProject(), position, data.getChangeList(), getConfiguration().getFrameworkPrefix());
            final Module module = getConfiguration().getConfigurationModule().getModule();
            final GlobalSearchScope searchScope = module != null ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(getProject());
            TestNGTestPattern.fillTestObjects(myClasses, patterns, TestSearchScope.MODULE_WITH_DEPENDENCIES, getConfiguration(), searchScope);
        }

        @Override
        protected void onFound() {
            super.onFound();
            writeClassesPerModule(myClasses);
        }
    };
}
Also used : SearchingForTestsTask(com.theoryinpractice.testng.configuration.SearchingForTestsTask) TestData(com.theoryinpractice.testng.model.TestData) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1911 VirtualFile (com.intellij.openapi.vfs.VirtualFile)585 Project (com.intellij.openapi.project.Project)381 NotNull (org.jetbrains.annotations.NotNull)331 Nullable (org.jetbrains.annotations.Nullable)268 File (java.io.File)185 PsiFile (com.intellij.psi.PsiFile)147 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)134 ArrayList (java.util.ArrayList)118 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)112 Sdk (com.intellij.openapi.projectRoots.Sdk)95 PsiElement (com.intellij.psi.PsiElement)89 PsiDirectory (com.intellij.psi.PsiDirectory)77 ModuleManager (com.intellij.openapi.module.ModuleManager)65 PsiClass (com.intellij.psi.PsiClass)65 IOException (java.io.IOException)61 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)57 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)57 List (java.util.List)57 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)51