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();
}
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;
}
Aggregations