Search in sources :

Example 1 with ModifiableModuleModel

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");
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module)

Example 2 with ModifiableModuleModel

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);
}
Also used : Project(com.intellij.openapi.project.Project) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) SmartList(com.intellij.util.SmartList) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 3 with ModifiableModuleModel

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 4 with ModifiableModuleModel

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();
    }
}
Also used : Project(com.intellij.openapi.project.Project) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel)

Example 5 with ModifiableModuleModel

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();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)45 Module (com.intellij.openapi.module.Module)30 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 ModuleManager (com.intellij.openapi.module.ModuleManager)10 Project (com.intellij.openapi.project.Project)9 NotNull (org.jetbrains.annotations.NotNull)8 File (java.io.File)6 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5 Result (com.intellij.openapi.application.Result)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (aQute.bnd.build.Project)2 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)2