Search in sources :

Example 1 with JavaModuleSourceRoot

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

the class MavenFoldersImporter method configGeneratedSourceFolder.

private void configGeneratedSourceFolder(@NotNull File targetDir, final JavaSourceRootType rootType) {
    switch(myImportingSettings.getGeneratedSourcesFolder()) {
        case GENERATED_SOURCE_FOLDER:
            myModel.addGeneratedJavaSourceFolder(targetDir.getPath(), rootType);
            break;
        case SUBFOLDER:
            addAllSubDirsAsGeneratedSources(targetDir, rootType);
            break;
        case AUTODETECT:
            Collection<JavaModuleSourceRoot> sourceRoots = JavaSourceRootDetectionUtil.suggestRoots(targetDir);
            for (JavaModuleSourceRoot root : sourceRoots) {
                if (FileUtil.filesEqual(targetDir, root.getDirectory())) {
                    myModel.addGeneratedJavaSourceFolder(targetDir.getPath(), rootType);
                    return;
                }
                addAsGeneratedSourceFolder(root.getDirectory(), rootType);
            }
            addAllSubDirsAsGeneratedSources(targetDir, rootType);
            break;
        case IGNORE:
            // Ignore.
            break;
    }
}
Also used : JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot)

Example 2 with JavaModuleSourceRoot

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

the class JavaSourceRootDetectionTest method doTest.

private void doTest(String... expected) {
    final String dirPath = JavaTestUtil.getJavaTestDataPath() + FileUtil.toSystemDependentName("/ide/sourceRootDetection/" + getTestName(true));
    final File dir = new File(dirPath);
    assertTrue(dir.isDirectory());
    final List<Pair<File, String>> actual = new ArrayList<>();
    for (JavaModuleSourceRoot root : JavaSourceRootDetectionUtil.suggestRoots(dir)) {
        actual.add(Pair.create(root.getDirectory(), root.getPackagePrefix()));
    }
    List<Pair<File, String>> expectedList = new ArrayList<>();
    for (int i = 0; i < expected.length / 2; i++) {
        expectedList.add(Pair.create(new File(dir, expected[2 * i]), expected[2 * i + 1]));
    }
    assertSameElements(actual, expectedList);
}
Also used : ArrayList(java.util.ArrayList) JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot) File(java.io.File) Pair(com.intellij.openapi.util.Pair)

Example 3 with JavaModuleSourceRoot

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

the class JavaModuleInsight method scanModuleInfoFiles.

private void scanModuleInfoFiles() {
    final List<DetectedSourceRoot> allRoots = super.getSourceRootsToScan();
    final List<JavaModuleSourceRoot> moduleInfoRoots = StreamEx.of(allRoots).select(JavaModuleSourceRoot.class).filter(JavaModuleSourceRoot::isWithModuleInfoFile).filter(root -> !isIgnoredName(root.getDirectory())).toList();
    if (moduleInfoRoots.isEmpty()) {
        return;
    }
    myProgress.setIndeterminate(true);
    myProgress.pushState();
    try {
        Map<String, ModuleInfo> moduleInfos = new HashMap<>();
        for (JavaModuleSourceRoot moduleInfoRoot : moduleInfoRoots) {
            final File sourceRoot = moduleInfoRoot.getDirectory();
            myProgress.setText("Scanning " + sourceRoot.getPath());
            final ModuleInfo moduleInfo = scanModuleInfoFile(sourceRoot);
            if (moduleInfo != null) {
                moduleInfo.descriptor = createModuleDescriptor(moduleInfo.directory, Collections.singletonList(moduleInfoRoot));
                moduleInfos.put(moduleInfo.name, moduleInfo);
                addExportedPackages(sourceRoot, moduleInfo.exportsPackages);
            }
        }
        myProgress.setText("Building modules layout...");
        for (ModuleInfo moduleInfo : moduleInfos.values()) {
            for (String requiresModule : moduleInfo.requiresModules) {
                ModuleInfo requiredModuleInfo = moduleInfos.get(requiresModule);
                if (requiredModuleInfo != null) {
                    moduleInfo.descriptor.addDependencyOn(requiredModuleInfo.descriptor);
                }
            }
        }
        addModules(StreamEx.of(moduleInfos.values()).map(info -> info.descriptor).toList());
    } catch (ProcessCanceledException ignored) {
    } finally {
        myProgress.popState();
    }
}
Also used : DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) java.util(java.util) ContainerUtil(com.intellij.util.containers.ContainerUtil) ReadAction(com.intellij.openapi.application.ReadAction) StringBuilderSpinAllocator(com.intellij.util.StringBuilderSpinAllocator) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProjectManager(com.intellij.openapi.project.ProjectManager) ZipFile(java.util.zip.ZipFile) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ZipEntry(java.util.zip.ZipEntry) JavaSourceRootDetectionUtil(com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil) Lexer(com.intellij.lexer.Lexer) LanguageLevel(com.intellij.pom.java.LanguageLevel) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot) IncorrectOperationException(com.intellij.util.IncorrectOperationException) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) JavaFileType(com.intellij.ide.highlighter.JavaFileType) DetectedProjectRoot(com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) StreamEx(one.util.streamex.StreamEx) JavaParserDefinition(com.intellij.lang.java.JavaParserDefinition) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) DetectedSourceRoot(com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot) Consumer(com.intellij.util.Consumer) JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot) ZipFile(java.util.zip.ZipFile) File(java.io.File) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 4 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 5 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