Search in sources :

Example 6 with DetectedProjectRoot

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

the class ProjectLayoutPanel method getElementText.

protected static String getElementText(Object element) {
    if (element instanceof LibraryDescriptor) {
        final StringBuilder builder = StringBuilderSpinAllocator.alloc();
        try {
            builder.append(((LibraryDescriptor) element).getName());
            final Collection<File> jars = ((LibraryDescriptor) element).getJars();
            if (jars.size() == 1) {
                final File parentFile = jars.iterator().next().getParentFile();
                if (parentFile != null) {
                    builder.append(" (");
                    builder.append(parentFile.getPath());
                    builder.append(")");
                }
            }
            return builder.toString();
        } finally {
            StringBuilderSpinAllocator.dispose(builder);
        }
    }
    if (element instanceof File) {
        final StringBuilder builder = StringBuilderSpinAllocator.alloc();
        try {
            builder.append(((File) element).getName());
            final File parentFile = ((File) element).getParentFile();
            if (parentFile != null) {
                builder.append(" (");
                builder.append(parentFile.getPath());
                builder.append(")");
            }
            return builder.toString();
        } finally {
            StringBuilderSpinAllocator.dispose(builder);
        }
    }
    if (element instanceof ModuleDescriptor) {
        final ModuleDescriptor moduleDescriptor = (ModuleDescriptor) element;
        final StringBuilder builder = StringBuilderSpinAllocator.alloc();
        try {
            builder.append(moduleDescriptor.getName());
            final Set<File> contents = moduleDescriptor.getContentRoots();
            final int rootCount = contents.size();
            if (rootCount > 0) {
                builder.append(" (");
                builder.append(contents.iterator().next().getPath());
                if (rootCount > 1) {
                    builder.append("...");
                }
                builder.append(")");
            }
            final Collection<? extends DetectedProjectRoot> sourceRoots = moduleDescriptor.getSourceRoots();
            if (sourceRoots.size() > 0) {
                builder.append(" [");
                for (Iterator<? extends DetectedProjectRoot> it = sourceRoots.iterator(); it.hasNext(); ) {
                    DetectedProjectRoot root = it.next();
                    builder.append(root.getDirectory().getName());
                    if (it.hasNext()) {
                        builder.append(",");
                    }
                }
                builder.append("]");
            }
            return builder.toString();
        } finally {
            StringBuilderSpinAllocator.dispose(builder);
        }
    }
    return "";
}
Also used : DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) File(java.io.File)

Example 7 with DetectedProjectRoot

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

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

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

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

the class ModuleDescriptor method toString.

/**
   * For debug purposes only
   */
public String toString() {
    @NonNls final StringBuilder builder = new StringBuilder();
    builder.append("[Module: ").append(getContentRoots()).append(" | ");
    for (DetectedProjectRoot sourceRoot : getSourceRoots()) {
        builder.append(sourceRoot.getDirectory().getName()).append(",");
    }
    builder.append("]");
    return builder.toString();
}
Also used : NonNls(org.jetbrains.annotations.NonNls) DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot)

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