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