use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class NewBlazePackageAction method filterDirectories.
/**
* Filter out directories that do not live under the project's directories.
*/
private static List<PsiDirectory> filterDirectories(Project project, PsiDirectory[] directories) {
if (directories.length == 0) {
return ImmutableList.of();
}
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (projectViewSet == null) {
return ImmutableList.of();
}
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, Blaze.getBuildSystem(project)).add(projectViewSet).build();
return Lists.newArrayList(directories).stream().filter(directory -> isUnderProjectViewDirectory(workspaceRoot, importRoots, directory)).collect(Collectors.toList());
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class NewBlazePackageDialog method doOKAction.
@Override
protected void doOKAction() {
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
logger.assertTrue(parentDirectory.getVirtualFile().isInLocalFileSystem());
File parentDirectoryFile = new File(parentDirectory.getVirtualFile().getPath());
String newPackageName = packageNameField.getText();
File newPackageDirectory = new File(parentDirectoryFile, newPackageName);
WorkspacePath newPackagePath = workspaceRoot.workspacePathFor(newPackageDirectory);
TargetName newTargetName = newRuleUI.getRuleName();
Label newRule = Label.create(newPackagePath, newTargetName);
Kind ruleKind = newRuleUI.getSelectedRuleKind();
try {
parentDirectory.checkCreateSubdirectory(newPackageName);
} catch (IncorrectOperationException ex) {
showErrorDialog(CreateElementActionBase.filterMessage(ex.getMessage()));
// do not close the dialog
return;
}
this.newRule = newRule;
this.newRuleKind = ruleKind;
super.doOKAction();
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class NewBlazeRuleDialog method doOKAction.
@Override
protected void doOKAction() {
TargetName targetName = newRuleUI.getRuleName();
Kind ruleKind = newRuleUI.getSelectedRuleKind();
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
WorkspacePath workspacePath = workspaceRoot.workspacePathFor(new File(buildFile.getParent().getPath()));
Label newRule = Label.create(workspacePath, targetName);
BuildFileModifier buildFileModifier = BuildFileModifier.getInstance();
String commandName = String.format("Add %s %s rule '%s'", buildSystemName, ruleKind, newRule);
boolean success = new WriteCommandAction<Boolean>(project, commandName) {
@Override
protected void run(@NotNull Result<Boolean> result) throws Throwable {
LocalHistory localHistory = LocalHistory.getInstance();
LocalHistoryAction action = localHistory.startAction(commandName);
try {
result.setResult(buildFileModifier.addRule(project, newRule, ruleKind));
} finally {
action.finish();
}
}
}.execute().getResultObject();
if (success) {
super.doOKAction();
} else {
super.setErrorText(String.format("Could not create new rule, see %s Console for details", buildSystemName));
}
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class PartialSyncAction method getTargets.
private static List<TargetExpression> getTargets(Project project, @Nullable VirtualFile virtualFile) {
if (virtualFile == null) {
return ImmutableList.of();
}
List<TargetExpression> targets = Lists.newArrayList();
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
SourceToTargetMap.getInstance(project);
if (!virtualFile.isDirectory()) {
targets.addAll(SourceToTargetMap.getInstance(project).getTargetsToBuildForSourceFile(new File(virtualFile.getPath())));
}
if (targets.isEmpty()) {
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (projectViewSet != null) {
BuildSystem buildSystem = Blaze.getBuildSystem(project);
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, buildSystem).add(projectViewSet).build();
BuildTargetFinder buildTargetFinder = new BuildTargetFinder(project, workspaceRoot, importRoots);
TargetExpression targetExpression = buildTargetFinder.findTargetForFile(new File(virtualFile.getPath()));
if (targetExpression != null) {
targets.add(targetExpression);
}
}
}
return targets;
}
use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.
the class ImportRoots method forProjectSafe.
/**
* Returns the ImportRoots for the project, or null if it's not a blaze project.
*/
@Nullable
public static ImportRoots forProjectSafe(Project project) {
WorkspaceRoot root = WorkspaceRoot.fromProjectSafe(project);
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (root == null || projectViewSet == null) {
return null;
}
return ImportRoots.builder(root, Blaze.getBuildSystem(project)).add(projectViewSet).build();
}
Aggregations