Search in sources :

Example 36 with ContentEntry

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

the class NonAndroidSourceTypeNode method getSourceFolders.

private List<VirtualFile> getSourceFolders() {
    ModuleRootManager rootManager = ModuleRootManager.getInstance(getValue());
    List<VirtualFile> folders = Lists.newArrayList();
    ContentEntry[] contentEntries = rootManager.getContentEntries();
    for (ContentEntry entry : contentEntries) {
        List<SourceFolder> sources = entry.getSourceFolders(mySourceType.rootType);
        for (SourceFolder folder : sources) {
            VirtualFile file = folder.getFile();
            if (file != null) {
                folders.add(file);
            }
        }
    }
    return folders;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager)

Example 37 with ContentEntry

use of com.intellij.openapi.roots.ContentEntry 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 38 with ContentEntry

use of com.intellij.openapi.roots.ContentEntry 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 39 with ContentEntry

use of com.intellij.openapi.roots.ContentEntry 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)

Example 40 with ContentEntry

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

the class DartHighlightingTest method excludeFolder.

private void excludeFolder(final String relPath) {
    ApplicationManager.getApplication().runWriteAction(() -> {
        final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
        try {
            final ContentEntry[] contentEntries = model.getContentEntries();
            contentEntries[0].addExcludeFolder(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

ContentEntry (com.intellij.openapi.roots.ContentEntry)61 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)27 Module (com.intellij.openapi.module.Module)17 File (java.io.File)16 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)11 SourceFolder (com.intellij.openapi.roots.SourceFolder)7 NotNull (org.jetbrains.annotations.NotNull)7 FilePaths.findParentContentEntry (com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry)4 IOException (java.io.IOException)4 Nullable (org.jetbrains.annotations.Nullable)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)3 Project (com.intellij.openapi.project.Project)3 CompilerModuleExtension (com.intellij.openapi.roots.CompilerModuleExtension)3 JavaModuleContentRoot (com.android.tools.idea.gradle.model.java.JavaModuleContentRoot)2 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)2 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 PsiFile (com.intellij.psi.PsiFile)2 ArrayList (java.util.ArrayList)2