use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver in project intellij by bazelbuild.
the class AddSourceToProjectHelper method findBlazePackagePath.
@Nullable
private static WorkspacePath findBlazePackagePath(Project project, WorkspacePath source) {
WorkspacePathResolver pathResolver = WorkspacePathResolverProvider.getInstance(project).getPathResolver();
if (pathResolver == null) {
return null;
}
BuildSystemProvider provider = Blaze.getBuildSystemProvider(project);
while (source != null) {
if (provider.findBuildFileInDirectory(pathResolver.resolveToFile(source)) != null) {
return source;
}
source = source.getParent();
}
return null;
}
use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver in project intellij by bazelbuild.
the class BlazePyResolverUtils method resolvePath.
/**
* Looks for a PsiDirectory or PyFile at the given workspace-relative path (appending '.py' to the
* path when looking for py files).
*/
@Nullable
public static PsiElement resolvePath(PyQualifiedNameResolveContext context, String relativePath) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(context.getProject()).getBlazeProjectData();
if (projectData == null) {
return null;
}
WorkspacePathResolver pathResolver = projectData.workspacePathResolver;
File file = pathResolver.resolveToFile(relativePath);
return resolveFile(context.getPsiManager(), file);
}
use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver in project intellij by bazelbuild.
the class BlazeEditProjectViewControl method modifyInitialProjectView.
private static String modifyInitialProjectView(BuildSystem buildSystem, String initialProjectViewText, WorkspacePathResolver workspacePathResolver) {
BlazeContext context = new BlazeContext();
ProjectViewParser projectViewParser = new ProjectViewParser(context, workspacePathResolver);
projectViewParser.parseProjectView(initialProjectViewText);
ProjectViewSet projectViewSet = projectViewParser.getResult();
ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
if (projectViewFile == null) {
return initialProjectViewText;
}
ProjectView projectView = projectViewFile.projectView;
// Sort default value providers to match the section order
List<SectionKey> sectionKeys = Sections.getParsers().stream().map(SectionParser::getSectionKey).collect(toList());
List<ProjectViewDefaultValueProvider> defaultValueProviders = Lists.newArrayList(ProjectViewDefaultValueProvider.EP_NAME.getExtensions());
defaultValueProviders.sort(Comparator.comparingInt(val -> sectionKeys.indexOf(val.getSectionKey())));
for (ProjectViewDefaultValueProvider defaultValueProvider : defaultValueProviders) {
projectView = defaultValueProvider.addProjectViewDefaultValue(buildSystem, projectViewSet, projectView);
}
return ProjectViewParser.projectViewToString(projectView);
}
use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver in project intellij by bazelbuild.
the class GenerateFromBuildFileSelectProjectViewOption method chooseWorkspacePath.
private void chooseWorkspacePath() {
BuildSystemProvider buildSystem = BuildSystemProvider.getBuildSystemProvider(builder.getBuildSystem());
assert buildSystem != null;
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false).withShowHiddenFiles(// Show root project view file
true).withHideIgnored(false).withTitle("Select BUILD File").withDescription("Select a BUILD file to synthesize a project view from.").withFileFilter(virtualFile -> buildSystem.isBuildFile(virtualFile.getName()));
FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
WorkspacePathResolver workspacePathResolver = builder.getWorkspaceOption().getWorkspacePathResolver();
File fileBrowserRoot = builder.getWorkspaceOption().getFileBrowserRoot();
File startingLocation = fileBrowserRoot;
String buildFilePath = getBuildFilePath();
if (!buildFilePath.isEmpty() && WorkspacePath.isValid(buildFilePath)) {
// If the user has typed part of the path then clicked the '...', try to start from the
// partial state
buildFilePath = StringUtil.trimEnd(buildFilePath, '/');
if (WorkspacePath.isValid(buildFilePath)) {
File fileLocation = workspacePathResolver.resolveToFile(new WorkspacePath(buildFilePath));
if (fileLocation.exists() && FileUtil.isAncestor(fileBrowserRoot, fileLocation, true)) {
startingLocation = fileLocation;
}
}
}
VirtualFile toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(startingLocation.getPath());
VirtualFile[] files = chooser.choose(null, toSelect);
if (files.length == 0) {
return;
}
VirtualFile file = files[0];
if (!FileUtil.isAncestor(fileBrowserRoot.getPath(), file.getPath(), true)) {
Messages.showErrorDialog(String.format("You must choose a BUILD file under %s.", fileBrowserRoot.getPath()), "Cannot Use BUILD File");
return;
}
String newWorkspacePath = FileUtil.getRelativePath(fileBrowserRoot, new File(file.getPath()));
buildFilePathField.setText(newWorkspacePath);
}
use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver in project intellij by bazelbuild.
the class ImportFromWorkspaceProjectViewOption method validate.
@Override
public BlazeValidationResult validate() {
if (getProjectViewPath().isEmpty()) {
return BlazeValidationResult.failure("Workspace path to project view file cannot be empty.");
}
String error = WorkspacePath.validate(getProjectViewPath());
if (error != null) {
return BlazeValidationResult.failure(error);
}
WorkspacePathResolver workspacePathResolver = builder.getWorkspaceOption().getWorkspacePathResolver();
File file = workspacePathResolver.resolveToFile(getSharedProjectView());
if (!file.exists()) {
return BlazeValidationResult.failure("Project view file does not exist.");
}
if (file.isDirectory()) {
return BlazeValidationResult.failure("Specified path is a directory, not a file");
}
return BlazeValidationResult.success();
}
Aggregations