Search in sources :

Example 1 with WorkspacePathResolver

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;
}
Also used : BuildSystemProvider(com.google.idea.blaze.base.bazel.BuildSystemProvider) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) Nullable(javax.annotation.Nullable)

Example 2 with WorkspacePathResolver

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);
}
Also used : BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 3 with WorkspacePathResolver

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);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ScalarSection(com.google.idea.blaze.base.projectview.section.ScalarSection) LanguageSupport(com.google.idea.blaze.base.sync.projectview.LanguageSupport) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) Sections(com.google.idea.blaze.base.projectview.section.sections.Sections) JBLabel(com.intellij.ui.components.JBLabel) JPanelProvidingProject(com.google.idea.blaze.base.settings.ui.JPanelProvidingProject) UiUtil(com.google.idea.blaze.base.ui.UiUtil) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) BorderLayout(java.awt.BorderLayout) ProgressManager(com.intellij.openapi.progress.ProgressManager) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) BlazeValidationResult(com.google.idea.blaze.base.ui.BlazeValidationResult) RecentProjectsManager(com.intellij.ide.RecentProjectsManager) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) BorderFactory(javax.swing.BorderFactory) ProjectViewDefaultValueProvider(com.google.idea.blaze.base.projectview.section.ProjectViewDefaultValueProvider) TextComponentAccessor(com.intellij.openapi.ui.TextComponentAccessor) Component(java.awt.Component) JRadioButton(javax.swing.JRadioButton) TargetSection(com.google.idea.blaze.base.projectview.section.sections.TargetSection) Propagation(com.google.idea.blaze.base.scope.OutputSink.Propagation) List(java.util.List) SystemProperties(com.intellij.util.SystemProperties) ImportSection(com.google.idea.blaze.base.projectview.section.sections.ImportSection) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) GridBagLayout(java.awt.GridBagLayout) NotNull(org.jetbrains.annotations.NotNull) JPanel(javax.swing.JPanel) SectionParser(com.google.idea.blaze.base.projectview.section.SectionParser) SectionKey(com.google.idea.blaze.base.projectview.section.SectionKey) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeSelectWorkspaceOption(com.google.idea.blaze.base.wizard2.BlazeSelectWorkspaceOption) JTextField(javax.swing.JTextField) Paths(com.intellij.history.core.Paths) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) Hashing(com.google.common.hash.Hashing) Lists(com.google.common.collect.Lists) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) Scope(com.google.idea.blaze.base.scope.Scope) BlazeDataStorage(com.google.idea.blaze.base.sync.data.BlazeDataStorage) BoolExperiment(com.google.idea.common.experiments.BoolExperiment) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) Nullable(javax.annotation.Nullable) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) ProjectDataDirectoryValidator(com.google.idea.blaze.base.wizard2.ProjectDataDirectoryValidator) ButtonGroup(javax.swing.ButtonGroup) HashCode(com.google.common.hash.HashCode) ProjectViewParser(com.google.idea.blaze.base.projectview.parser.ProjectViewParser) StringUtil(com.intellij.openapi.util.text.StringUtil) BlazeSelectProjectViewOption(com.google.idea.blaze.base.wizard2.BlazeSelectProjectViewOption) IOException(java.io.IOException) BlazeNewProjectBuilder(com.google.idea.blaze.base.wizard2.BlazeNewProjectBuilder) ProjectViewStorageManager(com.google.idea.blaze.base.projectview.ProjectViewStorageManager) Disposable(com.intellij.openapi.Disposable) File(java.io.File) Category(com.google.idea.blaze.base.scope.output.IssueOutput.Category) JScrollPane(javax.swing.JScrollPane) Collectors.toList(java.util.stream.Collectors.toList) BlazeValidationError(com.google.idea.blaze.base.ui.BlazeValidationError) ProjectViewVerifier(com.google.idea.blaze.base.projectview.ProjectViewVerifier) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) ProjectViewUi(com.google.idea.blaze.base.settings.ui.ProjectViewUi) JLabel(javax.swing.JLabel) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Comparator(java.util.Comparator) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) SectionKey(com.google.idea.blaze.base.projectview.section.SectionKey) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) ProjectViewDefaultValueProvider(com.google.idea.blaze.base.projectview.section.ProjectViewDefaultValueProvider) ProjectViewParser(com.google.idea.blaze.base.projectview.parser.ProjectViewParser)

Example 4 with WorkspacePathResolver

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);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) BuildSystemProvider(com.google.idea.blaze.base.bazel.BuildSystemProvider) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) FileChooserDialog(com.intellij.openapi.fileChooser.FileChooserDialog)

Example 5 with WorkspacePathResolver

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();
}
Also used : WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

WorkspacePathResolver (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver)15 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)8 File (java.io.File)8 Nullable (javax.annotation.Nullable)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 BuildSystemProvider (com.google.idea.blaze.base.bazel.BuildSystemProvider)4 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)4 Lists (com.google.common.collect.Lists)2 HashCode (com.google.common.hash.HashCode)2 BlazeInfo (com.google.idea.blaze.base.command.info.BlazeInfo)2 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)2 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)2 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)2 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 ProjectViewParser (com.google.idea.blaze.base.projectview.parser.ProjectViewParser)2 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)2 Scope (com.google.idea.blaze.base.scope.Scope)2 IssueOutput (com.google.idea.blaze.base.scope.output.IssueOutput)2 TimingScope (com.google.idea.blaze.base.scope.scopes.TimingScope)2