Search in sources :

Example 6 with JpsModuleSourceRootType

use of org.jetbrains.jps.model.module.JpsModuleSourceRootType 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 7 with JpsModuleSourceRootType

use of org.jetbrains.jps.model.module.JpsModuleSourceRootType in project intellij-community by JetBrains.

the class MavenFoldersImporter method configSourceFolders.

private void configSourceFolders() {
    final MultiMap<JpsModuleSourceRootType<?>, String> roots = new LinkedMultiMap<>();
    roots.putValues(JavaSourceRootType.SOURCE, myMavenProject.getSources());
    roots.putValues(JavaSourceRootType.TEST_SOURCE, myMavenProject.getTestSources());
    for (MavenImporter each : MavenImporter.getSuitableImporters(myMavenProject)) {
        each.collectSourceRoots(myMavenProject, (s, type) -> roots.putValue(type, s));
    }
    for (MavenResource each : myMavenProject.getResources()) {
        roots.putValue(JavaResourceRootType.RESOURCE, each.getDirectory());
    }
    for (MavenResource each : myMavenProject.getTestResources()) {
        roots.putValue(JavaResourceRootType.TEST_RESOURCE, each.getDirectory());
    }
    addBuilderHelperPaths("add-source", roots.getModifiable(JavaSourceRootType.SOURCE));
    addBuilderHelperPaths("add-test-source", roots.getModifiable(JavaSourceRootType.TEST_SOURCE));
    List<String> addedPaths = new ArrayList<>();
    for (JpsModuleSourceRootType<?> type : roots.keySet()) {
        for (String path : roots.get(type)) {
            addSourceFolderIfNotOverlap(path, type, addedPaths);
        }
    }
}
Also used : MavenResource(org.jetbrains.idea.maven.model.MavenResource) LinkedMultiMap(com.intellij.util.containers.LinkedMultiMap) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) ArrayList(java.util.ArrayList)

Example 8 with JpsModuleSourceRootType

use of org.jetbrains.jps.model.module.JpsModuleSourceRootType in project intellij-community by JetBrains.

the class MvcModuleStructureUtil method addSourceRootsAndLibDirectory.

@Nullable
private static Consumer<ModifiableRootModel> addSourceRootsAndLibDirectory(@NotNull final VirtualFile root, final MvcProjectStructure structure) {
    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(structure.myModule);
    Map<VirtualFile, JpsModuleSourceRootType<?>> sourceRoots = new HashMap<>();
    for (ContentEntry entry : moduleRootManager.getContentEntries()) {
        for (SourceFolder folder : entry.getSourceFolders()) {
            sourceRoots.put(folder.getFile(), folder.getRootType());
        }
    }
    root.refresh(false, true);
    final List<Consumer<ContentEntry>> actions = ContainerUtil.newArrayList();
    for (Map.Entry<JpsModuleSourceRootType<?>, Collection<String>> entry : structure.getSourceFolders().entrySet()) {
        JpsModuleSourceRootType<?> rootType = entry.getKey();
        for (String src : entry.getValue()) {
            addSourceFolder(root, src, rootType, actions, sourceRoots);
        }
    }
    for (final String src : structure.getInvalidSourceFolders()) {
        removeSrcFolderFromRoots(root.findFileByRelativePath(src), actions, sourceRoots);
    }
    for (final VirtualFile excluded : structure.getExcludedFolders(root)) {
        if (moduleRootManager.getFileIndex().isInContent(excluded)) {
            actions.add(contentEntry -> contentEntry.addExcludeFolder(excluded));
        }
    }
    final Consumer<ModifiableRootModel> modifyLib = addJarDirectory(root, structure.myModule, structure.getUserLibraryName());
    if (actions.isEmpty() && modifyLib == null && findContentEntry(moduleRootManager, root) != null) {
        return null;
    }
    return model -> {
        ContentEntry contentEntry = findContentEntry(model, root);
        if (contentEntry == null) {
            contentEntry = model.addContentEntry(root);
        }
        for (final Consumer<ContentEntry> action : actions) {
            action.consume(contentEntry);
        }
        if (modifyLib != null) {
            modifyLib.consume(model);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) java.util(java.util) Application(com.intellij.openapi.application.Application) ArrayUtil(com.intellij.util.ArrayUtil) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) PsiManager(com.intellij.psi.PsiManager) com.intellij.openapi.roots(com.intellij.openapi.roots) Library(com.intellij.openapi.roots.libraries.Library) Comparing(com.intellij.openapi.util.Comparing) SmartList(com.intellij.util.SmartList) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) ModifiableFacetModel(com.intellij.facet.ModifiableFacetModel) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) MultiMap(com.intellij.util.containers.MultiMap) CommonProcessors(com.intellij.util.CommonProcessors) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) LibraryUtil(com.intellij.openapi.roots.libraries.LibraryUtil) ModifiableModelCommitter(com.intellij.openapi.roots.impl.ModifiableModelCommitter) JavaSourceRootType(org.jetbrains.jps.model.java.JavaSourceRootType) Key(com.intellij.openapi.util.Key) IOException(java.io.IOException) FacetManager(com.intellij.facet.FacetManager) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) ModuleDeleteProvider(com.intellij.openapi.roots.ui.configuration.actions.ModuleDeleteProvider) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) JpsModuleSourceRootType(org.jetbrains.jps.model.module.JpsModuleSourceRootType) Consumer(com.intellij.util.Consumer) MultiMap(com.intellij.util.containers.MultiMap) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JpsModuleSourceRootType (org.jetbrains.jps.model.module.JpsModuleSourceRootType)8 File (java.io.File)4 Module (com.intellij.openapi.module.Module)3 SourceFolder (com.intellij.openapi.roots.SourceFolder)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 NotNull (org.jetbrains.annotations.NotNull)3 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)2 GradleVersion (com.android.ide.common.repository.GradleVersion)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 FacetManager (com.intellij.facet.FacetManager)1 ModifiableFacetModel (com.intellij.facet.ModifiableFacetModel)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 Application (com.intellij.openapi.application.Application)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)1