Search in sources :

Example 6 with WorkspacePathResolver

use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver in project intellij by bazelbuild.

the class BlazeEditProjectViewControl method update.

public void update(BlazeNewProjectBuilder builder) {
    this.workspaceOption = builder.getWorkspaceOption();
    this.projectViewOption = builder.getProjectViewOption();
    WorkspaceRoot workspaceRoot = workspaceOption.getWorkspaceRoot();
    WorkspacePath workspacePath = projectViewOption.getSharedProjectView();
    String initialProjectViewText = projectViewOption.getInitialProjectViewText();
    boolean allowAddDefaultValues = projectViewOption.allowAddDefaultProjectViewValues() && allowAddprojectViewDefaultValues.getValue();
    WorkspacePathResolver workspacePathResolver = workspaceOption.getWorkspacePathResolver();
    HashCode hashCode = Hashing.md5().newHasher().putUnencodedChars(workspaceRoot.toString()).putUnencodedChars(workspacePath != null ? workspacePath.toString() : "").putUnencodedChars(initialProjectViewText != null ? initialProjectViewText : "").putBoolean(allowAddDefaultValues).hash();
    // If any params have changed, reinit the control
    if (!hashCode.equals(paramsHash)) {
        this.paramsHash = hashCode;
        this.isInitialising = true;
        init(workspaceOption.getBuildSystemForWorkspace(), workspaceRoot, workspacePathResolver, workspacePath, initialProjectViewText, allowAddDefaultValues);
        this.isInitialising = false;
    }
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) HashCode(com.google.common.hash.HashCode) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot)

Example 7 with WorkspacePathResolver

use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver in project intellij by bazelbuild.

the class BlazeSyncTask method computeWorkspacePathResolverAndProjectView.

private WorkspacePathResolverAndProjectView computeWorkspacePathResolverAndProjectView(BlazeContext context, BlazeVcsHandler vcsHandler, ListeningExecutorService executor) {
    context.output(new StatusOutput("Updating VCS..."));
    for (int i = 0; i < 3; ++i) {
        WorkspacePathResolver vcsWorkspacePathResolver = null;
        BlazeVcsHandler.BlazeVcsSyncHandler vcsSyncHandler = vcsHandler.createSyncHandler(project, workspaceRoot);
        if (vcsSyncHandler != null) {
            boolean ok = Scope.push(context, (childContext) -> {
                childContext.push(new TimingScope("UpdateVcs", EventType.Other));
                return vcsSyncHandler.update(context, executor);
            });
            if (!ok) {
                return null;
            }
            vcsWorkspacePathResolver = vcsSyncHandler.getWorkspacePathResolver();
        }
        WorkspacePathResolver workspacePathResolver = vcsWorkspacePathResolver != null ? vcsWorkspacePathResolver : new WorkspacePathResolverImpl(workspaceRoot);
        ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).reloadProjectView(context, workspacePathResolver);
        if (projectViewSet == null) {
            return null;
        }
        if (vcsSyncHandler != null) {
            BlazeVcsHandler.BlazeVcsSyncHandler.ValidationResult validationResult = vcsSyncHandler.validateProjectView(context, projectViewSet);
            switch(validationResult) {
                case OK:
                    // Fall-through and return
                    break;
                case Error:
                    return null;
                case RestartSync:
                    continue;
                default:
                    // Cannot happen
                    return null;
            }
        }
        return new WorkspacePathResolverAndProjectView(workspacePathResolver, projectViewSet);
    }
    return null;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) BlazeVcsHandler(com.google.idea.blaze.base.vcs.BlazeVcsHandler)

Example 8 with WorkspacePathResolver

use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver in project intellij by bazelbuild.

the class GenerateFromBuildFileSelectProjectViewOption method getInitialProjectViewText.

@Nullable
@Override
public String getInitialProjectViewText() {
    WorkspacePathResolver workspacePathResolver = builder.getWorkspaceOption().getWorkspacePathResolver();
    WorkspacePath workspacePath = new WorkspacePath(Strings.nullToEmpty(new File(getBuildFilePath()).getParent()));
    return guessProjectViewFromLocation(workspacePathResolver, workspacePath);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 9 with WorkspacePathResolver

use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver in project intellij by bazelbuild.

the class GenerateFromBuildFileSelectProjectViewOption method validate.

@Override
public BlazeValidationResult validate() {
    String buildFilePath = getBuildFilePath();
    if (buildFilePath.isEmpty()) {
        return BlazeValidationResult.failure("BUILD file field cannot be empty.");
    }
    if (!WorkspacePath.isValid(buildFilePath)) {
        return BlazeValidationResult.failure("Invalid BUILD file path: specify a path relative to the workspace root.");
    }
    WorkspacePathResolver workspacePathResolver = builder.getWorkspaceOption().getWorkspacePathResolver();
    File file = workspacePathResolver.resolveToFile(new WorkspacePath(buildFilePath));
    if (!file.exists()) {
        return BlazeValidationResult.failure("BUILD file does not exist.");
    }
    if (file.isDirectory()) {
        return BlazeValidationResult.failure("Specified path is a directory, not a file");
    }
    BuildSystemProvider buildSystemProvider = BuildSystemProvider.getBuildSystemProvider(builder.getBuildSystem());
    checkState(buildSystemProvider != null);
    if (!buildSystemProvider.isBuildFile(file.getName())) {
        return BlazeValidationResult.failure("File must be a BUILD file.");
    }
    return BlazeValidationResult.success();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) 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)

Example 10 with WorkspacePathResolver

use of com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver in project intellij by bazelbuild.

the class ImportFromWorkspaceProjectViewOption method chooseWorkspacePath.

private void chooseWorkspacePath() {
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false).withShowHiddenFiles(// Show root project view file
    true).withHideIgnored(false).withTitle("Select Project View File").withDescription("Select a project view file to import.").withFileFilter(virtualFile -> ProjectViewStorageManager.isProjectViewFile(new File(virtualFile.getPath())));
    FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null);
    WorkspacePathResolver workspacePathResolver = builder.getWorkspaceOption().getWorkspacePathResolver();
    File fileBrowserRoot = builder.getWorkspaceOption().getFileBrowserRoot();
    File startingLocation = fileBrowserRoot;
    String projectViewPath = getProjectViewPath();
    if (!projectViewPath.isEmpty()) {
        // If the user has typed part of the path then clicked the '...', try to start from the
        // partial state
        projectViewPath = StringUtil.trimEnd(projectViewPath, '/');
        if (WorkspacePath.isValid(projectViewPath)) {
            File fileLocation = workspacePathResolver.resolveToFile(new WorkspacePath(projectViewPath));
            if (fileLocation.exists() && FileUtil.isAncestor(getCanonicalPathSafe(fileBrowserRoot), getCanonicalPathSafe(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(getCanonicalPathSafe(fileBrowserRoot), getCanonicalPathSafe(file), true)) {
        Messages.showErrorDialog(String.format("You must choose a project view file under %s. " + "To use an external project view, please use the 'Copy external' option.", fileBrowserRoot.getPath()), "Cannot Use Project View File");
        return;
    }
    String newWorkspacePath = FileUtil.getRelativePath(getCanonicalPathSafe(fileBrowserRoot), getCanonicalPathSafe(new File(file.getPath())), File.separatorChar);
    projectViewPathField.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) 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)

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