Search in sources :

Example 11 with DetectedProjectRoot

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

the class ModulesDetectionStep method calcStateHashCode.

private int calcStateHashCode() {
    final String contentEntryPath = myBuilder.getBaseProjectPath();
    int hash = contentEntryPath != null ? contentEntryPath.hashCode() : 1;
    for (DetectedProjectRoot root : myBuilder.getProjectRoots(myDetector)) {
        hash = 31 * hash + root.getDirectory().hashCode();
    }
    final List<LibraryDescriptor> libs = myProjectDescriptor.getLibraries();
    for (LibraryDescriptor lib : libs) {
        final Collection<File> files = lib.getJars();
        for (File file : files) {
            hash = 31 * hash + file.hashCode();
        }
    }
    return hash;
}
Also used : DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) File(java.io.File)

Example 12 with DetectedProjectRoot

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

the class RootDetectionProcessor method isUnderIncompatibleRoot.

private static boolean isUnderIncompatibleRoot(DetectedProjectRoot root, Map<File, DetectedRootData> rootData) {
    File directory = root.getDirectory().getParentFile();
    while (directory != null) {
        final DetectedRootData data = rootData.get(directory);
        if (data != null) {
            for (DetectedProjectRoot parentRoot : data.getAllRoots()) {
                if (!parentRoot.canContainRoot(root)) {
                    return true;
                }
            }
        }
        directory = directory.getParentFile();
    }
    return false;
}
Also used : DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) File(java.io.File)

Example 13 with DetectedProjectRoot

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

Example 14 with DetectedProjectRoot

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

the class DetectedRootData method addRoot.

public DetectedProjectRoot addRoot(ProjectStructureDetector detector, DetectedProjectRoot root) {
    for (Map.Entry<DetectedProjectRoot, Collection<ProjectStructureDetector>> entry : myRoots.entrySet()) {
        final DetectedProjectRoot oldRoot = entry.getKey();
        final DetectedProjectRoot combined = oldRoot.combineWith(root);
        if (combined != null) {
            myRoots.remove(oldRoot);
            final Set<ProjectStructureDetector> values = new HashSet<>(entry.getValue());
            values.add(detector);
            myRoots.put(combined, values);
            if (mySelectedRoot == oldRoot) {
                mySelectedRoot = combined;
            }
            return combined;
        }
    }
    myRoots.putValue(root, detector);
    return root;
}
Also used : DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) ProjectStructureDetector(com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector) MultiMap(com.intellij.util.containers.MultiMap)

Example 15 with DetectedProjectRoot

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

the class ImportFromSourcesTestCase method importFromSources.

protected void importFromSources(File dir) {
    myRootDir = dir;
    try {
        myProject = doCreateProject(getIprFile());
        myBuilder.setBaseProjectPath(dir.getAbsolutePath());
        List<DetectedRootData> list = RootDetectionProcessor.detectRoots(dir);
        MultiMap<ProjectStructureDetector, DetectedProjectRoot> map = RootDetectionProcessor.createRootsMap(list);
        myBuilder.setupProjectStructure(map);
        for (ProjectStructureDetector detector : map.keySet()) {
            List<ModuleWizardStep> steps = detector.createWizardSteps(myBuilder, myBuilder.getProjectDescriptor(detector), EmptyIcon.ICON_16);
            try {
                for (ModuleWizardStep step : steps) {
                    if (step instanceof AbstractStepWithProgress<?>) {
                        performStep((AbstractStepWithProgress<?>) step);
                    }
                }
            } finally {
                for (ModuleWizardStep step : steps) {
                    step.disposeUIResources();
                }
            }
        }
        myBuilder.commit(myProject, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) AbstractStepWithProgress(com.intellij.ide.util.projectWizard.AbstractStepWithProgress) DetectedRootData(com.intellij.ide.util.importProject.DetectedRootData) ProjectStructureDetector(com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep)

Aggregations

DetectedProjectRoot (com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot)16 File (java.io.File)8 ProjectStructureDetector (com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector)5 ModuleDescriptor (com.intellij.ide.util.importProject.ModuleDescriptor)3 DetectedSourceRoot (com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot)3 ArrayList (java.util.ArrayList)3 Pattern (java.util.regex.Pattern)2 NotNull (org.jetbrains.annotations.NotNull)2 DetectedRootData (com.intellij.ide.util.importProject.DetectedRootData)1 AbstractStepWithProgress (com.intellij.ide.util.projectWizard.AbstractStepWithProgress)1 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)1 DetectedContentRoot (com.intellij.ide.util.projectWizard.importSources.DetectedContentRoot)1 JavaModuleSourceRoot (com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot)1 ModuleType (com.intellij.openapi.module.ModuleType)1 SmartList (com.intellij.util.SmartList)1 MultiMap (com.intellij.util.containers.MultiMap)1 TableColumn (javax.swing.table.TableColumn)1 NonNls (org.jetbrains.annotations.NonNls)1