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);
}
}
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();
}
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();
}
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());
}
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);
}
Aggregations