Search in sources :

Example 6 with BlazeScalaImportResult

use of com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult 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 7 with BlazeScalaImportResult

use of com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testScalaBinaryWithMultipleLibraries.

@Test
public void testScalaBinaryWithMultipleLibraries() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/apps/example")))).build();
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/apps/example:example").setBuildFile(source("src/main/scala/apps/example/BUILD")).setKind("scala_binary").addSource(source("src/main/scala/apps/example/Main.scala")).addSource(source("src/main/scala/apps/example/subdir/SubdirHelper.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/apps/example/example.jar")).setClassJar(gen("src/main/scala/apps/example/example.jar")))).addDependency("//src/main/scala/some/library1:library1").addDependency("//src/main/java/other/library2:library2")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/some/library1:library1").setBuildFile(source("src/main/scala/some/library1/BUILD")).setKind("scala_library").addSource(source("src/main/scala/some/library1/Library.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/some/library1/library1_ijar.jar")).setClassJar(gen("src/main/scala/some/library1/library1.jar")))).addDependency("//src/main/java/other/import:import")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/java/other/library2:library2").setBuildFile(source("src/main/java/other/library2/BUILD")).setKind("java_library").addSource(source("src/main/java/other/library2/Library.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/java/other/library2/liblibrary2-ijar.jar")).setClassJar(gen("src/main/java/other/library2/liblibrary2.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//src/main/java/other/import:import").setBuildFile(source("src/main/java/other/import/BUILD")).setKind("java_import").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/java/other/import/libimport-ijar.jar")).setClassJar(gen("src/main/java/other/import/libimport.jar"))))).build();
    BlazeJavaImportResult javaImportResult = importJava(projectView, targetMap);
    BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
    errorCollector.assertNoIssues();
    assertThat(javaImportResult.contentEntries).containsExactly(BlazeContentEntry.builder("/root/src/main/scala/apps/example").addSource(BlazeSourceDirectory.builder("/root/src/main/scala/apps/example").setPackagePrefix("apps.example").build()).build());
    // Direct library deps will be double counted.
    assertThat(javaImportResult.libraries).hasSize(2);
    assertThat(hasLibrary(javaImportResult.libraries, "library1_ijar")).isTrue();
    assertThat(hasLibrary(javaImportResult.libraries, "library2-ijar")).isTrue();
    assertThat(javaImportResult.javaSourceFiles).containsExactly(source("src/main/scala/apps/example/Main.scala"), source("src/main/scala/apps/example/subdir/SubdirHelper.scala"));
    assertThat(scalaImportResult.libraries).hasSize(3);
    assertThat(hasLibrary(scalaImportResult.libraries, "library1_ijar")).isTrue();
    assertThat(hasLibrary(scalaImportResult.libraries, "library2-ijar")).isTrue();
    assertThat(hasLibrary(scalaImportResult.libraries, "import-ijar")).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 8 with BlazeScalaImportResult

use of com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testSourceTargetsWithoutNonGeneratedSourcesAddedToLibraries.

@Test
public void testSourceTargetsWithoutNonGeneratedSourcesAddedToLibraries() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/some/library")))).build();
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/apps/example:example").setBuildFile(source("src/main/scala/apps/example/BUILD")).setKind("scala_binary").addSource(source("src/main/scala/apps/example/Main.scala")).addSource(source("src/main/scala/apps/example/subdir/SubdirHelper.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/apps/example/example.jar")).setClassJar(gen("src/main/scala/apps/example/example.jar")))).addDependency("//src/main/scala/some/library:library")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/some/library:library").setBuildFile(source("src/main/scala/some/library/BUILD")).setKind("scala_library").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/some/library/library_ijar.jar")).setClassJar(gen("src/main/scala/some/library/library.jar"))))).build();
    BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
    errorCollector.assertNoIssues();
    assertThat(scalaImportResult.libraries).hasSize(1);
    assertThat(hasLibrary(scalaImportResult.libraries, "library_ijar")).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 9 with BlazeScalaImportResult

use of com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testSourceRulesNotInLibraries.

