Search in sources :

Example 46 with WorkspaceRoot

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());
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalHistoryAction(com.intellij.history.LocalHistoryAction) Presentation(com.intellij.openapi.actionSystem.Presentation) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) PsiManager(com.intellij.psi.PsiManager) BlazeProjectAction(com.google.idea.blaze.base.actions.BlazeProjectAction) BuildFileModifier(com.google.idea.blaze.base.buildmodifier.BuildFileModifier) Kind(com.google.idea.blaze.base.model.primitives.Kind) IdeView(com.intellij.ide.IdeView) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Scope(com.google.idea.blaze.base.scope.Scope) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Logger(com.intellij.openapi.diagnostic.Logger) DumbAware(com.intellij.openapi.project.DumbAware) Nullable(javax.annotation.Nullable) Blaze(com.google.idea.blaze.base.settings.Blaze) PlatformIcons(com.intellij.util.PlatformIcons) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) WorkspacePathUtil(com.google.idea.blaze.base.util.WorkspacePathUtil) IOException(java.io.IOException) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) File(java.io.File) DirectoryChooserUtil(com.intellij.ide.util.DirectoryChooserUtil) List(java.util.List) Label(com.google.idea.blaze.base.model.primitives.Label) Result(com.intellij.openapi.application.Result) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Optional(java.util.Optional) VfsUtil(com.intellij.openapi.vfs.VfsUtil) PsiDirectory(com.intellij.psi.PsiDirectory) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) LocalHistory(com.intellij.history.LocalHistory) LangDataKeys(com.intellij.openapi.actionSystem.LangDataKeys) NotNull(org.jetbrains.annotations.NotNull) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot)

Example 47 with WorkspaceRoot

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();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Kind(com.google.idea.blaze.base.model.primitives.Kind) JBLabel(com.intellij.ui.components.JBLabel) Label(com.google.idea.blaze.base.model.primitives.Label) IncorrectOperationException(com.intellij.util.IncorrectOperationException) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetName(com.google.idea.blaze.base.model.primitives.TargetName) File(java.io.File)

Example 48 with WorkspaceRoot

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));
    }
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Label(com.google.idea.blaze.base.model.primitives.Label) TargetName(com.google.idea.blaze.base.model.primitives.TargetName) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) Kind(com.google.idea.blaze.base.model.primitives.Kind) LocalHistoryAction(com.intellij.history.LocalHistoryAction) BuildFileModifier(com.google.idea.blaze.base.buildmodifier.BuildFileModifier) LocalHistory(com.intellij.history.LocalHistory) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 49 with WorkspaceRoot

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;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) BuildTargetFinder(com.google.idea.blaze.base.sync.BuildTargetFinder)

Example 50 with WorkspaceRoot

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();
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Nullable(javax.annotation.Nullable)

Aggregations

WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)50 File (java.io.File)30 Nullable (javax.annotation.Nullable)23 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)21 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)19 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)18 ImmutableList (com.google.common.collect.ImmutableList)14 List (java.util.List)13 Project (com.intellij.openapi.project.Project)12 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)10 Kind (com.google.idea.blaze.base.model.primitives.Kind)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Lists (com.google.common.collect.Lists)9 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)9 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)9 Collectors (java.util.stream.Collectors)9 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)8 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)8 Label (com.google.idea.blaze.base.model.primitives.Label)8 BlazeImportSettings (com.google.idea.blaze.base.settings.BlazeImportSettings)8