use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class BlazeEditProjectViewControl method validate.
public BlazeValidationResult validate() {
// Validate project settings fields
String projectName = projectNameField.getText().trim();
if (StringUtil.isEmpty(projectName)) {
return BlazeValidationResult.failure(new BlazeValidationError("Project name is not specified"));
}
String projectDataDirPath = projectDataDirField.getText().trim();
if (StringUtil.isEmpty(projectDataDirPath)) {
return BlazeValidationResult.failure(new BlazeValidationError("Project data directory is not specified"));
}
File projectDataDir = new File(projectDataDirPath);
if (!projectDataDir.isAbsolute()) {
return BlazeValidationResult.failure(new BlazeValidationError("Project data directory is not valid"));
}
for (ProjectDataDirectoryValidator validator : ProjectDataDirectoryValidator.EP_NAME.getExtensions()) {
BlazeValidationResult result = validator.validateDataDirectory(projectDataDir);
if (!result.success) {
return result;
}
}
File workspaceRootDirectory = workspaceRoot.directory();
if (!workspaceOption.allowProjectDataInVcs() && FileUtil.isAncestor(workspaceRootDirectory, projectDataDir, false)) {
return BlazeValidationResult.failure(new BlazeValidationError("Project data directory cannot be inside your workspace. " + "Please choose a directory outside your workspace."));
}
List<IssueOutput> issues = Lists.newArrayList();
ProjectViewSet projectViewSet = projectViewUi.parseProjectView(issues);
BlazeValidationError projectViewParseError = validationErrorFromIssueList(issues);
if (projectViewParseError != null) {
return BlazeValidationResult.failure(projectViewParseError);
}
ProjectViewValidator projectViewValidator = new ProjectViewValidator(workspacePathResolver, projectViewSet);
ProgressManager.getInstance().runProcessWithProgressSynchronously(projectViewValidator, "Validating Project", false, null);
if (!projectViewValidator.success) {
if (!projectViewValidator.errors.isEmpty()) {
return BlazeValidationResult.failure(validationErrorFromIssueList(projectViewValidator.errors));
}
return BlazeValidationResult.failure("Project view validation failed, but we couldn't find an error message. " + "Please report a bug.");
}
List<DirectoryEntry> directories = projectViewSet.listItems(DirectorySection.KEY);
if (directories.isEmpty()) {
String msg = "Add some directories to index in the 'directories' section.";
if (projectViewSet.listItems(TargetSection.KEY).isEmpty()) {
msg += "\nTargets are also generally required to resolve sources.";
}
return BlazeValidationResult.failure(msg);
}
return BlazeValidationResult.success();
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class WorkspaceRootNode method getChildrenImpl.
@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
if (!BlazeUserSettings.getInstance().getCollapseProjectView()) {
return super.getChildrenImpl();
}
Project project = getProject();
if (project == null) {
return super.getChildrenImpl();
}
List<AbstractTreeNode> children = Lists.newArrayList();
ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (projectViewSet == null) {
return super.getChildrenImpl();
}
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, Blaze.getBuildSystem(project)).add(projectViewSet).build();
if (importRoots.rootDirectories().stream().anyMatch(WorkspacePath::isWorkspaceRoot)) {
return super.getChildrenImpl();
}
for (WorkspacePath workspacePath : importRoots.rootDirectories()) {
VirtualFile virtualFile = VfsUtil.findFileByIoFile(workspaceRoot.fileForPath(workspacePath), false);
if (virtualFile == null) {
continue;
}
PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFile);
if (psiDirectory == null) {
continue;
}
children.add(new BlazePsiDirectoryRootNode(project, psiDirectory, getSettings()));
}
if (children.isEmpty()) {
return super.getChildrenImpl();
}
return children;
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method importWorkspace.
private BlazeJavaImportResult importWorkspace(WorkspaceRoot workspaceRoot, TargetMapBuilder targetMapBuilder, ProjectView projectView) {
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
TargetMap targetMap = targetMapBuilder.build();
JavaSourceFilter sourceFilter = new JavaSourceFilter(project, workspaceRoot, projectViewSet, targetMap);
BlazeJavaWorkspaceImporter blazeWorkspaceImporter = new BlazeJavaWorkspaceImporter(project, workspaceRoot, projectViewSet, workspaceLanguageSettings, targetMap, sourceFilter, jdepsMap, workingSet, FAKE_ARTIFACT_DECODER);
return blazeWorkspaceImporter.importWorkspace(context);
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class BuildPluginBeforeRunTaskProvider method executeTask.
@Override
public final boolean executeTask(final DataContext dataContext, final RunConfiguration configuration, final ExecutionEnvironment env, Task task) {
if (!canExecuteTask(configuration, task)) {
return false;
}
BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
return Scope.root(context -> {
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
context.push(new ExperimentScope()).push(new IssuesScope(project, true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build()).push(new IdeaLogScope());
BlazeIntellijPluginDeployer deployer = env.getUserData(BlazeIntellijPluginDeployer.USER_DATA_KEY);
if (deployer == null) {
IssueOutput.error("Could not find BlazeIntellijPluginDeployer in env.").submit(context);
return false;
}
deployer.buildStarted();
final ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
if (projectViewSet == null) {
IssueOutput.error("Could not load project view. Please resync project").submit(context);
return false;
}
final ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {
@Override
protected Void execute(BlazeContext context) {
String binaryPath = Blaze.getBuildSystemProvider(project).getBinaryPath();
BlazeIntellijPluginConfiguration config = (BlazeIntellijPluginConfiguration) configuration;
ListenableFuture<String> executionRootFuture = BlazeInfoRunner.getInstance().runBlazeInfo(context, binaryPath, workspaceRoot, config.getBlazeFlagsState().getExpandedFlags(), BlazeInfo.EXECUTION_ROOT_KEY);
String executionRoot;
try {
executionRoot = executionRootFuture.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
context.setCancelled();
return null;
} catch (ExecutionException e) {
IssueOutput.error(e.getMessage()).submit(context);
context.setHasError();
return null;
}
if (executionRoot == null) {
IssueOutput.error("Could not determine execution root").submit(context);
return null;
}
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (blazeProjectData == null) {
IssueOutput.error("Could not determine execution root").submit(context);
return null;
}
try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(f -> true)) {
BlazeCommand command = BlazeCommand.builder(binaryPath, BlazeCommandName.BUILD).addTargets(config.getTarget()).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.BUILD, BlazeInvocationContext.NonSync)).addBlazeFlags(config.getBlazeFlagsState().getExpandedFlags()).addExeFlags(config.getExeFlagsState().getExpandedFlags()).addBlazeFlags(buildResultHelper.getBuildFlags()).build();
if (command == null || context.hasErrors() || context.isCancelled()) {
return null;
}
SaveUtil.saveAllFiles();
int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
if (retVal != 0) {
context.setHasError();
}
FileCaches.refresh(project);
deployer.reportBuildComplete(new File(executionRoot), buildResultHelper);
return null;
}
}
};
ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project).setTitle("Executing blaze build for IntelliJ plugin jar").submitTaskWithResult(buildTask);
try {
Futures.getChecked(buildFuture, ExecutionException.class);
} catch (ExecutionException e) {
context.setHasError();
} catch (CancellationException e) {
context.setCancelled();
}
if (context.hasErrors() || context.isCancelled()) {
return false;
}
return true;
});
}
use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.
the class BlazeScalaWorkspaceImporter method importWorkspace.
public BlazeScalaImportResult importWorkspace() {
ProjectViewTargetImportFilter importFilter = new ProjectViewTargetImportFilter(project, workspaceRoot, projectViewSet);
Collection<Kind> scalaKinds = Kind.allKindsForLanguage(LanguageClass.SCALA);
List<TargetKey> scalaSourceTargets = targetMap.targets().stream().filter(target -> target.javaIdeInfo != null).filter(target -> target.kindIsOneOf(scalaKinds)).filter(importFilter::isSourceTarget).map(target -> target.key).collect(Collectors.toList());
Map<LibraryKey, BlazeJarLibrary> libraries = Maps.newHashMap();
// but since they'll all merged into one set, we will end up with exactly one of each.
for (TargetKey dependency : TransitiveDependencyMap.getTransitiveDependencies(scalaSourceTargets, targetMap)) {
TargetIdeInfo target = targetMap.get(dependency);
if (target == null) {
continue;
}
// Except source targets.
if (JavaSourceFilter.importAsSource(importFilter, target)) {
continue;
}
if (target.javaIdeInfo != null) {
target.javaIdeInfo.jars.stream().map(BlazeJarLibrary::new).forEach(library -> libraries.putIfAbsent(library.key, library));
}
}
return new BlazeScalaImportResult(ImmutableMap.copyOf(libraries));
}
Aggregations