Search in sources :

Example 1 with ListSection

use of com.google.idea.blaze.base.projectview.section.ListSection in project intellij by bazelbuild.

the class ProjectViewVerifier method verifyIncludedPackagesAreNotExcluded.

private static boolean verifyIncludedPackagesAreNotExcluded(BlazeContext context, ProjectViewSet projectViewSet) {
    boolean ok = true;
    List<WorkspacePath> includedDirectories = projectViewSet.listItems(DirectorySection.KEY).stream().filter(entry -> entry.included).map(entry -> entry.directory).collect(toList());
    for (WorkspacePath includedDirectory : includedDirectories) {
        for (ProjectViewSet.ProjectViewFile projectViewFile : projectViewSet.getProjectViewFiles()) {
            List<DirectoryEntry> directoryEntries = Lists.newArrayList();
            for (ListSection<DirectoryEntry> section : projectViewFile.projectView.getSectionsOfType(DirectorySection.KEY)) {
                directoryEntries.addAll(section.items());
            }
            for (DirectoryEntry entry : directoryEntries) {
                if (entry.included) {
                    continue;
                }
                WorkspacePath excludedDirectory = entry.directory;
                if (FileUtil.isAncestor(excludedDirectory.relativePath(), includedDirectory.relativePath(), false)) {
                    IssueOutput.error(String.format("%s is included, but that contradicts %s which was excluded", includedDirectory.toString(), excludedDirectory.toString())).inFile(projectViewFile.projectViewFile).submit(context);
                    ok = false;
                }
            }
        }
    }
    return ok;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) SectionParser(com.google.idea.blaze.base.projectview.section.SectionParser) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) LanguageSupport(com.google.idea.blaze.base.sync.projectview.LanguageSupport) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) Sections(com.google.idea.blaze.base.projectview.section.sections.Sections) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Lists(com.google.common.collect.Lists) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Project(com.intellij.openapi.project.Project) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) FileUtil(com.intellij.openapi.util.io.FileUtil) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) Nullable(javax.annotation.Nullable) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)

Example 2 with ListSection

use of com.google.idea.blaze.base.projectview.section.ListSection in project intellij by bazelbuild.

the class AddGeneratedResourceDirectoryNavigatable method addDirectoryToProjectView.

private static void addDirectoryToProjectView(Project project, File projectViewFile, ArtifactLocation generatedResDir) {
    ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
        ListSection<GenfilesPath> existingSection = builder.getLast(GeneratedAndroidResourcesSection.KEY);
        ListSection.Builder<GenfilesPath> directoryBuilder = ListSection.update(GeneratedAndroidResourcesSection.KEY, existingSection);
        directoryBuilder.add(new GenfilesPath(generatedResDir.getRelativePath()));
        builder.replace(existingSection, directoryBuilder);
        return true;
    });
    if (edit == null) {
        Messages.showErrorDialog("Could not modify project view. Check for errors in your project view and try again", "Error");
        return;
    }
    edit.apply();
    VirtualFile projectView = VfsUtil.findFileByIoFile(projectViewFile, false);
    if (projectView != null) {
        FileEditorManager.getInstance(project).openEditor(new OpenFileDescriptor(project, projectView), true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) GenfilesPath(com.google.idea.blaze.android.projectview.GenfilesPath)

Example 3 with ListSection

use of com.google.idea.blaze.base.projectview.section.ListSection in project intellij by bazelbuild.

the class AddLibraryTargetDirectoryToProjectViewAction method addDirectoriesToProjectView.

static void addDirectoriesToProjectView(Project project, List<Library> libraries) {
    Set<WorkspacePath> workspacePaths = Sets.newHashSet();
    for (Library library : libraries) {
        WorkspacePath workspacePath = getDirectoryToAddForLibrary(project, library);
        if (workspacePath != null) {
            workspacePaths.add(workspacePath);
        }
    }
    ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
        ListSection<DirectoryEntry> existingSection = builder.getLast(DirectorySection.KEY);
        ListSection.Builder<DirectoryEntry> directoryBuilder = ListSection.update(DirectorySection.KEY, existingSection);
        for (WorkspacePath workspacePath : workspacePaths) {
            directoryBuilder.add(new DirectoryEntry(workspacePath, true));
        }
        builder.replace(existingSection, directoryBuilder);
        return true;
    });
    if (edit == null) {
        Messages.showErrorDialog("Could not modify project view. Check for errors in your project view and try again", "Error");
        return;
    }
    edit.apply();
    BlazeSyncManager.getInstance(project).requestProjectSync(new BlazeSyncParams.Builder("Adding Library", BlazeSyncParams.SyncMode.INCREMENTAL).addProjectViewTargets(true).addWorkingSet(BlazeUserSettings.getInstance().getExpandSyncToWorkingSet()).build());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) Library(com.intellij.openapi.roots.libraries.Library) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)

Aggregations

ListSection (com.google.idea.blaze.base.projectview.section.ListSection)3 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)2 ProjectViewEdit (com.google.idea.blaze.base.projectview.ProjectViewEdit)2 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)2 Lists (com.google.common.collect.Lists)1 GenfilesPath (com.google.idea.blaze.android.projectview.GenfilesPath)1 FileOperationProvider (com.google.idea.blaze.base.io.FileOperationProvider)1 ProjectViewFile (com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)1 SectionParser (com.google.idea.blaze.base.projectview.section.SectionParser)1 DirectorySection (com.google.idea.blaze.base.projectview.section.sections.DirectorySection)1 Sections (com.google.idea.blaze.base.projectview.section.sections.Sections)1 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)1 IssueOutput (com.google.idea.blaze.base.scope.output.IssueOutput)1 BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)1 LanguageSupport (com.google.idea.blaze.base.sync.projectview.LanguageSupport)1 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)1 WorkspacePathResolver (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver)1 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 Project (com.intellij.openapi.project.Project)1