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