Search in sources :

Example 1 with JavaModuleContentRoot

use of com.android.tools.idea.gradle.model.java.JavaModuleContentRoot in project android by JetBrains.

the class ContentRootsModuleSetupStep method findContentEntries.

@NotNull
private static List<ContentEntry> findContentEntries(@NotNull ModifiableRootModel moduleModel, @NotNull JavaModuleModel javaModuleModel) {
    removeExistingContentEntries(moduleModel);
    List<ContentEntry> contentEntries = new ArrayList<>();
    for (JavaModuleContentRoot contentRoot : javaModuleModel.getContentRoots()) {
        File rootDirPath = contentRoot.getRootDirPath();
        ContentEntry contentEntry = moduleModel.addContentEntry(pathToIdeaUrl(rootDirPath));
        contentEntries.add(contentEntry);
    }
    return contentEntries;
}
Also used : ContentEntry(com.intellij.openapi.roots.ContentEntry) ArrayList(java.util.ArrayList) JavaModuleContentRoot(com.android.tools.idea.gradle.model.java.JavaModuleContentRoot) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JavaModuleContentRoot

use of com.android.tools.idea.gradle.model.java.JavaModuleContentRoot 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)

Aggregations

JavaModuleContentRoot (com.android.tools.idea.gradle.model.java.JavaModuleContentRoot)2 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 File (java.io.File)2 FilePaths.findParentContentEntry (com.android.tools.idea.gradle.util.FilePaths.findParentContentEntry)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1