Search in sources :

Example 36 with ProjectViewSet

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();
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeValidationResult(com.google.idea.blaze.base.ui.BlazeValidationResult) BlazeValidationError(com.google.idea.blaze.base.ui.BlazeValidationError) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) File(java.io.File) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) ProjectDataDirectoryValidator(com.google.idea.blaze.base.wizard2.ProjectDataDirectoryValidator)

Example 37 with ProjectViewSet

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;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) PsiDirectory(com.intellij.psi.PsiDirectory) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 38 with ProjectViewSet

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);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Example 39 with ProjectViewSet

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;
    });
}
Also used : WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) ExecutionException(java.util.concurrent.ExecutionException) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) CancellationException(java.util.concurrent.CancellationException) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) File(java.io.File) BlazeConsolePopupBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior)

Example 40 with ProjectViewSet

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));
}
Also used : LibraryKey(com.google.idea.blaze.base.model.LibraryKey) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) TransitiveDependencyMap(com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap) List(java.util.List) Map(java.util.Map) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Project(com.intellij.openapi.project.Project) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)

Aggregations

ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)74 File (java.io.File)30 Test (org.junit.Test)29 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)21 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)17 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)17 ImmutableList (com.google.common.collect.ImmutableList)16 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)16 Project (com.intellij.openapi.project.Project)16 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)15 Nullable (javax.annotation.Nullable)15 List (java.util.List)14 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)12 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)11 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)11 Kind (com.google.idea.blaze.base.model.primitives.Kind)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 Set (java.util.Set)11 Lists (com.google.common.collect.Lists)10 Collectors (java.util.stream.Collectors)10