@Test
public void testSourceRulesNotInLibraries() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/some/library1"))).add(DirectoryEntry.include(new WorkspacePath("src/main/java/other/library2")))).build();
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/apps/example:example").setBuildFile(source("src/main/scala/apps/example/BUILD")).setKind("scala_binary").addSource(source("src/main/scala/apps/example/Main.scala")).addSource(source("src/main/scala/apps/example/subdir/SubdirHelper.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/apps/example/example.jar")).setClassJar(gen("src/main/scala/apps/example/example.jar")))).addDependency("//src/main/scala/some/library1:library1").addDependency("//src/main/java/other/library2:library2")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/some/library1:library1").setBuildFile(source("src/main/scala/some/library1/BUILD")).setKind("scala_library").addSource(source("src/main/scala/some/library1/Library.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/some/library1/library1_ijar.jar")).setClassJar(gen("src/main/scala/some/library1/library1.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//src/main/java/other/library2:library2").setBuildFile(source("src/main/java/other/library2/BUILD")).setKind("java_library").addSource(source("src/main/java/other/library2/Library.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/java/other/library2/libibrary2-ijar.jar")).setClassJar(gen("src/main/java/other/library2/liblibrary2.jar"))))).build();
    BlazeJavaImportResult javaImportResult = importJava(projectView, targetMap);
    BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
    errorCollector.assertNoIssues();
    assertThat(javaImportResult.contentEntries).containsExactly(BlazeContentEntry.builder("/root/src/main/scala/apps/example").addSource(BlazeSourceDirectory.builder("/root/src/main/scala/apps/example").setPackagePrefix("apps.example").build()).build(), BlazeContentEntry.builder("/root/src/main/scala/some/library1").addSource(BlazeSourceDirectory.builder("/root/src/main/scala/some/library1").setPackagePrefix("some.library1").build()).build(), BlazeContentEntry.builder("/root/src/main/java/other/library2").addSource(BlazeSourceDirectory.builder("/root/src/main/java/other/library2").setPackagePrefix("other.library2").build()).build());
    assertThat(javaImportResult.libraries).isEmpty();
    assertThat(javaImportResult.javaSourceFiles).containsExactly(source("src/main/scala/apps/example/Main.scala"), source("src/main/scala/apps/example/subdir/SubdirHelper.scala"), source("src/main/scala/some/library1/Library.scala"), source("src/main/java/other/library2/Library.java"));
    assertThat(scalaImportResult.libraries).isEmpty();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 10 with BlazeScalaImportResult

use of com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method testDuplicateScalaLibraries.

@Test
public void testDuplicateScalaLibraries() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/apps/example")))).build();
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/apps/example:example").setKind("scala_binary").addSource(source("src/main/scala/apps/example/Main.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/apps/example/example.jar")).setClassJar(gen("src/main/scala/apps/example/example.jar")))).addDependency("//src/main/scala/imports:import1").addDependency("//src/main/scala/imports:import2")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/imports:import1").setKind("scala_import").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/imports/import.jar")).setClassJar(gen("src/main/scala/imports/import.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/imports:import2").setKind("scala_import").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/imports/import.jar")).setClassJar(gen("src/main/scala/imports/import.jar"))))).build();
    BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
    errorCollector.assertNoIssues();
    assertThat(scalaImportResult.libraries).hasSize(1);
    assertThat(hasLibrary(scalaImportResult.libraries, "import")).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Aggregations

BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)10 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)9 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)8 Test (org.junit.Test)8 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)7 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)6 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps (com.google.common.collect.Maps)1 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)1 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)1 LibraryKey (com.google.idea.blaze.base.model.LibraryKey)1 Kind (com.google.idea.blaze.base.model.primitives.Kind)1 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)1 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 TimingScope (com.google.idea.blaze.base.scope.scopes.TimingScope)1 ProjectViewTargetImportFilter (com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter)1 TransitiveDependencyMap (com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap)1 JavaSourceFilter (com.google.idea.blaze.java.sync.importer.JavaSourceFilter)1 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)1