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