Search in sources :

Example 51 with ContentEntry

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

the class CommonContentEntriesEditor method addContentEntries.

protected List<ContentEntry> addContentEntries(final VirtualFile[] files) {
    List<ContentEntry> contentEntries = new ArrayList<>();
    for (final VirtualFile file : files) {
        if (isAlreadyAdded(file)) {
            continue;
        }
        final ContentEntry contentEntry = getModel().addContentEntry(file);
        contentEntries.add(contentEntry);
    }
    return contentEntries;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) ArrayList(java.util.ArrayList)

Example 52 with ContentEntry

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

the class CommonContentEntriesEditor method addContentEntryPanels.

protected void addContentEntryPanels(ContentEntry[] contentEntriesArray) {
    for (ContentEntry contentEntry : contentEntriesArray) {
        addContentEntryPanel(contentEntry.getUrl());
    }
    myEditorsPanel.revalidate();
    myEditorsPanel.repaint();
    selectContentEntry(contentEntriesArray[contentEntriesArray.length - 1].getUrl());
}
Also used : ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 53 with ContentEntry

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

the class IdeFrameFixture method getSourceFolderRelativePaths.

@NotNull
public Collection<String> getSourceFolderRelativePaths(@NotNull String moduleName, @NotNull final JpsModuleSourceRootType<?> sourceType) {
    final Set<String> paths = new HashSet<>();
    Module module = getModule(moduleName);
    final 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(relativePath);
                        }
                    }
                }
            } finally {
                rootModel.dispose();
            }
        }
    });
    return paths;
}
Also used : ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) 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) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 54 with ContentEntry

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

the class ConfigurationsTest method addSourcePath.

private static void addSourcePath(Module module, String path, boolean testSource) {
    final ContentEntry entry = ModuleRootManager.getInstance(module).getContentEntries()[0];
    VirtualFile child = entry.getFile().findChild(path);
    assertNotNull(child);
    PsiTestUtil.addSourceRoot(module, child, testSource);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 55 with ContentEntry

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

the class ContentRootDataService method importData.

private static void importData(@NotNull IdeModifiableModelsProvider modelsProvider, @NotNull final Collection<DataNode<ContentRootData>> data, @NotNull final Module module, boolean forceDirectoriesCreation) {
    final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
    final ContentEntry[] contentEntries = modifiableRootModel.getContentEntries();
    final Map<String, ContentEntry> contentEntriesMap = ContainerUtilRt.newHashMap();
    for (ContentEntry contentEntry : contentEntries) {
        contentEntriesMap.put(contentEntry.getUrl(), contentEntry);
    }
    boolean createEmptyContentRootDirectories = forceDirectoriesCreation;
    if (!forceDirectoriesCreation && !data.isEmpty()) {
        ProjectSystemId projectSystemId = data.iterator().next().getData().getOwner();
        AbstractExternalSystemSettings externalSystemSettings = ExternalSystemApiUtil.getSettings(module.getProject(), projectSystemId);
        String path = module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
        if (path != null) {
            ExternalProjectSettings projectSettings = externalSystemSettings.getLinkedProjectSettings(path);
            createEmptyContentRootDirectories = projectSettings != null && projectSettings.isCreateEmptyContentRootDirectories();
        }
    }
    final Set<ContentEntry> importedContentEntries = ContainerUtil.newIdentityTroveSet();
    for (final DataNode<ContentRootData> node : data) {
        final ContentRootData contentRoot = node.getData();
        final ContentEntry contentEntry = findOrCreateContentRoot(modifiableRootModel, contentRoot.getRootPath());
        if (!importedContentEntries.contains(contentEntry)) {
            // clear source folders but do not remove existing excluded folders
            contentEntry.clearSourceFolders();
            importedContentEntries.add(contentEntry);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Importing content root '%s' for module '%s'", contentRoot.getRootPath(), module.getName()));
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE_GENERATED)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, true, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST_GENERATED)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, true, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.RESOURCE)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.RESOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST_RESOURCE)) {
            createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.TEST_RESOURCE, false, createEmptyContentRootDirectories);
        }
        for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.EXCLUDED)) {
            createExcludedRootIfAbsent(contentEntry, path, module.getName(), module.getProject());
        }
        contentEntriesMap.remove(contentEntry.getUrl());
    }
    for (ContentEntry contentEntry : contentEntriesMap.values()) {
        modifiableRootModel.removeContentEntry(contentEntry);
    }
}
Also used : ContentRootData(com.intellij.openapi.externalSystem.model.project.ContentRootData) SourceRoot(com.intellij.openapi.externalSystem.model.project.ContentRootData.SourceRoot) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) 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