Search in sources :

Example 21 with ContentEntry

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

the class GradleSyncIntegrationTest method LoadPlainJavaProject.

// https://code.google.com/p/android/issues/detail?id=233038
public void LoadPlainJavaProject() throws Exception {
    prepareProjectForImport(PURE_JAVA_PROJECT);
    Project project = getProject();
    importProject(project.getName(), getBaseDirPath(project), null);
    Module[] modules = ModuleManager.getInstance(project).getModules();
    for (Module module : modules) {
        ContentEntry[] entries = ModuleRootManager.getInstance(module).getContentEntries();
        assertThat(entries).named(module.getName() + " should have content entries").isNotEmpty();
    }
}
Also used : Project(com.intellij.openapi.project.Project) ContentEntry(com.intellij.openapi.roots.ContentEntry) Module(com.intellij.openapi.module.Module)

Example 22 with ContentEntry

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

the class ContentRootsModuleSetupStepTest method indexByName.

@NotNull
private static Map<String, ContentEntry> indexByName(@NotNull ContentEntry[] contentEntries) {
    Map<String, ContentEntry> entriesByName = new HashMap<>();
    for (ContentEntry entry : contentEntries) {
        VirtualFile file = entry.getFile();
        assertNotNull(file);
        entriesByName.put(file.getName(), entry);
    }
    return entriesByName;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(java.util.HashMap) ContentEntry(com.intellij.openapi.roots.ContentEntry) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with ContentEntry

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

the class AngularJSProjectConfigurator method configureProject.

@Override
public void configureProject(Project project, @NotNull VirtualFile baseDir, Ref<Module> moduleRef) {
    final ModuleManager moduleManager = ModuleManager.getInstance(project);
    final Module[] modules = moduleManager.getModules();
    if (modules.length == 1) {
        final VirtualFile cliJson = baseDir.findChild(ANGULAR_CLI_JSON);
        final ModifiableRootModel model = ModuleRootManager.getInstance(modules[0]).getModifiableModel();
        final ContentEntry entry = MarkRootActionBase.findContentEntry(model, baseDir);
        if (entry != null && cliJson != null) {
            excludeDefault(baseDir, entry);
            ApplicationManager.getApplication().runWriteAction(() -> {
                model.commit();
                project.save();
            });
        } else {
            model.dispose();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 24 with ContentEntry

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

the class ContentRootsModuleSetupStepTest method testSetUpNativeModule.

public void testSetUpNativeModule() {
    // Simulate this is a native module
    NdkModuleModel ndkModuleModel = mock(NdkModuleModel.class);
    when(ndkModuleModel.getSelectedVariant()).thenReturn(mock(NdkModuleModel.NdkVariant.class));
    NdkFacet facet = addNativeAndroidFacet(myModelsProvider);
    facet.setNdkModuleModel(ndkModuleModel);
    ModifiableRootModel moduleModel = myModelsProvider.getModifiableRootModel(getModule());
    when(myFactory.create(myAndroidModel, moduleModel, true)).thenReturn(mySetup);
    mySetupStep.setUpModule(getModule(), myModelsProvider, myAndroidModel, null, null);
    Map<String, ContentEntry> entriesByName = indexByName(moduleModel.getContentEntries());
    // Content roots "a", "b", and "c" should be there, since they did not get removed because this is a native model.
    assertThat(entriesByName).hasSize(4);
    assertThat(entriesByName).containsKey("a");
    assertThat(entriesByName).containsKey("b");
    assertThat(entriesByName).containsKey("c");
    ContentEntry newContentEntry = entriesByName.get(myModuleFolder.getName());
    assertNotNull(newContentEntry);
    ApplicationManager.getApplication().runWriteAction(myModelsProvider::commit);
    verify(mySetup).execute(Collections.singletonList(newContentEntry));
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel)

Example 25 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)

Aggregations

ContentEntry (com.intellij.openapi.roots.ContentEntry)60 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)27 VirtualFile (com.intellij.openapi.vfs.VirtualFile)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 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 SyncIssue (com.android.builder.model.SyncIssue)1