Search in sources :

Example 6 with DetectedSourceRoot

use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-elixir by KronicDeth.

the class ElixirProjectStructureDetector method setupProjectStructure.

/**
   * This detector just for import non-organization project which not like mix-project
   * So that it's no need to detect directories such as libs, deps, tests etc
   *
   * And mix-project will imported by the MixProjectImportBuilder.java
   * */
@Override
public void setupProjectStructure(@NotNull Collection<DetectedProjectRoot> roots, @NotNull ProjectDescriptor projectDescriptor, @NotNull ProjectFromSourcesBuilder builder) {
    if (!roots.isEmpty() && !builder.hasRootsFromOtherDetectors(this)) {
        List<ModuleDescriptor> modules = projectDescriptor.getModules();
        if (modules.isEmpty()) {
            modules = new ArrayList<ModuleDescriptor>();
            for (DetectedProjectRoot root : roots) {
                modules.add(new ModuleDescriptor(root.getDirectory(), ElixirModuleType.getInstance(), ContainerUtil.<DetectedSourceRoot>emptyList()));
            }
            projectDescriptor.setModules(modules);
        }
    }
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) ModuleDescriptor(com.intellij.ide.util.importProject.ModuleDescriptor) DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot)

Example 7 with DetectedSourceRoot

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

the class ModuleInsight method splitModule.

@Nullable
public ModuleDescriptor splitModule(final ModuleDescriptor descriptor, String newModuleName, final Collection<File> contentsToExtract) {
    ModuleDescriptor newModule = null;
    for (File root : contentsToExtract) {
        final Collection<DetectedSourceRoot> sources = descriptor.removeContentRoot(root);
        if (newModule == null) {
            newModule = createModuleDescriptor(root, sources != null ? sources : new HashSet<>());
        } else {
            if (sources != null && sources.size() > 0) {
                for (DetectedSourceRoot source : sources) {
                    newModule.addSourceRoot(root, source);
                }
            } else {
                newModule.addContentRoot(root);
            }
        }
    }
    if (newModule != null) {
        newModule.setName(newModuleName);
        myModules.add(newModule);
    } else {
        return null;
    }
    final Map<File, ModuleDescriptor> contentRootToModule = new HashMap<>();
    for (ModuleDescriptor module : myModules) {
        final Set<File> roots = module.getContentRoots();
        for (File root : roots) {
            contentRootToModule.put(root, module);
        }
        module.clearModuleDependencies();
        module.clearLibraryFiles();
    }
    buildModuleDependencies(contentRootToModule);
    return newModule;
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with DetectedSourceRoot

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

the class ModuleInsight method appendContentRoot.

private static File appendContentRoot(final ModuleDescriptor module, final File contentRoot) {
    final Set<File> moduleRoots = module.getContentRoots();
    for (File moduleRoot : moduleRoots) {
        if (FileUtil.isAncestor(moduleRoot, contentRoot, false)) {
            // no need to include a separate root
            return moduleRoot;
        }
        if (FileUtil.isAncestor(contentRoot, moduleRoot, true)) {
            final Collection<DetectedSourceRoot> currentSources = module.getSourceRoots(moduleRoot);
            module.removeContentRoot(moduleRoot);
            module.addContentRoot(contentRoot);
            for (DetectedSourceRoot source : currentSources) {
                module.addSourceRoot(contentRoot, source);
            }
            // no need to include a separate root
            return contentRoot;
        }
    }
    module.addContentRoot(contentRoot);
    return contentRoot;
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) File(java.io.File)

Example 9 with DetectedSourceRoot

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

the class RootDetectionProcessor method mergeContentRoots.

private List<DetectedRootData> mergeContentRoots(Map<File, DetectedRootData> rootData) {
    LOG.debug(rootData.size() + " roots found, merging content roots");
    boolean hasSourceRoots = false;
    Set<ModuleType> typesToReplace = new HashSet<>();
    Set<ModuleType> moduleTypes = new HashSet<>();
    for (DetectedRootData data : rootData.values()) {
        for (DetectedProjectRoot root : data.getAllRoots()) {
            if (root instanceof DetectedContentRoot) {
                Collections.addAll(typesToReplace, ((DetectedContentRoot) root).getTypesToReplace());
                moduleTypes.add(((DetectedContentRoot) root).getModuleType());
            } else if (root instanceof DetectedSourceRoot) {
                LOG.debug("Source root found: " + root.getDirectory() + ", content roots will be ignored");
                hasSourceRoots = true;
                break;
            }
        }
    }
    moduleTypes.removeAll(typesToReplace);
    if (hasSourceRoots || moduleTypes.size() <= 1) {
        Iterator<DetectedRootData> iterator = rootData.values().iterator();
        DetectedContentRoot firstRoot = null;
        ProjectStructureDetector firstDetector = null;
        while (iterator.hasNext()) {
            DetectedRootData data = iterator.next();
            for (DetectedProjectRoot root : data.getAllRoots()) {
                if (root instanceof DetectedContentRoot) {
                    LOG.debug("Removed detected " + root.getRootTypeName() + " content root: " + root.getDirectory());
                    Collection<ProjectStructureDetector> detectors = data.removeRoot(root);
                    if ((firstRoot == null || firstDetector == null) && moduleTypes.contains(((DetectedContentRoot) root).getModuleType())) {
                        firstRoot = (DetectedContentRoot) root;
                        firstDetector = ContainerUtil.getFirstItem(detectors);
                    }
                }
            }
            if (data.isEmpty()) {
                iterator.remove();
            }
        }
        if (!hasSourceRoots && firstRoot != null && firstDetector != null) {
            DetectedContentRoot baseRoot = new DetectedContentRoot(myBaseDir, firstRoot.getRootTypeName(), firstRoot.getModuleType());
            DetectedRootData data = rootData.get(myBaseDir);
            if (data == null) {
                rootData.put(myBaseDir, new DetectedRootData(firstDetector, baseRoot));
            } else {
                data.addRoot(firstDetector, baseRoot);
            }
            LOG.debug("Added " + firstRoot.getRootTypeName() + " content root for " + myBaseDir);
        }
    }
    return new ArrayList<>(rootData.values());
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) ModuleType(com.intellij.openapi.module.ModuleType) DetectedContentRoot(com.intellij.ide.util.projectWizard.importSources.DetectedContentRoot) ProjectStructureDetector(com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector)

Aggregations

DetectedSourceRoot (com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot)9 File (java.io.File)7 DetectedProjectRoot (com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot)4 ModuleDescriptor (com.intellij.ide.util.importProject.ModuleDescriptor)3 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