use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-community by JetBrains.
the class CloudGitChooseAccountStepImpl method updateDataModel.
@Override
public void updateDataModel() {
super.updateDataModel();
final MultiMap<CloudGitProjectRoot, DetectedSourceRoot> project2sourceRoots = new MultiMap<>();
new RootIterator() {
CloudGitProjectRoot lastProjectRoot = null;
@Override
protected void processProjectRoot(CloudGitProjectRoot root) {
lastProjectRoot = root;
project2sourceRoots.put(lastProjectRoot, new ArrayList<>());
}
@Override
protected void processJavaSourceRoot(DetectedSourceRoot root) {
project2sourceRoots.putValue(lastProjectRoot, root);
}
}.iterate();
List<ModuleDescriptor> modules = new ArrayList<>(myProjectDescriptor.getModules());
for (Map.Entry<CloudGitProjectRoot, Collection<DetectedSourceRoot>> project2sourceRootsEntry : project2sourceRoots.entrySet()) {
final CloudGitProjectRoot projectRoot = project2sourceRootsEntry.getKey();
final File directory = projectRoot.getDirectory();
ModuleDescriptor moduleDescriptor = new ModuleDescriptor(directory, StdModuleTypes.JAVA, project2sourceRootsEntry.getValue());
final String applicationName = projectRoot.getApplicationName();
moduleDescriptor.addConfigurationUpdater(new ModuleBuilder.ModuleConfigurationUpdater() {
@Override
public void update(@NotNull final Module module, @NotNull ModifiableRootModel rootModel) {
final MessageBusConnection connection = module.getProject().getMessageBus().connect();
connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {
@Override
public void moduleAdded(@NotNull Project project, @NotNull Module addedModule) {
if (addedModule == module) {
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> onModuleAdded(module));
connection.disconnect();
}
}
});
}
private void onModuleAdded(Module module) {
createRunConfiguration(module, applicationName);
GitInit.refreshAndConfigureVcsMappings(module.getProject(), projectRoot.getRepositoryRoot(), directory.getAbsolutePath());
}
});
modules.add(moduleDescriptor);
}
myProjectDescriptor.setModules(modules);
}
use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot 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.DetectedSourceRoot in project intellij-community by JetBrains.
the class ModuleInsight method merge.
public void merge(final ModuleDescriptor mainModule, final ModuleDescriptor module) {
for (File contentRoot : module.getContentRoots()) {
final File _contentRoot = appendContentRoot(mainModule, contentRoot);
final Collection<DetectedSourceRoot> sources = module.getSourceRoots(contentRoot);
for (DetectedSourceRoot source : sources) {
mainModule.addSourceRoot(_contentRoot, source);
}
}
for (File jar : module.getLibraryFiles()) {
mainModule.addLibraryFile(jar);
}
// fix forward dependencies
for (ModuleDescriptor dependency : module.getDependencies()) {
if (!mainModule.equals(dependency)) {
// avoid self-dependencies
mainModule.addDependencyOn(dependency);
}
}
myModules.remove(module);
// fix back dependencies
for (ModuleDescriptor moduleDescr : myModules) {
if (moduleDescr.getDependencies().contains(module)) {
moduleDescr.removeDependencyOn(module);
if (!moduleDescr.equals(mainModule)) {
// avoid self-dependencies
moduleDescr.addDependencyOn(mainModule);
}
}
}
}
use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot in project intellij-community by JetBrains.
the class ModuleInsight method scanModules.
public void scanModules() {
myProgress.setIndeterminate(true);
final Map<File, ModuleDescriptor> contentRootToModules = new HashMap<>();
try {
myProgress.pushState();
List<DetectedSourceRoot> processedRoots = new ArrayList<>();
for (DetectedSourceRoot root : getSourceRootsToScan()) {
final File sourceRoot = root.getDirectory();
if (isIgnoredName(sourceRoot)) {
continue;
}
myProgress.setText("Scanning " + sourceRoot.getPath());
final HashSet<String> usedPackages = new HashSet<>();
mySourceRootToReferencedPackagesMap.put(sourceRoot, usedPackages);
final HashSet<String> selfPackages = new HashSet<>();
addExportedPackages(sourceRoot, selfPackages);
scanSources(sourceRoot, ProjectFromSourcesBuilderImpl.getPackagePrefix(root), usedPackages, selfPackages);
usedPackages.removeAll(selfPackages);
processedRoots.add(root);
}
myProgress.popState();
myProgress.pushState();
myProgress.setText("Building modules layout...");
for (DetectedSourceRoot sourceRoot : processedRoots) {
final File srcRoot = sourceRoot.getDirectory();
final File moduleContentRoot = isEntryPointRoot(srcRoot) ? srcRoot : srcRoot.getParentFile();
ModuleDescriptor moduleDescriptor = contentRootToModules.get(moduleContentRoot);
if (moduleDescriptor != null) {
moduleDescriptor.addSourceRoot(moduleContentRoot, sourceRoot);
} else {
moduleDescriptor = createModuleDescriptor(moduleContentRoot, Collections.singletonList(sourceRoot));
contentRootToModules.put(moduleContentRoot, moduleDescriptor);
}
}
buildModuleDependencies(contentRootToModules);
myProgress.popState();
} catch (ProcessCanceledException ignored) {
}
addModules(contentRootToModules.values());
}
use of com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot 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);
}
Aggregations