Search in sources :

Example 1 with DetectedSourceRoot

use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-community by JetBrains.

the class CloudGitChooseAccountStepImpl method updateDataModel.

@Override
public void updateDataModel() {
    super.updateDataModel();
    final MultiMap<CloudGitProjectRoot, DetectedSourceRoot> project2sourceRoots = new MultiMap<>();
    new RootIterator() {

        CloudGitProjectRoot lastProjectRoot = null;

        @Override
        protected void processProjectRoot(CloudGitProjectRoot root) {
            lastProjectRoot = root;
            project2sourceRoots.put(lastProjectRoot, new ArrayList<>());
        }

        @Override
        protected void processJavaSourceRoot(DetectedSourceRoot root) {
            project2sourceRoots.putValue(lastProjectRoot, root);
        }
    }.iterate();
    List<ModuleDescriptor> modules = new ArrayList<>(myProjectDescriptor.getModules());
    for (Map.Entry<CloudGitProjectRoot, Collection<DetectedSourceRoot>> project2sourceRootsEntry : project2sourceRoots.entrySet()) {
        final CloudGitProjectRoot projectRoot = project2sourceRootsEntry.getKey();
        final File directory = projectRoot.getDirectory();
        ModuleDescriptor moduleDescriptor = new ModuleDescriptor(directory, StdModuleTypes.JAVA, project2sourceRootsEntry.getValue());
        final String applicationName = projectRoot.getApplicationName();
        moduleDescriptor.addConfigurationUpdater(new ModuleBuilder.ModuleConfigurationUpdater() {

            @Override
            public void update(@NotNull final Module module, @NotNull ModifiableRootModel rootModel) {
                final MessageBusConnection connection = module.getProject().getMessageBus().connect();
                connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

                    @Override
                    public void moduleAdded(@NotNull Project project, @NotNull Module addedModule) {
                        if (addedModule == module) {
                            StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> onModuleAdded(module));
                            connection.disconnect();
                        }
                    }
                });
            }

            private void onModuleAdded(Module module) {
                createRunConfiguration(module, applicationName);
                GitInit.refreshAndConfigureVcsMappings(module.getProject(), projectRoot.getRepositoryRoot(), directory.getAbsolutePath());
            }
        });
        modules.add(moduleDescriptor);
    }
    myProjectDescriptor.setModules(modules);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) ModuleBuilder(com.intellij.ide.util.projectWizard.ModuleBuilder) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull) DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) MultiMap(com.intellij.util.containers.MultiMap) ModuleDescriptor(com.intellij.ide.util.importProject.ModuleDescriptor) Project(com.intellij.openapi.project.Project) Collection(java.util.Collection) Module(com.intellij.openapi.module.Module) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) File(java.io.File)

Example 2 with DetectedSourceRoot

use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-community by JetBrains.

the class JavaModuleInsight method scanModuleInfoFiles.

private void scanModuleInfoFiles() {
    final List<DetectedSourceRoot> allRoots = super.getSourceRootsToScan();
    final List<JavaModuleSourceRoot> moduleInfoRoots = StreamEx.of(allRoots).select(JavaModuleSourceRoot.class).filter(JavaModuleSourceRoot::isWithModuleInfoFile).filter(root -> !isIgnoredName(root.getDirectory())).toList();
    if (moduleInfoRoots.isEmpty()) {
        return;
    }
    myProgress.setIndeterminate(true);
    myProgress.pushState();
    try {
        Map<String, ModuleInfo> moduleInfos = new HashMap<>();
        for (JavaModuleSourceRoot moduleInfoRoot : moduleInfoRoots) {
            final File sourceRoot = moduleInfoRoot.getDirectory();
            myProgress.setText("Scanning " + sourceRoot.getPath());
            final ModuleInfo moduleInfo = scanModuleInfoFile(sourceRoot);
            if (moduleInfo != null) {
                moduleInfo.descriptor = createModuleDescriptor(moduleInfo.directory, Collections.singletonList(moduleInfoRoot));
                moduleInfos.put(moduleInfo.name, moduleInfo);
                addExportedPackages(sourceRoot, moduleInfo.exportsPackages);
            }
        }
        myProgress.setText("Building modules layout...");
        for (ModuleInfo moduleInfo : moduleInfos.values()) {
            for (String requiresModule : moduleInfo.requiresModules) {
                ModuleInfo requiredModuleInfo = moduleInfos.get(requiresModule);
                if (requiredModuleInfo != null) {
                    moduleInfo.descriptor.addDependencyOn(requiredModuleInfo.descriptor);
                }
            }
        }
        addModules(StreamEx.of(moduleInfos.values()).map(info -> info.descriptor).toList());
    } catch (ProcessCanceledException ignored) {
    } finally {
        myProgress.popState();
    }
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) java.util(java.util) ContainerUtil(com.intellij.util.containers.ContainerUtil) ReadAction(com.intellij.openapi.application.ReadAction) StringBuilderSpinAllocator(com.intellij.util.StringBuilderSpinAllocator) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProjectManager(com.intellij.openapi.project.ProjectManager) ZipFile(java.util.zip.ZipFile) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ZipEntry(java.util.zip.ZipEntry) JavaSourceRootDetectionUtil(com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil) Lexer(com.intellij.lexer.Lexer) LanguageLevel(com.intellij.pom.java.LanguageLevel) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot) IncorrectOperationException(com.intellij.util.IncorrectOperationException) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) JavaFileType(com.intellij.ide.highlighter.JavaFileType) DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) StreamEx(one.util.streamex.StreamEx) JavaParserDefinition(com.intellij.lang.java.JavaParserDefinition) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) Consumer(com.intellij.util.Consumer) JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot) ZipFile(java.util.zip.ZipFile) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 3 with DetectedSourceRoot

