mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-94764: remove undesirable modules + consider entry root as module root
GitOrigin-RevId: e753310618dad64fd001c8bd51fe36f4966964cc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6d4dbf40c0
commit
aa4500aaa6
@@ -1,7 +1,6 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.util.importProject;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedProjectRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.DetectedSourceRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.impl.ProjectFromSourcesBuilderImpl;
|
||||
@@ -45,7 +44,6 @@ public abstract class ModuleInsight {
|
||||
private List<LibraryDescriptor> myLibraries;
|
||||
private final Set<String> myExistingModuleNames;
|
||||
private final Set<String> myExistingProjectLibraryNames;
|
||||
private static final Set<String> ourModuleUndesirableNames = ImmutableSet.of("src");
|
||||
|
||||
public ModuleInsight(@Nullable final ProgressIndicator progress, Set<String> existingModuleNames, Set<String> existingProjectLibraryNames) {
|
||||
myExistingModuleNames = existingModuleNames;
|
||||
@@ -113,7 +111,7 @@ public abstract class ModuleInsight {
|
||||
Map<File, ModuleCandidate> rootToModule = new HashMap<>();
|
||||
for (DetectedSourceRoot sourceRoot : processedRoots) {
|
||||
final File srcRoot = sourceRoot.getDirectory();
|
||||
final File moduleContentRoot = suggestModuleRoot(srcRoot);
|
||||
final File moduleContentRoot = isEntryPointRoot(srcRoot) ? srcRoot : srcRoot.getParentFile();
|
||||
rootToModule.computeIfAbsent(moduleContentRoot, file -> new ModuleCandidate(moduleContentRoot)).myRoots.add(sourceRoot);
|
||||
}
|
||||
maximizeModuleFolders(rootToModule.values());
|
||||
@@ -150,41 +148,26 @@ public abstract class ModuleInsight {
|
||||
if (!dirToChildRootCount.adjustValue(file, 1)) {
|
||||
dirToChildRootCount.put(file, 1);
|
||||
}
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
for (ModuleCandidate module : modules) {
|
||||
File moduleRoot = module.myFolder;
|
||||
Ref<File> adjustedRootRef = new Ref<>(module.myFolder);
|
||||
walkParents(moduleRoot,
|
||||
file -> isEntryPointRoot(file) || dirToChildRootCount.get(file) != 1,
|
||||
file -> adjustedRootRef.set(file),
|
||||
false
|
||||
);
|
||||
File current = moduleRoot;
|
||||
while (dirToChildRootCount.get(current) == 1) {
|
||||
adjustedRootRef.set(current);
|
||||
if (isEntryPointRoot(current)) break;
|
||||
current = current.getParentFile();
|
||||
}
|
||||
module.myFolder = adjustedRootRef.get();
|
||||
}
|
||||
}
|
||||
|
||||
private static void walkParents(@NotNull File file, Predicate<File> stopCondition, @NotNull Consumer<File> fileConsumer, boolean includeStop) {
|
||||
private static void walkParents(@NotNull File file, Predicate<File> stopCondition, @NotNull Consumer<File> fileConsumer) {
|
||||
File current = file;
|
||||
while (true) {
|
||||
if (!includeStop) {
|
||||
if (stopCondition.test(current)) break;
|
||||
fileConsumer.consume(current);
|
||||
} else {
|
||||
fileConsumer.consume(current);
|
||||
if (stopCondition.test(current)) break;
|
||||
}
|
||||
current = current.getParentFile();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private File suggestModuleRoot(@NotNull File srcRoot) {
|
||||
File current = isEntryPointRoot(srcRoot) ? srcRoot : srcRoot.getParentFile();
|
||||
while (true) {
|
||||
if (isEntryPointRoot(current) || !ourModuleUndesirableNames.contains(current.getName())) {
|
||||
return current;
|
||||
}
|
||||
fileConsumer.consume(current);
|
||||
if (stopCondition.test(current)) break;
|
||||
current = current.getParentFile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,15 @@ public class ImportActionTest extends ProjectWizardTestCase<AddModuleWizard> {
|
||||
assertEquals(path + "/inner/m2", contentRoots.get(1).getPath());
|
||||
}
|
||||
|
||||
public void testSingleModuleInProject() {
|
||||
String path = getModuleMaximizationPath("single");
|
||||
Project project = importProjectFrom(path, null, new ImportFromSourcesProvider()).getProject();
|
||||
Module[] modules = ModuleManager.getInstance(project).getModules();
|
||||
assertEquals(1, modules.length);
|
||||
List<VirtualFile> contentRoots = getSingleContentRoots(modules);
|
||||
assertEquals(path, contentRoots.get(0).getPath());
|
||||
}
|
||||
|
||||
private static String getModuleMaximizationPath(String projectName) {
|
||||
String basePath = "/ide/importAction/moduleMaximization";
|
||||
return PathManagerEx.getTestDataPath(basePath + "/" + projectName);
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
class Foo {}
|
||||
+1
@@ -0,0 +1 @@
|
||||
class FooTest {}
|
||||
Reference in New Issue
Block a user