Search in sources :

Example 36 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class TransitiveDependencyMap method getTransitiveDependencies.

public static ImmutableCollection<TargetKey> getTransitiveDependencies(Collection<TargetKey> targetKeys, TargetMap targetMap) {
    Queue<TargetKey> targetsToVisit = Queues.newArrayDeque();
    Set<TargetKey> transitiveDependencies = Sets.newHashSet();
    targetsToVisit.addAll(targetKeys);
    while (!targetsToVisit.isEmpty()) {
        TargetIdeInfo currentTarget = targetMap.get(targetsToVisit.remove());
        if (currentTarget == null) {
            continue;
        }
        List<TargetKey> newDependencies = currentTarget.dependencies.stream().map(d -> TargetKey.forPlainTarget(d.targetKey.label)).filter(r -> !transitiveDependencies.contains(r)).collect(Collectors.toList());
        targetsToVisit.addAll(newDependencies);
        transitiveDependencies.addAll(newDependencies);
    }
    return ImmutableSet.copyOf(transitiveDependencies);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) ImmutableCollection(com.google.common.collect.ImmutableCollection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) Queues(com.google.common.collect.Queues) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) ImmutableList(com.google.common.collect.ImmutableList) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Queue(java.util.Queue) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey)

Example 37 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap 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 38 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap 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 39 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class KotlinSyncTest method testSimpleSync.

@Test
public void testSimpleSync() {
    setProjectView("directories:", "  src/main/kotlin/com/google", "targets:", "  //src/main/kotlin/com/google:lib", "additional_languages:", "  kotlin");
    workspace.createFile(new WorkspacePath("src/main/kotlin/com/google/Source.kt"), "package com.google;", "public class Source {}");
    workspace.createFile(new WorkspacePath("src/main/kotlin/com/google/Other.kt"), "package com.google;", "public class Other {}");
    workspace.createDirectory(new WorkspacePath("external/com_github_jetbrains_kotlin"));
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("src/main/kotlin/com/google/BUILD")).setLabel("//src/main/kotlin/com/google:lib").setKind("kt_jvm_library").addSource(sourceRoot("src/main/kotlin/com/google/Source.kotlin")).addSource(sourceRoot("src/main/kotlin/com/google/Other.kotlin")).setJavaInfo(JavaIdeInfo.builder())).build();
    setTargetMap(targetMap);
    runBlazeSync(new BlazeSyncParams.Builder("Sync", BlazeSyncParams.SyncMode.INCREMENTAL).addProjectViewTargets(true).build());
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
    assertThat(blazeProjectData).isNotNull();
    assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
    assertThat(blazeProjectData.workspaceLanguageSettings).isEqualTo(new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.GENERIC, LanguageClass.KOTLIN, LanguageClass.JAVA)));
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeSyncParams(com.google.idea.blaze.base.sync.BlazeSyncParams) Test(org.junit.Test)

Example 40 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class MockBlazeProjectDataBuilder method build.

public BlazeProjectData build() {
    TargetMap targetMap = this.targetMap != null ? this.targetMap : new TargetMap(ImmutableMap.of());
    BlazeInfo blazeInfo = this.blazeInfo;
    if (blazeInfo == null) {
        String outputBase = this.outputBase != null ? this.outputBase : "/usr/workspace/1234";
        blazeInfo = BlazeInfo.createMockBlazeInfo(outputBase, outputBase + "/execroot", outputBase + "/execroot/bin", outputBase + "/execroot/gen");
    }
    BlazeVersionData blazeVersionData = this.blazeVersionData != null ? this.blazeVersionData : BlazeVersionData.builder().build();
    WorkspacePathResolver workspacePathResolver = this.workspacePathResolver != null ? this.workspacePathResolver : new WorkspacePathResolverImpl(workspaceRoot);
    ArtifactLocationDecoder artifactLocationDecoder = this.artifactLocationDecoder != null ? this.artifactLocationDecoder : new ArtifactLocationDecoderImpl(blazeInfo, workspacePathResolver);
    WorkspaceLanguageSettings workspaceLanguageSettings = this.workspaceLanguageSettings != null ? this.workspaceLanguageSettings : new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of());
    SyncState syncState = this.syncState != null ? this.syncState : new SyncState(ImmutableMap.of());
    ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = this.reverseDependencies != null ? this.reverseDependencies : ImmutableMultimap.of();
    return new BlazeProjectData(syncTime, targetMap, blazeInfo, blazeVersionData, workspacePathResolver, artifactLocationDecoder, workspaceLanguageSettings, syncState, reverseDependencies);
}
Also used : BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) ArtifactLocationDecoderImpl(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoderImpl) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Aggregations

TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)77 Test (org.junit.Test)56 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)33 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)27 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)26 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)17 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)16 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)15 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)12 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)10 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)10 BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)10 File (java.io.File)10 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)9 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)9 ImmutableList (com.google.common.collect.ImmutableList)8 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)8 ImmutableSet (com.google.common.collect.ImmutableSet)7