Search in sources :

Example 1 with ProjectStructureDetector

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

the class RootDetectionProcessor method detectRoots.

private List<DetectedRootData> detectRoots() {
    Map<ProjectStructureDetector, List<DetectedProjectRoot>> roots = runDetectors();
    if (myProgressIndicator != null) {
        myProgressIndicator.setText2("Processing " + roots.values().size() + " project roots...");
    }
    Map<File, DetectedRootData> rootData = new LinkedHashMap<>();
    for (ProjectStructureDetector detector : roots.keySet()) {
        for (DetectedProjectRoot detectedRoot : roots.get(detector)) {
            if (isUnderIncompatibleRoot(detectedRoot, rootData)) {
                continue;
            }
            final DetectedRootData data = rootData.get(detectedRoot.getDirectory());
            if (data == null) {
                rootData.put(detectedRoot.getDirectory(), new DetectedRootData(detector, detectedRoot));
            } else {
                detectedRoot = data.addRoot(detector, detectedRoot);
            }
            removeIncompatibleRoots(detectedRoot, rootData);
        }
    }
    List<DetectedRootData> dataCollection = mergeContentRoots(rootData);
    if (myProgressIndicator != null) {
        myProgressIndicator.setText2("");
    }
    return dataCollection;
}
Also used : DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) ProjectStructureDetector(com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector) SmartList(com.intellij.util.SmartList) File(java.io.File)

Example 2 with ProjectStructureDetector

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

the class CreateFromSourcesMode method addSteps.

public void addSteps(WizardContext context, ModulesProvider modulesProvider, StepSequence sequence, String specific) {
    final ProjectFromSourcesBuilderImpl projectBuilder = new ProjectFromSourcesBuilderImpl(context, modulesProvider);
    myProjectBuilder = projectBuilder;
    final Icon icon = context.getStepIcon();
    if (context.isCreatingNewProject()) {
        addStep(sequence, new ProjectNameStep(context, this), specific);
    }
    addStep(sequence, new RootsDetectionStep(projectBuilder, context, sequence, icon, "reference.dialogs.new.project.fromCode.source"), specific);
    Set<String> detectorTypes = new HashSet<>();
    for (ProjectStructureDetector detector : ProjectStructureDetector.EP_NAME.getExtensions()) {
        detectorTypes.add(detector.getDetectorId());
        for (ModuleWizardStep step : detector.createWizardSteps(projectBuilder, projectBuilder.getProjectDescriptor(detector), icon)) {
            sequence.addSpecificStep(detector.getDetectorId(), step);
        }
    }
    if (FrameworkDetectionStep.isEnabled()) {
        FrameworkDetectionStep frameworkDetectionStep = new FrameworkDetectionStep(icon, projectBuilder) {

            public List<ModuleDescriptor> getModuleDescriptors() {
                final List<ModuleDescriptor> moduleDescriptors = new ArrayList<>();
                for (ProjectDescriptor descriptor : projectBuilder.getSelectedDescriptors()) {
                    moduleDescriptors.addAll(descriptor.getModules());
                }
                return moduleDescriptors;
            }
        };
        projectBuilder.addConfigurationUpdater(frameworkDetectionStep);
        sequence.addCommonFinishingStep(frameworkDetectionStep, detectorTypes);
    }
}
Also used : ArrayList(java.util.ArrayList) ProjectFromSourcesBuilderImpl(com.intellij.ide.util.projectWizard.importSources.impl.ProjectFromSourcesBuilderImpl) ModuleDescriptor(com.intellij.ide.util.importProject.ModuleDescriptor) ProjectStructureDetector(com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) ProjectNameStep(com.intellij.ide.util.newProjectWizard.ProjectNameStep) ProjectDescriptor(com.intellij.ide.util.importProject.ProjectDescriptor) FrameworkDetectionStep(com.intellij.ide.util.importProject.FrameworkDetectionStep) RootsDetectionStep(com.intellij.ide.util.importProject.RootsDetectionStep) HashSet(java.util.HashSet)

Example 3 with ProjectStructureDetector

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

Example 4 with ProjectStructureDetector

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

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

the class RootsDetectionStep method updateSelectedTypes.

private void updateSelectedTypes() {
    Set<String> selectedTypes = new LinkedHashSet<>();
    selectedTypes.add("Existing Sources");
    for (DetectedRootData rootData : myDetectedRootsChooser.getMarkedElements()) {
        for (ProjectStructureDetector detector : rootData.getSelectedDetectors()) {
            selectedTypes.add(detector.getDetectorId());
        }
    }
    mySequence.setTypes(selectedTypes);
    myContext.requestWizardButtonsUpdate();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProjectStructureDetector(com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector)

Aggregations

ProjectStructureDetector (com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector)7 DetectedProjectRoot (com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot)5 ModuleDescriptor (com.intellij.ide.util.importProject.ModuleDescriptor)2 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)2 DetectedSourceRoot (com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 DetectedRootData (com.intellij.ide.util.importProject.DetectedRootData)1 FrameworkDetectionStep (com.intellij.ide.util.importProject.FrameworkDetectionStep)1 ProjectDescriptor (com.intellij.ide.util.importProject.ProjectDescriptor)1 RootsDetectionStep (com.intellij.ide.util.importProject.RootsDetectionStep)1 ProjectNameStep (com.intellij.ide.util.newProjectWizard.ProjectNameStep)1 AbstractStepWithProgress (com.intellij.ide.util.projectWizard.AbstractStepWithProgress)1 DetectedContentRoot (com.intellij.ide.util.projectWizard.importSources.DetectedContentRoot)1 ProjectFromSourcesBuilderImpl (com.intellij.ide.util.projectWizard.importSources.impl.ProjectFromSourcesBuilderImpl)1 ModuleType (com.intellij.openapi.module.ModuleType)1 SmartList (com.intellij.util.SmartList)1 MultiMap (com.intellij.util.containers.MultiMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1