Search in sources :

Example 31 with ContentEntry

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

the class ContentRootsModuleSetupStep method findContentEntries.

@NotNull
private static List<ContentEntry> findContentEntries(@NotNull ModifiableRootModel moduleModel, @NotNull AndroidModuleModel androidModel, boolean hasNativeModel) {
    if (!hasNativeModel) {
        removeExistingContentEntries(moduleModel);
    }
    List<ContentEntry> contentEntries = new ArrayList<>();
    ContentEntry contentEntry = moduleModel.addContentEntry(androidModel.getRootDir());
    contentEntries.add(contentEntry);
    File buildFolderPath = androidModel.getAndroidProject().getBuildFolder();
    if (!isAncestor(androidModel.getRootDirPath(), buildFolderPath, false)) {
        contentEntries.add(moduleModel.addContentEntry(pathToIdeaUrl(buildFolderPath)));
    }
    return contentEntries;
}
Also used : ContentEntry(com.intellij.openapi.roots.ContentEntry) ArrayList(java.util.ArrayList) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with ContentEntry

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

the class DependenciesModuleSetupStep method updateLibraryDependency.

public void updateLibraryDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull LibraryDependency dependency, @NotNull AndroidProject androidProject) {
    String name = dependency.getName();
    DependencyScope scope = dependency.getScope();
    myDependenciesSetup.setUpLibraryDependency(module, modelsProvider, name, scope, dependency.getArtifactPath(), dependency.getPaths(BINARY), dependency.getPaths(DOCUMENTATION));
    File buildFolder = androidProject.getBuildFolder();
    // Exclude jar files that are in "jars" folder in "build" folder.
    // see https://code.google.com/p/android/issues/detail?id=123788
    ContentEntry[] contentEntries = modelsProvider.getModifiableRootModel(module).getContentEntries();
    if (contentEntries.length > 0) {
        for (File binaryPath : dependency.getPaths(BINARY)) {
            File parent = binaryPath.getParentFile();
            if (parent != null && FD_JARS.equals(parent.getName()) && isAncestor(buildFolder, parent, true)) {
                ContentEntry parentContentEntry = findParentContentEntry(parent, contentEntries);
                if (parentContentEntry != null) {
                    parentContentEntry.addExcludeFolder(pathToIdeaUrl(parent));
                }
            }
        }
    }
}
Also used : DependencyScope(com.intellij.openapi.roots.DependencyScope) FilePaths.findParentContentEntry(com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry) ContentEntry(com.intellij.openapi.roots.ContentEntry) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 33 with ContentEntry

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

the class AndroidContentEntriesSetup method addExcludedOutputFolders.

private void addExcludedOutputFolders(@NotNull List<ContentEntry> contentEntries) {
    File buildFolderPath = getAndroidProject().getBuildFolder();
    ContentEntry parentContentEntry = findParentContentEntry(buildFolderPath, contentEntries);
    if (parentContentEntry != null) {
        List<File> excludedFolderPaths = myAndroidModel.getExcludedFolderPaths();
        for (File folderPath : excludedFolderPaths) {
            addExcludedFolder(parentContentEntry, folderPath);
        }
    }
}
Also used : FilePaths.findParentContentEntry(com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry) ContentEntry(com.intellij.openapi.roots.ContentEntry) File(java.io.File)

Example 34 with ContentEntry

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

the class JavaContentEntriesSetup method execute.

@Override
public void execute(@NotNull List<ContentEntry> contentEntries) {
    boolean isTopLevelJavaModule = isGradleProjectModule(getModule());
    File buildFolderPath = myJavaModuleModel.getBuildFolderPath();
    boolean buildFolderExcluded = buildFolderPath != null;
    for (JavaModuleContentRoot contentRoot : myJavaModuleModel.getContentRoots()) {
        if (contentRoot == null) {
            continue;
        }
        addSourceFolders(contentRoot.getSourceDirPaths(), contentEntries, SOURCE, false);
        addSourceFolders(contentRoot.getGenSourceDirPaths(), contentEntries, SOURCE, true);
        addSourceFolders(contentRoot.getResourceDirPaths(), contentEntries, RESOURCE, false);
        addSourceFolders(contentRoot.getTestDirPaths(), contentEntries, TEST_SOURCE, false);
        addSourceFolders(contentRoot.getGenTestDirPaths(), contentEntries, TEST_SOURCE, true);
        addSourceFolders(contentRoot.getTestResourceDirPaths(), contentEntries, TEST_RESOURCE, false);
        for (File excluded : contentRoot.getExcludeDirPaths()) {
            ContentEntry contentEntry = findParentContentEntry(excluded, contentEntries);
            if (contentEntry != null) {
                if (isTopLevelJavaModule && buildFolderExcluded) {
                    // We need to "undo" the implicit exclusion of "build" folder for top-level module.
                    if (filesEqual(excluded, buildFolderPath)) {
                        buildFolderExcluded = true;
                        continue;
                    }
                }
                addExcludedFolder(contentEntry, excluded);
            }
        }
    }
    addOrphans();
}
Also used : FilePaths.findParentContentEntry(com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry) ContentEntry(com.intellij.openapi.roots.ContentEntry) JavaModuleContentRoot(com.android.tools.idea.gradle.model.java.JavaModuleContentRoot) File(java.io.File)

Example 35 with ContentEntry

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

the class JavaModuleSetup method cleanUpAndroidModuleWithoutVariants.

private static void cleanUpAndroidModuleWithoutVariants(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider) {
    // Remove Android facet, otherwise the IDE will try to build the module, and fail. The facet may have been added in a previous
    // successful commit.
    removeAllFacets(ideModelsProvider.getModifiableFacetModel(module), AndroidFacet.ID);
    // Clear all source and exclude folders.
    ModifiableRootModel rootModel = ideModelsProvider.getModifiableRootModel(module);
    for (ContentEntry contentEntry : rootModel.getContentEntries()) {
        contentEntry.clearSourceFolders();
        contentEntry.clearExcludeFolders();
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) 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