use of com.intellij.openapi.module.ModuleManager in project intellij-community by JetBrains.
the class MvcModuleStructureUtil method removeAuxiliaryModule.
public static void removeAuxiliaryModule(Module toRemove) {
List<ModifiableRootModel> usingModels = new SmartList<>();
Project project = toRemove.getProject();
ModuleManager moduleManager = ModuleManager.getInstance(project);
for (Module module : moduleManager.getModules()) {
if (module == toRemove) {
continue;
}
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
for (OrderEntry entry : moduleRootManager.getOrderEntries()) {
if (entry instanceof ModuleOrderEntry && toRemove == ((ModuleOrderEntry) entry).getModule()) {
usingModels.add(moduleRootManager.getModifiableModel());
break;
}
}
}
final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
ModuleDeleteProvider.removeModule(toRemove, null, usingModels, moduleModel);
ModifiableModelCommitter.multiCommit(usingModels, moduleModel);
}
use of com.intellij.openapi.module.ModuleManager in project intellij-community by JetBrains.
the class MvcModuleStructureUtil method generateUniqueModuleName.
private static String generateUniqueModuleName(@NotNull Project project, String prefix) {
ModuleManager manager = ModuleManager.getInstance(project);
int i = 0;
do {
String res = i == 0 ? prefix : prefix + i;
i++;
if (manager.findModuleByName(res) == null)
return res;
} while (true);
}
use of com.intellij.openapi.module.ModuleManager in project intellij-community by JetBrains.
the class ProjectImpl method distributeProgress.
private void distributeProgress() {
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
if (indicator == null)
return;
ModuleManager moduleManager = ModuleManager.getInstance(this);
if (!(moduleManager instanceof ModuleManagerImpl)) {
return;
}
double toDistribute = 1 - indicator.getFraction();
int modulesCount = ((ModuleManagerImpl) moduleManager).getModulePathsCount();
EditorsSplitters splitters = ((FileEditorManagerImpl) FileEditorManager.getInstance(this)).getMainSplitters();
int editors = splitters.getEditorsCount();
double modulesPart = ourClassesAreLoaded || editors == 0 ? toDistribute : toDistribute * 0.5;
if (modulesCount != 0) {
double step = modulesPart / modulesCount;
((ModuleManagerImpl) moduleManager).setProgressStep(step);
}
if (editors != 0) {
splitters.setProgressStep(toDistribute - modulesPart / editors);
}
}
use of com.intellij.openapi.module.ModuleManager in project intellij-community by JetBrains.
the class ModuleVcsDetector method autoDetectVcsMappings.
private void autoDetectVcsMappings(final boolean tryMapPieces) {
Set<AbstractVcs> usedVcses = new HashSet<>();
Map<VirtualFile, AbstractVcs> vcsMap = new HashMap<>();
final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
for (Module module : moduleManager.getModules()) {
final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
for (VirtualFile file : files) {
AbstractVcs contentRootVcs = myVcsManager.findVersioningVcs(file);
if (contentRootVcs != null) {
vcsMap.put(file, contentRootVcs);
}
usedVcses.add(contentRootVcs);
}
}
if (usedVcses.size() == 1) {
// todo I doubt this is correct, see IDEA-50527
final AbstractVcs[] abstractVcses = usedVcses.toArray(new AbstractVcs[1]);
final Module[] modules = moduleManager.getModules();
final Set<String> contentRoots = new HashSet<>();
for (Module module : modules) {
final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
for (VirtualFile root : roots) {
contentRoots.add(root.getPath());
}
}
if (abstractVcses[0] != null) {
final List<VcsDirectoryMapping> vcsDirectoryMappings = new ArrayList<>(myVcsManager.getDirectoryMappings());
for (Iterator<VcsDirectoryMapping> iterator = vcsDirectoryMappings.iterator(); iterator.hasNext(); ) {
final VcsDirectoryMapping mapping = iterator.next();
if (!contentRoots.contains(mapping.getDirectory())) {
iterator.remove();
}
}
myVcsManager.setAutoDirectoryMapping("", abstractVcses[0].getName());
for (VcsDirectoryMapping mapping : vcsDirectoryMappings) {
myVcsManager.removeDirectoryMapping(mapping);
}
myVcsManager.cleanupMappings();
}
} else if (tryMapPieces) {
for (Map.Entry<VirtualFile, AbstractVcs> entry : vcsMap.entrySet()) {
myVcsManager.setAutoDirectoryMapping(entry.getKey().getPath(), entry.getValue() == null ? "" : entry.getValue().getName());
}
myVcsManager.cleanupMappings();
}
}
use of com.intellij.openapi.module.ModuleManager in project intellij-community by JetBrains.
the class ModuleTestCase method tearDown.
@Override
protected void tearDown() throws Exception {
try {
if (!myModulesToDispose.isEmpty()) {
List<Throwable> errors = new SmartList<>();
WriteAction.run(() -> {
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
for (Module module : myModulesToDispose) {
try {
String moduleName = module.getName();
if (moduleManager.findModuleByName(moduleName) != null) {
moduleManager.disposeModule(module);
}
} catch (Throwable e) {
errors.add(e);
}
}
});
CompoundRuntimeException.throwIfNotEmpty(errors);
}
} finally {
myModulesToDispose.clear();
super.tearDown();
}
}
Aggregations