Search in sources :

Example 31 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot 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)

Example 32 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.

the class AllInPackageBlazeConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    PsiDirectory dir = getTestDirectory(context);
    if (dir == null) {
        return false;
    }
    WorkspaceRoot root = WorkspaceRoot.fromProject(context.getProject());
    WorkspacePath packagePath = getWorkspaceRelativeDirectoryPath(root, dir);
    if (packagePath == null) {
        return false;
    }
    sourceElement.set(dir);
    configuration.setTarget(TargetExpression.allFromPackageRecursive(packagePath));
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
    configuration.setGeneratedName();
    return true;
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) PsiDirectory(com.intellij.psi.PsiDirectory) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot)

Example 33 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.

the class AllInPackageBlazeConfigurationProducer method getTestDirectory.

@Nullable
private static PsiDirectory getTestDirectory(ConfigurationContext context) {
    WorkspaceRoot root = WorkspaceRoot.fromProject(context.getProject());
    PsiElement location = context.getPsiLocation();
    if (!(location instanceof PsiDirectory)) {
        return null;
    }
    PsiDirectory dir = (PsiDirectory) location;
    return isInWorkspace(root, dir) && BlazePackage.hasBlazePackageChild(dir) ? dir : null;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) PsiElement(com.intellij.psi.PsiElement) Nullable(javax.annotation.Nullable)

Example 34 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.

the class ExportRunConfigurationDialog method defaultExportDirectory.

/**
 * Try to find a checked-in project view file. Otherwise, fall back to the workspace root.
 */
@Nullable
private static File defaultExportDirectory(Project project) {
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProjectSafe(project);
    if (workspaceRoot == null) {
        return null;
    }
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    if (projectViewSet != null) {
        for (ProjectViewFile projectViewFile : projectViewSet.getProjectViewFiles()) {
            File file = projectViewFile.projectViewFile;
            if (file != null && FileUtil.isAncestor(workspaceRoot.directory(), file, false)) {
                return file.getParentFile();
            }
        }
    }
    return workspaceRoot.directory();
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectViewFile(com.google.idea.blaze.base.projectview.ProjectViewSet.ProjectViewFile) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 35 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.

the class BlazeBeforeRunCommandHelper method runBlazeBuild.

/**
 * Kicks off the blaze build task, returning a corresponding {@link ListenableFuture}.
 */
public static ListenableFuture<BuildResult> runBlazeBuild(BlazeCommandRunConfiguration configuration, BuildResultHelper buildResultHelper, List<String> requiredExtraBlazeFlags, List<String> overridableExtraBlazeFlags, String progressMessage) {
    Project project = configuration.getProject();
    BlazeCommandRunConfigurationCommonState handlerState = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    String binaryPath = handlerState.getBlazeBinaryState().getBlazeBinary() != null ? handlerState.getBlazeBinaryState().getBlazeBinary() : Blaze.getBuildSystemProvider(project).getBinaryPath();
    BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
    return ProgressiveTaskWithProgressIndicator.builder(project).submitTaskWithResult(new ScopedTask<BuildResult>() {

        @Override
        protected BuildResult execute(BlazeContext context) {
            context.push(new IssuesScope(project, true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build());
            context.output(new StatusOutput(progressMessage));
            BlazeCommand.Builder command = BlazeCommand.builder(binaryPath, BlazeCommandName.BUILD).addTargets(configuration.getTarget()).addBlazeFlags(overridableExtraBlazeFlags).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.BUILD, BlazeInvocationContext.NonSync)).addBlazeFlags(handlerState.getBlazeFlagsState().getExpandedFlags()).addBlazeFlags(requiredExtraBlazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags());
            int exitCode = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
            return BuildResult.fromExitCode(exitCode);
        }
    });
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Project(com.intellij.openapi.project.Project) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) BlazeConsolePopupBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior)

Aggregations

WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)50 File (java.io.File)30 Nullable (javax.annotation.Nullable)23 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)21 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)19 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)18 ImmutableList (com.google.common.collect.ImmutableList)14 List (java.util.List)13 Project (com.intellij.openapi.project.Project)12 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)10 Kind (com.google.idea.blaze.base.model.primitives.Kind)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Lists (com.google.common.collect.Lists)9 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)9 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)9 Collectors (java.util.stream.Collectors)9 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)8 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)8 Label (com.google.idea.blaze.base.model.primitives.Label)8 BlazeImportSettings (com.google.idea.blaze.base.settings.BlazeImportSettings)8