use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-community by JetBrains.

the class ModuleInsight method merge.

public void merge(final ModuleDescriptor mainModule, final ModuleDescriptor module) {
    for (File contentRoot : module.getContentRoots()) {
        final File _contentRoot = appendContentRoot(mainModule, contentRoot);
        final Collection<DetectedSourceRoot> sources = module.getSourceRoots(contentRoot);
        for (DetectedSourceRoot source : sources) {
            mainModule.addSourceRoot(_contentRoot, source);
        }
    }
    for (File jar : module.getLibraryFiles()) {
        mainModule.addLibraryFile(jar);
    }
    // fix forward dependencies
    for (ModuleDescriptor dependency : module.getDependencies()) {
        if (!mainModule.equals(dependency)) {
            // avoid self-dependencies
            mainModule.addDependencyOn(dependency);
        }
    }
    myModules.remove(module);
    // fix back dependencies
    for (ModuleDescriptor moduleDescr : myModules) {
        if (moduleDescr.getDependencies().contains(module)) {
            moduleDescr.removeDependencyOn(module);
            if (!moduleDescr.equals(mainModule)) {
                // avoid self-dependencies
                moduleDescr.addDependencyOn(mainModule);
            }
        }
    }
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) File(java.io.File)

Example 4 with DetectedSourceRoot

use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-community by JetBrains.

the class ModuleInsight method scanModules.

public void scanModules() {
    myProgress.setIndeterminate(true);
    final Map<File, ModuleDescriptor> contentRootToModules = new HashMap<>();
    try {
        myProgress.pushState();
        List<DetectedSourceRoot> processedRoots = new ArrayList<>();
        for (DetectedSourceRoot root : getSourceRootsToScan()) {
            final File sourceRoot = root.getDirectory();
            if (isIgnoredName(sourceRoot)) {
                continue;
            }
            myProgress.setText("Scanning " + sourceRoot.getPath());
            final HashSet<String> usedPackages = new HashSet<>();
            mySourceRootToReferencedPackagesMap.put(sourceRoot, usedPackages);
            final HashSet<String> selfPackages = new HashSet<>();
            addExportedPackages(sourceRoot, selfPackages);
            scanSources(sourceRoot, ProjectFromSourcesBuilderImpl.getPackagePrefix(root), usedPackages, selfPackages);
            usedPackages.removeAll(selfPackages);
            processedRoots.add(root);
        }
        myProgress.popState();
        myProgress.pushState();
        myProgress.setText("Building modules layout...");
        for (DetectedSourceRoot sourceRoot : processedRoots) {
            final File srcRoot = sourceRoot.getDirectory();
            final File moduleContentRoot = isEntryPointRoot(srcRoot) ? srcRoot : srcRoot.getParentFile();
            ModuleDescriptor moduleDescriptor = contentRootToModules.get(moduleContentRoot);
            if (moduleDescriptor != null) {
                moduleDescriptor.addSourceRoot(moduleContentRoot, sourceRoot);
            } else {
                moduleDescriptor = createModuleDescriptor(moduleContentRoot, Collections.singletonList(sourceRoot));
                contentRootToModules.put(moduleContentRoot, moduleDescriptor);
            }
        }
        buildModuleDependencies(contentRootToModules);
        myProgress.popState();
    } catch (ProcessCanceledException ignored) {
    }
    addModules(contentRootToModules.values());
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 5 with DetectedSourceRoot

use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project android by JetBrains.

the class AndroidProjectStructureDetector method setupProjectStructure.

@Override
public void setupProjectStructure(@NotNull Collection<DetectedProjectRoot> roots, @NotNull ProjectDescriptor projectDescriptor, @NotNull ProjectFromSourcesBuilder builder) {
    final List<File> existingRoots = new ArrayList<File>();
    for (ProjectStructureDetector detector : ProjectStructureDetector.EP_NAME.getExtensions()) {
        if (detector != this) {
            for (DetectedProjectRoot root : builder.getProjectRoots(detector)) {
                existingRoots.add(root.getDirectory());
            }
        }
    }
    final List<ModuleDescriptor> modules = new ArrayList<ModuleDescriptor>();
    for (DetectedProjectRoot root : roots) {
        final File dir = root.getDirectory();
        boolean javaSrcRootInside = false;
        for (File javaSourceRoot : existingRoots) {
            if (FileUtil.isAncestor(dir, javaSourceRoot, false)) {
                javaSrcRootInside = true;
            }
        }
        if (!javaSrcRootInside) {
            modules.add(new ModuleDescriptor(root.getDirectory(), JavaModuleType.getModuleType(), Collections.<DetectedSourceRoot>emptyList()));
        }
    }
    projectDescriptor.setModules(modules);
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) ModuleDescriptor(com.intellij.ide.util.importProject.ModuleDescriptor) ProjectStructureDetector(com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

DetectedSourceRoot (com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot)10 File (java.io.File)7 DetectedProjectRoot (com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot)5 ModuleDescriptor (com.intellij.ide.util.importProject.ModuleDescriptor)4 ProjectStructureDetector (com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 JavaFileType (com.intellij.ide.highlighter.JavaFileType)1 ModuleBuilder (com.intellij.ide.util.projectWizard.ModuleBuilder)1 DetectedContentRoot (com.intellij.ide.util.projectWizard.importSources.DetectedContentRoot)1 JavaModuleSourceRoot (com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot)1 JavaSourceRootDetectionUtil (com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil)1 JavaParserDefinition (com.intellij.lang.java.JavaParserDefinition)1 Lexer (com.intellij.lexer.Lexer)1 ReadAction (com.intellij.openapi.application.ReadAction)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Module (com.intellij.openapi.module.Module)1 ModuleType (com.intellij.openapi.module.ModuleType)1 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)1