Search in sources :

Example 56 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class CreateNewModuleTask method perform.

@Override
public Exception perform() {
    final Module depModule = ApplicationManager.getApplication().runWriteAction(new Computable<Module>() {

        @Override
        public Module compute() {
            final Module depModule = ModuleManager.getInstance(myProject).newModule(myContentRoot.getPath() + '/' + myContentRoot.getName() + ".iml", StdModuleTypes.JAVA.getId());
            final ModifiableRootModel model = ModuleRootManager.getInstance(depModule).getModifiableModel();
            model.addContentEntry(myContentRoot);
            model.commit();
            return depModule;
        }
    });
    if (AndroidFacet.getInstance(depModule) == null) {
        AndroidUtils.addAndroidFacetInWriteAction(depModule, myContentRoot, true);
    }
    AndroidSdkUtils.setupAndroidPlatformIfNecessary(depModule, false);
    setDepModule(depModule);
    return null;
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Module(com.intellij.openapi.module.Module)

Example 57 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class JavaModuleSetupTest method testSetUpAndroidModuleWithoutVariants.

public void testSetUpAndroidModuleWithoutVariants() {
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    when(myJavaModuleModel.isAndroidModuleWithoutVariants()).thenReturn(true);
    Module module = getModule();
    // Add AndroidFacet to verify that is removed.
    createAndAddAndroidFacet(module);
    ApplicationManager.getApplication().runWriteAction(() -> {
        // Add source folders and excluded folders to verify that they are removed.
        ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
        ContentEntry contentEntry = modifiableModel.addContentEntry("file://fakePath");
        contentEntry.addSourceFolder("file://fakePath/sourceFolder", false);
        contentEntry.addExcludeFolder("file://fakePath/excludedFolder");
        modifiableModel.commit();
    });
    myModuleSetup.setUpModule(module, modelsProvider, myJavaModuleModel, myModuleModels, null);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    // Verify AndroidFacet was removed.
    assertNull(AndroidFacet.getInstance(module));
    // Verify source folders and excluded folders were removed.
    ContentEntry[] contentEntries = ModuleRootManager.getInstance(module).getContentEntries();
    assertThat(contentEntries).hasLength(1);
    ContentEntry contentEntry = contentEntries[0];
    assertThat(contentEntry.getSourceFolders()).isEmpty();
    assertThat(contentEntry.getExcludeFolderUrls()).isEmpty();
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) Module(com.intellij.openapi.module.Module)

Example 58 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.

the class ContentRootsModuleSetupStepTest method addContentRoots.

private void addContentRoots(@NotNull String... names) throws IOException {
    assertThat(names).isNotEmpty();
    VirtualFile projectFolder = getProject().getBaseDir();
    Module module = getModule();
    ModuleRootManager manager = ModuleRootManager.getInstance(module);
    ModifiableRootModel modifiableModel = manager.getModifiableModel();
    for (String name : names) {
        VirtualFile folder = findOrCreateChildFolder(projectFolder, name);
        modifiableModel.addContentEntry(folder);
    }
    ApplicationManager.getApplication().runWriteAction(modifiableModel::commit);
    ContentEntry[] entries = manager.getContentEntries();
    assertThat(entries).hasLength(names.length);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module)

Example 59 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-plugins by JetBrains.

the class DartResolveTest method configureLibrary.

private void configureLibrary(final VirtualFile root) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
        final Library library = model.getModuleLibraryTable().createLibrary();
        final Library.ModifiableModel libModel = library.getModifiableModel();
        libModel.addRoot(root, OrderRootType.CLASSES);
        libModel.commit();
        model.getContentEntries()[0].addExcludeFolder(root);
        model.commit();
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Library(com.intellij.openapi.roots.libraries.Library)

Example 60 with ModifiableRootModel

use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-plugins by JetBrains.

the class DartHighlightingTest method unexcludeFolder.

private void unexcludeFolder(final String relPath) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
        try {
            final ContentEntry[] contentEntries = model.getContentEntries();
            contentEntries[0].removeExcludeFolder(contentEntries[0].getUrl() + "/" + relPath);
            model.commit();
        } finally {
            if (!model.isDisposed()) {
                model.dispose();
            }
        }
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Aggregations

ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)102 Module (com.intellij.openapi.module.Module)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 ContentEntry (com.intellij.openapi.roots.ContentEntry)27 File (java.io.File)18 Library (com.intellij.openapi.roots.libraries.Library)15 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)14 ModuleManager (com.intellij.openapi.module.ModuleManager)8 Sdk (com.intellij.openapi.projectRoots.Sdk)8 IOException (java.io.IOException)8 NotNull (org.jetbrains.annotations.NotNull)8 OrderEntry (com.intellij.openapi.roots.OrderEntry)7 Project (com.intellij.openapi.project.Project)6 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)6 Nullable (org.jetbrains.annotations.Nullable)6 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)5 ConfigurationException (com.intellij.openapi.options.ConfigurationException)5 THashMap (gnu.trove.THashMap)5 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)4 AccessToken (com.intellij.openapi.application.AccessToken)4