Search in sources :

Example 1 with WorkspacePath

use of com.google.idea.blaze.base.model.primitives.WorkspacePath in project intellij by bazelbuild.

the class AddSourceToProjectHelper method getContext.

/**
 * Returns the location context related to a source file to be added to the project.
 */
@Nullable
static LocationContext getContext(Project project, File file) {
    BlazeProjectData syncData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (syncData == null) {
        return null;
    }
    WorkspacePath workspacePath = getWorkspacePath(project, file);
    if (workspacePath == null || isBuildSystemOutputArtifact(project, workspacePath)) {
        return null;
    }
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    if (projectViewSet == null) {
        return null;
    }
    WorkspacePath parent = workspacePath.getParent();
    if (parent == null) {
        return null;
    }
    WorkspacePath blazePackage = findBlazePackagePath(project, parent);
    return blazePackage != null ? new LocationContext(project, syncData, projectViewSet, file, workspacePath, blazePackage) : null;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Nullable(javax.annotation.Nullable)

Example 2 with WorkspacePath

use of com.google.idea.blaze.base.model.primitives.WorkspacePath in project intellij by bazelbuild.

the class NewBlazePackageAction method isUnderProjectViewDirectory.

private static boolean isUnderProjectViewDirectory(WorkspaceRoot workspaceRoot, ImportRoots importRoots, PsiDirectory directory) {
    VirtualFile virtualFile = directory.getVirtualFile();
    // Ignore jars, etc. and their contents, which are in an ArchiveFileSystem.
    if (!(virtualFile.isInLocalFileSystem())) {
        return false;
    }
    if (!workspaceRoot.isInWorkspace(virtualFile)) {
        return false;
    }
    WorkspacePath workspacePath = workspaceRoot.workspacePathFor(virtualFile);
    return WorkspacePathUtil.isUnderAnyWorkspacePath(importRoots.rootDirectories(), workspacePath);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath)

Example 3 with WorkspacePath

use of com.google.idea.blaze.base.model.primitives.WorkspacePath in project intellij by bazelbuild.

the class AllInPackageBlazeConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    PsiDirectory dir = getTestDirectory(context);
    if (dir == null) {
        return false;
    }
    WorkspaceRoot root = WorkspaceRoot.fromProject(context.getProject());
    WorkspacePath packagePath = getWorkspaceRelativeDirectoryPath(root, dir);
    if (packagePath == null) {
        return false;
    }
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    return Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.TEST) && Objects.equals(configuration.getTarget(), TargetExpression.allFromPackageRecursive(packagePath));
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) PsiDirectory(com.intellij.psi.PsiDirectory) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot)

Example 4 with WorkspacePath

use of com.google.idea.blaze.base.model.primitives.WorkspacePath 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 5 with WorkspacePath

use of com.google.idea.blaze.base.model.primitives.WorkspacePath in project intellij by bazelbuild.

the class ProjectViewParserIntegrationTest method parse.

private String parse(String... lines) {
    PsiFile file = workspace.createPsiFile(new WorkspacePath(".blazeproject"), lines);
    collectErrors(file);
    return treeToString(file);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) PsiFile(com.intellij.psi.PsiFile)

Aggregations

WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)509 Test (org.junit.Test)454 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)197 PsiFile (com.intellij.psi.PsiFile)84 File (java.io.File)75 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)53 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)48 Editor (com.intellij.openapi.editor.Editor)46 VirtualFile (com.intellij.openapi.vfs.VirtualFile)41 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)40 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)37 PsiReference (com.intellij.psi.PsiReference)37 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)34 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)34 BlazeContentEntry (com.google.idea.blaze.java.sync.model.BlazeContentEntry)33 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)29 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)26 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)26 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)25 PsiElement (com.intellij.psi.PsiElement)25