Search in sources :

Example 6 with SourceFolder

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

the class ContentEntryImpl method writeExternal.

public void writeExternal(@NotNull Element element) throws WriteExternalException {
    assert !isDisposed();
    LOG.assertTrue(ELEMENT_NAME.equals(element.getName()));
    element.setAttribute(URL_ATTRIBUTE, myRoot.getUrl());
    for (final SourceFolder sourceFolder : mySourceFolders) {
        if (sourceFolder instanceof SourceFolderImpl) {
            JpsModuleRootModelSerializer.saveSourceRoot(element, sourceFolder.getUrl(), sourceFolder.getJpsElement().asTyped());
        }
    }
    for (final ExcludeFolder excludeFolder : myExcludeFolders) {
        if (excludeFolder instanceof ExcludeFolderImpl) {
            final Element subElement = new Element(ExcludeFolderImpl.ELEMENT_NAME);
            ((ExcludeFolderImpl) excludeFolder).writeExternal(subElement);
            element.addContent(subElement);
        }
    }
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) JpsElement(org.jetbrains.jps.model.JpsElement) Element(org.jdom.Element) ExcludeFolder(com.intellij.openapi.roots.ExcludeFolder)

Example 7 with SourceFolder

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

the class PluginModuleType method getPluginXml.

@Nullable
public static XmlFile getPluginXml(Module module) {
    if (module == null)
        return null;
    if (!isOfType(module)) {
        for (final ContentEntry entry : ModuleRootManager.getInstance(module).getContentEntries()) {
            for (final SourceFolder folder : entry.getSourceFolders(JavaModuleSourceRootTypes.PRODUCTION)) {
                final VirtualFile file = folder.getFile();
                if (file == null)
                    continue;
                final String packagePrefix = folder.getPackagePrefix();
                final String prefixPath = packagePrefix.isEmpty() ? "" : packagePrefix.replace('.', '/') + '/';
                final String relativePath = prefixPath + PluginDescriptorConstants.PLUGIN_XML_PATH;
                final VirtualFile pluginXmlVF = file.findFileByRelativePath(relativePath);
                if (pluginXmlVF != null) {
                    final PsiFile psiFile = PsiManager.getInstance(module.getProject()).findFile(pluginXmlVF);
                    if (psiFile instanceof XmlFile) {
                        return (XmlFile) psiFile;
                    }
                }
            }
        }
        return null;
    }
    final PluginBuildConfiguration buildConfiguration = PluginBuildConfiguration.getInstance(module);
    if (buildConfiguration == null)
        return null;
    final ConfigFile configFile = buildConfiguration.getPluginXmlConfigFile();
    return configFile != null ? configFile.getXmlFile() : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder) XmlFile(com.intellij.psi.xml.XmlFile) ConfigFile(com.intellij.util.descriptors.ConfigFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) PluginBuildConfiguration(org.jetbrains.idea.devkit.build.PluginBuildConfiguration) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with SourceFolder

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

the class AddAndroidActivityPath method getSourceDirectoryPackagePrefix.

/**
   * Returns the package prefix of the module's content root if it can be found.
   */
@NotNull
private static String getSourceDirectoryPackagePrefix(@NotNull Module module, File javaDir) {
    VirtualFile javaVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(javaDir);
    if (javaVirtualFile == null) {
        return "";
    }
    SourceFolder sourceFolder = ProjectRootsUtil.findSourceFolder(module, javaVirtualFile);
    if (sourceFolder == null) {
        return "";
    }
    return sourceFolder.getPackagePrefix();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with SourceFolder

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

the class NonAndroidModuleNode method getNonEmptySourceTypes.

private static Set<NonAndroidSourceType> getNonEmptySourceTypes(Module module) {
    ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    Set<NonAndroidSourceType> sourceTypes = Sets.newHashSetWithExpectedSize(NonAndroidSourceType.values().length);
    ContentEntry[] contentEntries = rootManager.getContentEntries();
    for (ContentEntry entry : contentEntries) {
        for (NonAndroidSourceType type : NonAndroidSourceType.values()) {
            for (SourceFolder sourceFolder : entry.getSourceFolders(type.rootType)) {
                if (sourceFolder.getFile() != null) {
                    sourceTypes.add(type);
                    break;
                }
            }
        }
    }
    return sourceTypes;
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentEntry(com.intellij.openapi.roots.ContentEntry) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager)

Example 10 with SourceFolder

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

the class ExcludedRoots method addFolderPathsFromExcludedModules.

private void addFolderPathsFromExcludedModules() {
    for (Module module : myExcludedModules) {
        ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
        for (ContentEntry entry : rootManager.getContentEntries()) {
            for (SourceFolder sourceFolder : entry.getSourceFolders()) {
                myExcludedRoots.add(urlToFilePath(sourceFolder.getUrl()));
            }
            CompilerModuleExtension compiler = rootManager.getModuleExtension(CompilerModuleExtension.class);
            String url = compiler.getCompilerOutputUrl();
            if (isNotEmpty(url)) {
                myExcludedRoots.add(urlToFilePath(url));
            }
        }
        AndroidModuleModel androidModuleModel = AndroidModuleModel.get(module);
        if (androidModuleModel != null) {
            myExcludedRoots.add(androidModuleModel.getMainArtifact().getJavaResourcesFolder());
        }
    }
}
Also used : SourceFolder(com.intellij.openapi.roots.SourceFolder) ContentEntry(com.intellij.openapi.roots.ContentEntry) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Module(com.intellij.openapi.module.Module) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension)

Aggregations

SourceFolder (com.intellij.openapi.roots.SourceFolder)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 ContentEntry (com.intellij.openapi.roots.ContentEntry)7 Module (com.intellij.openapi.module.Module)6 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)5 NotNull (org.jetbrains.annotations.NotNull)5 ExcludeFolder (com.intellij.openapi.roots.ExcludeFolder)3 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)3 JavaSourceRootProperties (org.jetbrains.jps.model.java.JavaSourceRootProperties)3 JpsModuleSourceRootType (org.jetbrains.jps.model.module.JpsModuleSourceRootType)3 Project (com.intellij.openapi.project.Project)2 ContentFolder (com.intellij.openapi.roots.ContentFolder)2 File (java.io.File)2 Assert.assertNotNull (junit.framework.Assert.assertNotNull)2 GuiTask (org.fest.swing.edt.GuiTask)2 Nullable (org.jetbrains.annotations.Nullable)2 JpsElement (org.jetbrains.jps.model.JpsElement)2 JpsModuleSourceRoot (org.jetbrains.jps.model.module.JpsModuleSourceRoot)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 GradleUtil.getGradleBuildFile (com.android.tools.idea.gradle.util.GradleUtil.getGradleBuildFile)1