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));
}
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();
}
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();
}
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();
}
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();
}
Aggregations