Search in sources :

Example 26 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 27 with ContentEntry

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

the class FlashBuilderModuleImporter method handleRawSourcePath.

private void handleRawSourcePath(final ModifiableRootModel rootModel, final FlashBuilderProject fbProject, final String mainContentEntryUrl, final ContentEntry mainContentEntry, final Collection<ContentEntry> otherContentEntries, final String rawSourcePath) {
    final String sourcePath = getAbsolutePathWithLinksHandled(fbProject, rawSourcePath);
    final String sourceUrl = VfsUtilCore.pathToUrl(sourcePath);
    if (FileUtil.isAncestor(new File(VfsUtilCore.urlToPath(mainContentEntryUrl)), new File(VfsUtilCore.urlToPath(sourceUrl)), false)) {
        addSourceRoot(mainContentEntry, sourceUrl);
    } else {
        for (final ContentEntry otherContentEntry : otherContentEntries) {
            if (FileUtil.isAncestor(new File(VfsUtilCore.urlToPath(mainContentEntryUrl)), new File(VfsUtilCore.urlToPath(sourceUrl)), false)) {
                addSourceRoot(otherContentEntry, sourceUrl);
                return;
            }
        }
        final ContentEntry newContentEntry = rootModel.addContentEntry(sourceUrl);
        addSourceRoot(newContentEntry, sourceUrl);
        otherContentEntries.add(newContentEntry);
    }
}
Also used : ContentEntry(com.intellij.openapi.roots.ContentEntry) File(java.io.File)

Example 28 with ContentEntry

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

the class FlashBuilderModuleImporter method setupRoots.

private void setupRoots(final ModifiableRootModel rootModel, final FlashBuilderProject fbProject) {
    final String mainContentEntryUrl = VfsUtilCore.pathToUrl(fbProject.getProjectRootPath());
    final ContentEntry mainContentEntry = rootModel.addContentEntry(mainContentEntryUrl);
    final Collection<ContentEntry> otherContentEntries = new ArrayList<>();
    final Collection<String> sourcePaths = fbProject.getSourcePaths();
    if (sourcePaths.isEmpty()) {
        final VirtualFile contentRoot = mainContentEntry.getFile();
        final String mainClass = fbProject.getMainAppClassName();
        if (contentRoot != null && !StringUtil.isEmpty(mainClass) && (contentRoot.findChild(mainClass + ".mxml") != null || contentRoot.findChild(mainClass + ".as") != null)) {
            mainContentEntry.addSourceFolder(mainContentEntry.getUrl(), false);
        }
    } else {
        final List<String> locales = FlexCommonUtils.getOptionValues(fbProject.getAdditionalCompilerOptions(), "locale", "compiler.locale");
        final List<String> moreSourcePaths = FlexCommonUtils.getOptionValues(fbProject.getAdditionalCompilerOptions(), "source-path", "compiler.source-path");
        for (final String rawSourcePath : sourcePaths) {
            if (rawSourcePath.contains(FlexCommonUtils.LOCALE_TOKEN)) {
                for (String locale : locales) {
                    handleRawSourcePath(rootModel, fbProject, mainContentEntryUrl, mainContentEntry, otherContentEntries, rawSourcePath.replace(FlexCommonUtils.LOCALE_TOKEN, locale));
                }
            } else {
                handleRawSourcePath(rootModel, fbProject, mainContentEntryUrl, mainContentEntry, otherContentEntries, rawSourcePath);
            }
        }
        for (String sourcePath : moreSourcePaths) {
            if (sourcePath.contains(FlexCommonUtils.LOCALE_TOKEN)) {
                for (String locale : locales) {
                    final String path = getPathToSourceRootSetInAdditionalOptions(sourcePath.replace(FlexCommonUtils.LOCALE_TOKEN, locale), mainContentEntryUrl, mainContentEntry);
                    if (path != null) {
                        handleRawSourcePath(rootModel, fbProject, mainContentEntryUrl, mainContentEntry, otherContentEntries, path);
                    }
                }
            } else {
                final String path = getPathToSourceRootSetInAdditionalOptions(sourcePath, mainContentEntryUrl, mainContentEntry);
                if (path != null) {
                    handleRawSourcePath(rootModel, fbProject, mainContentEntryUrl, mainContentEntry, otherContentEntries, path);
                }
            }
        }
    }
}
Also used : ContentEntry(com.intellij.openapi.roots.ContentEntry)

Example 29 with ContentEntry

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

the class MultiModuleEditingTest method testRootsEditing.

public void testRootsEditing() {
    final MessageBusConnection connection = myProject.getMessageBus().connect();
    final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    final MyModuleListener moduleListener = new MyModuleListener();
    connection.subscribe(ProjectTopics.MODULES, moduleListener);
    final Module moduleA;
    final Module moduleB;
    {
        final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
        moduleA = moduleModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
        moduleB = moduleModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
        final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
        final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
        rootModelB.addModuleOrderEntry(moduleA);
        final ContentEntry contentEntryA = rootModelA.addContentEntry(getVirtualFileInTestData("a"));
        contentEntryA.addSourceFolder(getVirtualFileInTestData("a/src"), false);
        final ContentEntry contentEntryB = rootModelB.addContentEntry(getVirtualFileInTestData("b"));
        contentEntryB.addSourceFolder(getVirtualFileInTestData("b/src"), false);
        ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(new ModifiableRootModel[] { rootModelB, rootModelA }, moduleModel));
    }
    final JavaPsiFacade psiManager = getJavaFacade();
    assertNull(psiManager.findClass("j.B", GlobalSearchScope.moduleWithDependenciesScope(moduleA)));
    assertNull(psiManager.findClass("q.A", GlobalSearchScope.moduleScope(moduleB)));
    assertNotNull(psiManager.findClass("q.A", GlobalSearchScope.moduleScope(moduleA)));
    assertNotNull(psiManager.findClass("q.A", GlobalSearchScope.moduleWithDependenciesScope(moduleB)));
    assertNotNull(psiManager.findClass("j.B", GlobalSearchScope.moduleScope(moduleB)));
    assertNotNull(psiManager.findClass("j.B", GlobalSearchScope.moduleWithDependenciesScope(moduleB)));
    moduleManager.disposeModule(moduleB);
    moduleManager.disposeModule(moduleA);
    moduleListener.assertCorrectEvents(new String[][] { { "+b", "+a" }, { "-b" }, { "-a" } });
    connection.disconnect();
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

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

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