Search in sources :

Example 11 with ContentEntry

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

the class ContentRootsModuleSetupStepTest method testSetUpModule.

public void testSetUpModule() {
    ModifiableRootModel moduleModel = myModelsProvider.getModifiableRootModel(getModule());
    when(myFactory.create(myAndroidModel, moduleModel, false)).thenReturn(mySetup);
    mySetupStep.setUpModule(getModule(), myModelsProvider, myAndroidModel, null, null);
    ContentEntry[] entries = moduleModel.getContentEntries();
    // Content roots "a", "b", and "c" should not be there, since they got removed.
    assertThat(entries).hasLength(1);
    assertEquals(myModuleFolder, entries[0].getFile());
    ApplicationManager.getApplication().runWriteAction(myModelsProvider::commit);
    verify(mySetup).execute(Arrays.asList(entries));
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 12 with ContentEntry

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

the class IdeFrameFixture method getSourceFolderRelativePaths.

/**
   * Returns a list of system independent paths
   */
@NotNull
public Collection<String> getSourceFolderRelativePaths(@NotNull String moduleName, @NotNull JpsModuleSourceRootType<?> sourceType) {
    Set<String> paths = Sets.newHashSet();
    Module module = getModule(moduleName);
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
            try {
                for (ContentEntry contentEntry : rootModel.getContentEntries()) {
                    for (SourceFolder folder : contentEntry.getSourceFolders()) {
                        JpsModuleSourceRootType<?> rootType = folder.getRootType();
                        if (rootType.equals(sourceType)) {
                            String path = urlToPath(folder.getUrl());
                            String relativePath = getRelativePath(myProjectPath, new File(toSystemDependentName(path)));
                            paths.add(PathUtil.toSystemIndependentName(relativePath));
                        }
                    }
                }
            } finally {
                rootModel.dispose();
            }
        }
    });
    return paths;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) SourceFolder(com.intellij.openapi.roots.SourceFolder) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) GradleUtil.getGradleBuildFile(com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ContentEntry

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

the class ContentRootsModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
    boolean hasNativeModel = hasNativeModel(module, ideModelsProvider, gradleModels);
    AndroidContentEntriesSetup setup = myContentEntriesSetupFactory.create(androidModel, moduleModel, hasNativeModel);
    List<ContentEntry> contentEntries = findContentEntries(moduleModel, androidModel, hasNativeModel);
    setup.execute(contentEntries);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 14 with ContentEntry

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

the class ContentEntriesSetup method addOrphans.

protected void addOrphans() {
    for (RootSourceFolder orphan : myOrphans) {
        File path = orphan.getPath();
        ContentEntry contentEntry = myModuleModel.addContentEntry(pathToIdeaUrl(path));
        addSourceFolder(contentEntry, path, orphan.getType(), orphan.isGenerated());
    }
}
Also used : ContentEntry(com.intellij.openapi.roots.ContentEntry) File(java.io.File)

Example 15 with ContentEntry

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

the class ContentEntriesSetup method addSourceFolder.

protected void addSourceFolder(@NotNull File folderPath, @NotNull Collection<ContentEntry> contentEntries, @NotNull JpsModuleSourceRootType type, boolean generated) {
    ContentEntry parent = findParentContentEntry(folderPath, contentEntries);
    if (parent == null) {
        myOrphans.add(new RootSourceFolder(folderPath, type, generated));
        return;
    }
    addSourceFolder(parent, folderPath, type, generated);
}
Also used : 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