use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class ReimportingTest method testKeepingModuleGroups.
public void testKeepingModuleGroups() throws Exception {
final Module m = getModule("project");
new WriteCommandAction.Simple(myProject) {
@Override
protected void run() throws Throwable {
ModifiableModuleModel model = ModuleManager.getInstance(myProject).getModifiableModel();
model.setModuleGroupPath(m, new String[] { "group" });
model.commit();
}
}.execute().throwException();
importProject();
assertModuleGroupPath("project", "group");
}
use of com.intellij.openapi.module.ModifiableModuleModel 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.ModifiableModuleModel in project intellij-elixir by KronicDeth.
the class MixProjectImportBuilder method commit.
@Override
public List<Module> commit(@NotNull Project project, @Nullable ModifiableModuleModel moduleModel, @NotNull ModulesProvider modulesProvider, @Nullable ModifiableArtifactModel artifactModel) {
Set<String> selectedAppNames = ContainerUtil.newHashSet();
for (ImportedOtpApp importedOtpApp : mySelectedOtpApps) {
selectedAppNames.add(importedOtpApp.getName());
}
Sdk projectSdk = fixProjectSdk(project);
List<Module> createModules = new ArrayList<Module>();
final List<ModifiableRootModel> createdRootModels = new ArrayList<ModifiableRootModel>();
final ModifiableModuleModel obtainedModuleModel = moduleModel != null ? moduleModel : ModuleManager.getInstance(project).getModifiableModel();
VirtualFile _buildDir = null;
for (ImportedOtpApp importedOtpApp : mySelectedOtpApps) {
// add Module
VirtualFile ideaModuleDir = importedOtpApp.getRoot();
String ideaModuleFile = ideaModuleDir.getCanonicalPath() + File.separator + importedOtpApp.getName() + ".iml";
Module module = obtainedModuleModel.newModule(ideaModuleFile, ElixirModuleType.getInstance().getId());
createModules.add(module);
// add rootModule
importedOtpApp.setModule(module);
if (importedOtpApp.getIdeaModuleFile() == null) {
ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
// Make it inherit SDK from the project.
rootModel.inheritSdk();
// Initialize source and test paths.
ContentEntry content = rootModel.addContentEntry(importedOtpApp.getRoot());
addSourceDirToContent(content, ideaModuleDir, "lib", false);
addSourceDirToContent(content, ideaModuleDir, "test", true);
// Exclude standard folders
// excludeDirFromContent(content, ideaModuleDir, "_build");
// Initialize output paths according to mix conventions.
CompilerModuleExtension compilerModuleExt = rootModel.getModuleExtension(CompilerModuleExtension.class);
compilerModuleExt.inheritCompilerOutputPath(false);
_buildDir = myProjectRoot != null && myProjectRoot.equals(ideaModuleDir) ? ideaModuleDir : ideaModuleDir.getParent().getParent();
compilerModuleExt.setCompilerOutputPath(_buildDir + StringUtil.replace("/_build/dev/lib/" + importedOtpApp.getName() + "/ebin", "/", File.separator));
compilerModuleExt.setCompilerOutputPathForTests(_buildDir + StringUtil.replace("/_build/test/lib/" + importedOtpApp.getName() + "/ebin", "/", File.separator));
createdRootModels.add(rootModel);
// Set inter-module dependencies
resolveModuleDeps(rootModel, importedOtpApp, projectSdk, selectedAppNames);
}
}
// Commit project structure.
LOG.info("Commit project structure");
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
for (ModifiableRootModel rootModel : createdRootModels) {
rootModel.commit();
}
obtainedModuleModel.commit();
}
});
MixSettings.getInstance(project).setMixPath(myMixPath);
if (myIsImportingProject) {
ElixirCompilerSettings.getInstance(project).setUseMixCompilerEnabled(true);
}
CompilerWorkspaceConfiguration.getInstance(project).CLEAR_OUTPUT_DIRECTORY = false;
return createModules;
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class ModuleRootManagerImpl method commitModel.
void commitModel(RootModelImpl rootModel) {
ApplicationManager.getApplication().assertWriteAccessAllowed();
LOG.assertTrue(rootModel.myModuleRootManager == this);
boolean changed = rootModel.isChanged();
final Project project = myModule.getProject();
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel();
ModifiableModelCommitter.multiCommit(Collections.singletonList(rootModel), moduleModel);
if (changed) {
stateChanged();
}
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class PsiTestUtil method addModule.
public static Module addModule(Project project, ModuleType type, String name, VirtualFile root) {
return new WriteCommandAction<Module>(project) {
@Override
protected void run(@NotNull Result<Module> result) throws Throwable {
String moduleName;
ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel();
try {
moduleName = moduleModel.newModule(root.getPath() + "/" + name + ".iml", type.getId()).getName();
moduleModel.commit();
} catch (Throwable t) {
moduleModel.dispose();
throw t;
}
Module dep = ModuleManager.getInstance(project).findModuleByName(moduleName);
assert dep != null : moduleName;
ModifiableRootModel model = ModuleRootManager.getInstance(dep).getModifiableModel();
try {
model.addContentEntry(root).addSourceFolder(root, false);
model.commit();
} catch (Throwable t) {
model.dispose();
throw t;
}
result.setResult(dep);
}
}.execute().getResultObject();
}
Aggregations