Search in sources :

Example 1 with ModuleRootManager

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

the class GroovyAntCustomCompilerProvider method hasCustomCompile.

/**
   * {@inheritDoc}
   */
@Override
public boolean hasCustomCompile(ModuleChunk chunk) {
    for (Module m : chunk.getModules()) {
        if (LibrariesUtil.hasGroovySdk(m)) {
            final Set<String> scriptExtensions = GroovyFileTypeLoader.getCustomGroovyScriptExtensions();
            final ContentIterator groovyFileSearcher = new ContentIterator() {

                @Override
                public boolean processFile(VirtualFile fileOrDir) {
                    ProgressManager.checkCanceled();
                    if (isCompilableGroovyFile(fileOrDir, scriptExtensions)) {
                        return false;
                    }
                    return true;
                }
            };
            final ModuleRootManager rootManager = ModuleRootManager.getInstance(m);
            final ModuleFileIndex fileIndex = rootManager.getFileIndex();
            for (VirtualFile file : rootManager.getSourceRoots(JavaModuleSourceRootTypes.SOURCES)) {
                if (!fileIndex.iterateContentUnderDirectory(file, groovyFileSearcher)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ModuleFileIndex(com.intellij.openapi.roots.ModuleFileIndex) Module(com.intellij.openapi.module.Module)

Example 2 with ModuleRootManager

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

the class MavenIdeaPluginConfigurer method configureJdk.

private static void configureJdk(Element cfg, @NotNull Module module) {
    String jdkName = cfg.getChildTextTrim("jdkName");
    if (StringUtil.isEmptyOrSpaces(jdkName))
        return;
    ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    String currentSdkName = null;
    Sdk sdk = rootManager.getSdk();
    if (sdk != null) {
        currentSdkName = sdk.getName();
    }
    if (!jdkName.equals(currentSdkName)) {
        ModifiableRootModel model = rootManager.getModifiableModel();
        if (jdkName.equals(ProjectRootManager.getInstance(model.getProject()).getProjectSdkName())) {
            model.inheritSdk();
        } else {
            Sdk jdk = ProjectJdkTable.getInstance().findJdk(jdkName);
            if (jdk != null) {
                model.setSdk(jdk);
            } else {
                model.setInvalidSdk(jdkName, JavaSdk.getInstance().getName());
            }
        }
        model.commit();
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 3 with ModuleRootManager

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

the class MvcRunConfiguration method getState.

@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    final Module module = getModule();
    if (module == null) {
        throw new ExecutionException("Module is not specified");
    }
    if (!isSupport(module)) {
        throw new ExecutionException(getNoSdkMessage());
    }
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    final Sdk sdk = rootManager.getSdk();
    if (sdk == null || !(sdk.getSdkType() instanceof JavaSdkType)) {
        throw CantRunException.noJdkForModule(module);
    }
    return createCommandLineState(environment, module);
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 4 with ModuleRootManager

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

the class PyUtil method getSourceRoots.

/**
   * @return Source roots <strong>and</strong> content roots for module
   */
@NotNull
public static Collection<VirtualFile> getSourceRoots(@NotNull Module module) {
    final Set<VirtualFile> result = new LinkedHashSet<>();
    final ModuleRootManager manager = ModuleRootManager.getInstance(module);
    Collections.addAll(result, manager.getSourceRoots());
    Collections.addAll(result, manager.getContentRoots());
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager)

Example 5 with ModuleRootManager

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

the class ModuleChunkSourcePath method addExcludePatterns.

private static void addExcludePatterns(Module module, final VirtualFile root, VirtualFile dir, final CompositeGenerator generator, final boolean parentIncluded) {
    final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() {

        @Override
        public boolean visitFile(@NotNull VirtualFile dir) {
            if (!dir.isDirectory() || fileTypeManager.isFileIgnored(dir)) {
                // ignored files are handled by global 'ignored' pattern set
                return false;
            }
            final boolean isIncluded = moduleRootManager.getFileIndex().isInContent(dir);
            if (isIncluded != parentIncluded) {
                final String relativePath = VfsUtilCore.getRelativePath(dir, root, '/');
                if (isIncluded) {
                    generator.add(new Include(relativePath + "/**"));
                } else {
                    if (!isExcludedByDefault(dir.getName())) {
                        generator.add(new Exclude(relativePath + "/**"));
                    }
                }
            }
            return true;
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor)

Aggregations

ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)47 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 Module (com.intellij.openapi.module.Module)19 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)13 ContentEntry (com.intellij.openapi.roots.ContentEntry)11 Sdk (com.intellij.openapi.projectRoots.Sdk)10 File (java.io.File)7 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)6 SourceFolder (com.intellij.openapi.roots.SourceFolder)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 OrderEntry (com.intellij.openapi.roots.OrderEntry)2 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)2 ProjectRootManagerEx (com.intellij.openapi.roots.ex.ProjectRootManagerEx)2 FilePaths.findParentContentEntry (com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1 CodeInsightTestCase (com.intellij.codeInsight.CodeInsightTestCase)1