Search in sources :

Example 1 with DetectedContentRoot

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

the class PyProjectStructureDetector method detectRoots.

@NotNull
@Override
public DirectoryProcessingResult detectRoots(@NotNull File dir, @NotNull File[] children, @NotNull File base, @NotNull List<DetectedProjectRoot> result) {
    LOG.info("Detecting roots under " + dir);
    for (File child : children) {
        final String name = child.getName();
        if (FileUtilRt.extensionEquals(name, "py")) {
            LOG.info("Found Python file " + child.getPath());
            result.add(new DetectedContentRoot(dir, "Python", PythonModuleTypeBase.getInstance(), WebModuleType.getInstance()));
            return DirectoryProcessingResult.SKIP_CHILDREN;
        }
        if ("node_modules".equals(name)) {
            return DirectoryProcessingResult.SKIP_CHILDREN;
        }
    }
    return DirectoryProcessingResult.PROCESS_CHILDREN;
}
Also used : DetectedContentRoot(com.intellij.ide.util.projectWizard.importSources.DetectedContentRoot) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with DetectedContentRoot

use of com.intellij.ide.util.projectWizard.importSources.DetectedContentRoot 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

DetectedContentRoot (com.intellij.ide.util.projectWizard.importSources.DetectedContentRoot)2 DetectedProjectRoot (com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot)1 DetectedSourceRoot (com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot)1 ProjectStructureDetector (com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector)1 ModuleType (com.intellij.openapi.module.ModuleType)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1