Search in sources :

Example 6 with JavaModuleSourceRoot

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

the class JavaContentEntriesEditor method addSourceRoots.

private static void addSourceRoots(@NotNull Project project, final ContentEntry[] contentEntries, final Runnable finishRunnable) {
    final HashMap<ContentEntry, Collection<JavaModuleSourceRoot>> entryToRootMap = new HashMap<>();
    final Map<File, ContentEntry> fileToEntryMap = new HashMap<>();
    for (final ContentEntry contentEntry : contentEntries) {
        final VirtualFile file = contentEntry.getFile();
        if (file != null) {
            entryToRootMap.put(contentEntry, null);
            fileToEntryMap.put(VfsUtilCore.virtualToIoFile(file), contentEntry);
        }
    }
    final ProgressWindow progressWindow = new ProgressWindow(true, project);
    final ProgressIndicator progressIndicator = new SmoothProgressAdapter(progressWindow, project);
    final Runnable searchRunnable = () -> {
        final Runnable process = () -> {
            for (final File file : fileToEntryMap.keySet()) {
                progressIndicator.setText(ProjectBundle.message("module.paths.searching.source.roots.progress", file.getPath()));
                final Collection<JavaModuleSourceRoot> roots = JavaSourceRootDetectionUtil.suggestRoots(file);
                entryToRootMap.put(fileToEntryMap.get(file), roots);
            }
        };
        progressWindow.setTitle(ProjectBundle.message("module.paths.searching.source.roots.title"));
        ProgressManager.getInstance().runProcess(process, progressIndicator);
    };
    final Runnable addSourcesRunnable = () -> {
        for (final ContentEntry contentEntry : contentEntries) {
            final Collection<JavaModuleSourceRoot> suggestedRoots = entryToRootMap.get(contentEntry);
            if (suggestedRoots != null) {
                for (final JavaModuleSourceRoot suggestedRoot : suggestedRoots) {
                    final VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByIoFile(suggestedRoot.getDirectory());
                    final VirtualFile fileContent = contentEntry.getFile();
                    if (sourceRoot != null && fileContent != null && VfsUtilCore.isAncestor(fileContent, sourceRoot, false)) {
                        contentEntry.addSourceFolder(sourceRoot, false, suggestedRoot.getPackagePrefix());
                    }
                }
            }
        }
        if (finishRunnable != null) {
            finishRunnable.run();
        }
    };
    new SwingWorker() {

        @Override
        public Object construct() {
            searchRunnable.run();
            return null;
        }

        @Override
        public void finished() {
            addSourcesRunnable.run();
        }
    }.start();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SmoothProgressAdapter(com.intellij.openapi.progress.util.SmoothProgressAdapter) HashMap(java.util.HashMap) ContentEntry(com.intellij.openapi.roots.ContentEntry) ProgressWindow(com.intellij.openapi.progress.util.ProgressWindow) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Collection(java.util.Collection) SwingWorker(com.intellij.util.concurrency.SwingWorker) JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 7 with JavaModuleSourceRoot

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

the class CloudGitProjectStructureDetector method detectJavaRoots.

private DirectoryProcessingResult detectJavaRoots(String javaSourceRootTypeName, @NotNull File dir, @NotNull File[] children, @NotNull File base, @NotNull List<DetectedProjectRoot> result) {
    List<DetectedProjectRoot> detectedJavaRoots = new ArrayList<>();
    DirectoryProcessingResult processingResult = myJavaDetector.detectRoots(dir, children, base, detectedJavaRoots);
    for (DetectedProjectRoot detectedJavaRoot : detectedJavaRoots) {
        if (detectedJavaRoot instanceof JavaModuleSourceRoot) {
            result.add(new CloudGitJavaSourceRoot(javaSourceRootTypeName, (JavaModuleSourceRoot) detectedJavaRoot));
        }
    }
    return processingResult;
}
Also used : DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) ArrayList(java.util.ArrayList) JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot)

Aggregations

JavaModuleSourceRoot (com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot)7 File (java.io.File)3 DetectedProjectRoot (com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Pair (com.intellij.openapi.util.Pair)2 ArrayList (java.util.ArrayList)2 JavaFileType (com.intellij.ide.highlighter.JavaFileType)1 DetectedSourceRoot (com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot)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 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressWindow (com.intellij.openapi.progress.util.ProgressWindow)1 SmoothProgressAdapter (com.intellij.openapi.progress.util.SmoothProgressAdapter)1 ProjectManager (com.intellij.openapi.project.ProjectManager)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1 MultiLineLabelUI (com.intellij.openapi.ui.MultiLineLabelUI)1