Search in sources :

Example 11 with FileOperationProvider

use of com.google.idea.blaze.base.io.FileOperationProvider in project intellij by bazelbuild.

the class WorkspaceHelper method enumerateExternalWorkspaces.

@SuppressWarnings("unused")
private static Map<String, WorkspaceRoot> enumerateExternalWorkspaces(Project project, BlazeProjectData blazeProjectData) {
    FileOperationProvider provider = FileOperationProvider.getInstance();
    File[] children = provider.listFiles(getExternalSourceRoot(blazeProjectData));
    if (children == null) {
        return ImmutableMap.of();
    }
    return Arrays.stream(children).filter(provider::isDirectory).collect(Collectors.toMap(File::getName, WorkspaceRoot::new));
}
Also used : FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) File(java.io.File)

Example 12 with FileOperationProvider

use of com.google.idea.blaze.base.io.FileOperationProvider in project intellij by bazelbuild.

the class ProjectViewVerifier method verifyIncludedPackagesExistOnDisk.

private static boolean verifyIncludedPackagesExistOnDisk(BlazeContext context, WorkspacePathResolver workspacePathResolver, ProjectViewSet projectViewSet) {
    boolean ok = true;
    FileOperationProvider fileOperationProvider = FileOperationProvider.getInstance();
    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 workspacePath = entry.directory;
            File file = workspacePathResolver.resolveToFile(workspacePath);
            if (!fileOperationProvider.exists(file)) {
                IssueOutput.error(String.format("Directory '%s' specified in project view not found.", workspacePath)).inFile(projectViewFile.projectViewFile).submit(context);
                ok = false;
            } else if (!fileOperationProvider.isDirectory(file)) {
                IssueOutput.error(String.format("Directory '%s' specified in project view is a file.", workspacePath)).inFile(projectViewFile.projectViewFile).submit(context);
                ok = false;
            }
        }
    }
    return ok;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) File(java.io.File) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile)

Example 13 with FileOperationProvider

use of com.google.idea.blaze.base.io.FileOperationProvider in project intellij by bazelbuild.

the class BlazeGoGotoDeclarationHandler method resolveElement.

@Nullable
private static PsiElement[] resolveElement(@Nullable PsiElement element) {
    if (element == null) {
        return null;
    }
    PsiFile targetPsiFile = element.getContainingFile();
    if (!(targetPsiFile instanceof GoFile)) {
        return null;
    }
    LocalFileSystem lfs = VirtualFileSystemProvider.getInstance().getSystem();
    FileOperationProvider provider = FileOperationProvider.getInstance();
    VirtualFile targetVirtualFile = targetPsiFile.getVirtualFile();
    File targetFile = VfsUtil.virtualToIoFile(targetVirtualFile);
    if (!provider.isSymbolicLink(targetFile)) {
        return null;
    }
    VirtualFile resolved;
    try {
        // Resolve only one layer of symlink.
        File resolvedFile = provider.readSymbolicLink(targetFile);
        resolved = lfs.findFileByIoFile(resolvedFile);
    } catch (IOException e) {
        logger.error(e);
        return null;
    }
    if (resolved == null) {
        return null;
    }
    PsiFile resolvedFile = PsiManager.getInstance(element.getProject()).findFile(resolved);
    if (!(resolvedFile instanceof GoFile)) {
        return null;
    }
    PsiElement foundElement = resolvedFile.findElementAt(element.getTextOffset());
    return new PsiElement[] { PsiTreeUtil.getParentOfType(foundElement, element.getClass()) };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GoFile(com.goide.psi.GoFile) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) GoFile(com.goide.psi.GoFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Example 14 with FileOperationProvider

use of com.google.idea.blaze.base.io.FileOperationProvider in project intellij by bazelbuild.

the class BlazeGoRootsProvider method createGoPathSourceRoot.

/**
 * Creates the .gopath root under the project data directory. Then {@link #createSymLinks} for
 * each go target discovered in the target map into the root directory.
 */
public static synchronized void createGoPathSourceRoot(Project project, BlazeProjectData projectData) {
    File goRoot = getGoRoot(project);
    if (goRoot == null) {
        return;
    }
    FileOperationProvider provider = FileOperationProvider.getInstance();
    if (provider.exists(goRoot)) {
        try {
            provider.deleteRecursively(goRoot);
        } catch (IOException e) {
            logger.error(e);
            return;
        }
    }
    if (!provider.mkdirs(goRoot)) {
        logger.error("Failed to create " + goRoot);
        return;
    }
    ArtifactLocationDecoder decoder = projectData.artifactLocationDecoder;
    for (TargetIdeInfo target : projectData.targetMap.targets()) {
        if (target.goIdeInfo == null || target.goIdeInfo.importPath == null) {
            continue;
        }
        String importPath = target.goIdeInfo.importPath;
        createSymLinks(goRoot, importPath, getGoSources(target, decoder, projectData.blazeInfo));
    }
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 15 with FileOperationProvider

use of com.google.idea.blaze.base.io.FileOperationProvider in project intellij by bazelbuild.

the class BlazeGoRootsProvider method createSymLinks.

@Nullable
private static synchronized File createSymLinks(File goRoot, String importPath, List<File> sources) {
    FileOperationProvider provider = FileOperationProvider.getInstance();
    File goPackage = new File(goRoot, importPath);
    if (!provider.exists(goPackage)) {
        if (!provider.mkdirs(goPackage)) {
            return null;
        }
    }
    for (File src : sources) {
        File link = new File(goPackage, hashName(src));
        if (!provider.exists(link)) {
            try {
                provider.createSymbolicLink(link, src);
            } catch (IOException e) {
                logger.warn(e);
            }
        }
    }
    return goPackage;
}
Also used : FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(javax.annotation.Nullable)

Aggregations

FileOperationProvider (com.google.idea.blaze.base.io.FileOperationProvider)15 File (java.io.File)10 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 IOException (java.io.IOException)5 Nullable (javax.annotation.Nullable)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)3 PsiFile (com.intellij.psi.PsiFile)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 Futures (com.google.common.util.concurrent.Futures)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)2 Project (com.intellij.openapi.project.Project)2 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2