Search in sources :

Example 1 with ProjectViewEdit

use of com.google.idea.blaze.base.projectview.ProjectViewEdit 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 2 with ProjectViewEdit

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

the class ExcludeLibraryAction method actionPerformedInBlazeProject.

@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent e) {
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return;
    }
    Library library = LibraryActionHelper.findLibraryForAction(e);
    if (library == null) {
        return;
    }
    BlazeJarLibrary blazeLibrary = LibraryActionHelper.findLibraryFromIntellijLibrary(project, blazeProjectData, library);
    if (blazeLibrary == null) {
        Messages.showErrorDialog(project, "Could not find this library in the project.", CommonBundle.getErrorTitle());
        return;
    }
    final LibraryArtifact libraryArtifact = blazeLibrary.libraryArtifact;
    final String path = libraryArtifact.jarForIntellijLibrary().getRelativePath();
    ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
        ListSection<Glob> existingSection = builder.getLast(ExcludeLibrarySection.KEY);
        builder.replace(existingSection, ListSection.update(ExcludeLibrarySection.KEY, existingSection).add(new Glob(path)));
        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).incrementalProjectSync();
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) Glob(com.google.idea.blaze.base.projectview.section.Glob) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) Library(com.intellij.openapi.roots.libraries.Library) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact)

Example 3 with ProjectViewEdit

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

the class BlazePythonSyncPlugin method fixLanguageSupport.

private static void fixLanguageSupport(Project project, boolean removeWorkspaceType) {
    ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
        if (removeWorkspaceType) {
            removePythonWorkspaceType(builder);
        }
        removeFromAdditionalLanguages(builder);
        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).incrementalProjectSync();
}
Also used : ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit)

Example 4 with ProjectViewEdit

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

the class AdditionalLanguagesHelper method enableLanguageSupport.

/**
 * Adds the specified languages to the project view's 'additional_languages' section, and
 * installs/enables any other required plugins.
 */
public static void enableLanguageSupport(Project project, List<LanguageClass> languages) {
    ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
        ListSection<LanguageClass> existingSection = builder.getLast(AdditionalLanguagesSection.KEY);
        builder.replace(existingSection, ListSection.update(AdditionalLanguagesSection.KEY, existingSection).addAll(languages));
        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();
    ImmutableSet<String> requiredPlugins = Arrays.stream(BlazeSyncPlugin.EP_NAME.getExtensions()).map(syncPlugin -> syncPlugin.getRequiredExternalPluginIds(languages)).flatMap(Collection::stream).collect(toImmutableSet());
    PluginUtils.installOrEnablePlugins(requiredPlugins);
    BlazeSyncManager.getInstance(project).requestProjectSync(new BlazeSyncParams.Builder("Sync", BlazeSyncParams.SyncMode.INCREMENTAL).addProjectViewTargets(true).addWorkingSet(BlazeUserSettings.getInstance().getExpandSyncToWorkingSet()).build());
}
Also used : ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass)

Example 5 with ProjectViewEdit

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

the class AddSourceToProjectHelper method addSourceAndTargetsToProject.

/**
 * Adds the parent directory of the specified {@link WorkspacePath}, and the given targets to the
 * project view.
 */
static void addSourceAndTargetsToProject(Project project, WorkspacePath workspacePath, List<? extends TargetExpression> targets) {
    ImportRoots roots = ImportRoots.forProjectSafe(project);
    if (roots == null) {
        notifyFailed(project, "Couldn't parse existing project view file. Please sync the project and retry.");
        return;
    }
    WorkspacePath parentPath = Preconditions.checkNotNull(workspacePath.getParent());
    boolean addDirectory = !roots.containsWorkspacePath(parentPath);
    if (targets.isEmpty() && !addDirectory) {
        return;
    }
    ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
        if (addDirectory) {
            addDirectory(builder, parentPath);
        }
        addTargets(builder, targets);
        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).partialSync(targets);
    notifySuccess(project, addDirectory ? parentPath : null, targets);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit)

Aggregations

ProjectViewEdit (com.google.idea.blaze.base.projectview.ProjectViewEdit)8 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)2 ListSection (com.google.idea.blaze.base.projectview.section.ListSection)2 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)2 Library (com.intellij.openapi.roots.libraries.Library)2 GenfilesPath (com.google.idea.blaze.android.projectview.GenfilesPath)1 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)1 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)1 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)1 Glob (com.google.idea.blaze.base.projectview.section.Glob)1 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)1 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1