use of com.google.idea.blaze.java.sync.model.BlazeJavaImportResult in project intellij by bazelbuild.
the class BlazeScalaWorkspaceImporterTest method testTwoScalaBinariesWithSharedLibrary.
@Test
public void testTwoScalaBinariesWithSharedLibrary() {
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/apps/other")))).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/apps/other:other").setBuildFile(source("src/main/scala/apps/other/BUILD")).setKind("scala_binary").addSource(source("src/main/scala/apps/other/Main.scala")).addSource(source("src/main/scala/apps/other/subdir/SubdirHelper.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/apps/other/other.jar")).setClassJar(gen("src/main/scala/apps/other/other.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").addSource(source("src/main/scala/some/library/Library.scala")).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();
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/apps/other").addSource(BlazeSourceDirectory.builder("/root/src/main/scala/apps/other").setPackagePrefix("apps.other").build()).build());
// Direct library deps will be double counted.
assertThat(javaImportResult.libraries).hasSize(1);
assertThat(hasLibrary(javaImportResult.libraries, "library_ijar")).isTrue();
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/apps/other/Main.scala"), source("src/main/scala/apps/other/subdir/SubdirHelper.scala"));
assertThat(scalaImportResult.libraries).hasSize(1);
assertThat(hasLibrary(scalaImportResult.libraries, "library_ijar")).isTrue();
}
use of com.google.idea.blaze.java.sync.model.BlazeJavaImportResult in project intellij by bazelbuild.
the class BlazeScalaWorkspaceImporterTest method testEmptyProject.
@Test
public void testEmptyProject() {
ProjectView projectView = ProjectView.builder().build();
TargetMap targetMap = TargetMapBuilder.builder().build();
BlazeJavaImportResult javaImportResult = importJava(projectView, targetMap);
BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
errorCollector.assertNoIssues();
assertThat(javaImportResult.libraries).isEmpty();
assertThat(javaImportResult.contentEntries).isEmpty();
assertThat(javaImportResult.javaSourceFiles).isEmpty();
assertThat(javaImportResult.libraries).isEmpty();
assertThat(scalaImportResult.libraries).isEmpty();
}
use of com.google.idea.blaze.java.sync.model.BlazeJavaImportResult in project intellij by bazelbuild.
the class BlazeScalaWorkspaceImporterTest method testScalaAndJavaBinary.
@Test
public void testScalaAndJavaBinary() {
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/java/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"))))).addTarget(TargetIdeInfo.builder().setLabel("//src/main/java/apps/example:example").setBuildFile(source("src/main/java/apps/example/BUILD")).setKind("java_binary").addSource(source("src/main/java/apps/example/Main.java")).addSource(source("src/main/java/apps/example/subdir/SubdirHelper.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/java/apps/example/example.jar")).setClassJar(gen("src/main/java/apps/example/example.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/java/apps/example").addSource(BlazeSourceDirectory.builder("/root/src/main/java/apps/example").setPackagePrefix("apps.example").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/java/apps/example/Main.java"), source("src/main/java/apps/example/subdir/SubdirHelper.java"));
assertThat(scalaImportResult.libraries).isEmpty();
}
use of com.google.idea.blaze.java.sync.model.BlazeJavaImportResult in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method importWorkspace.
public BlazeJavaImportResult importWorkspace(BlazeContext context) {
WorkspaceBuilder workspaceBuilder = new WorkspaceBuilder();
for (TargetIdeInfo target : sourceFilter.sourceTargets) {
addTargetAsSource(workspaceBuilder, target, sourceFilter.targetToJavaSources.get(target.key));
}
SourceDirectoryCalculator sourceDirectoryCalculator = new SourceDirectoryCalculator();
ImmutableList<BlazeContentEntry> contentEntries = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, artifactLocationDecoder, importRoots, workspaceBuilder.sourceArtifacts, workspaceBuilder.javaPackageManifests);
int totalContentEntryCount = 0;
for (BlazeContentEntry contentEntry : contentEntries) {
totalContentEntryCount += contentEntry.sources.size();
}
context.output(PrintOutput.log("Java content entry count: " + totalContentEntryCount));
ImmutableMap<LibraryKey, BlazeJarLibrary> libraries = buildLibraries(workspaceBuilder, targetMap, sourceFilter.libraryTargets, sourceFilter.protoLibraries);
duplicateSourceDetector.reportDuplicates(context);
String sourceVersion = findSourceVersion(targetMap);
return new BlazeJavaImportResult(contentEntries, libraries, ImmutableList.copyOf(workspaceBuilder.buildOutputJars.stream().sorted().collect(Collectors.toList())), ImmutableSet.copyOf(workspaceBuilder.addedSourceFiles), sourceVersion);
}
use of com.google.idea.blaze.java.sync.model.BlazeJavaImportResult in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testAarImport_outsideSourcesAndNoJdeps_keepsAarLibrary.
@Test
public void testAarImport_outsideSourcesAndNoJdeps_keepsAarLibrary() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/example:lib").setBuildFile(source("java/example/BUILD")).setKind(Kind.ANDROID_LIBRARY).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("example")).setJavaInfo(JavaIdeInfo.builder()).addSource(source("java/example/Source.java")).addDependency("//third_party/lib:an_aar").build()).addTarget(TargetIdeInfo.builder().setLabel("//third_party/lib:an_aar").setBuildFile(source("third_party/lib/BUILD")).setKind(Kind.AAR_IMPORT).setAndroidAarInfo(new AndroidAarIdeInfo(source("third_party/lib/lib_aar.aar"))).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setClassJar(gen("third_party/lib/_aar/an_aar/" + "classes_and_libs_merged.jar")))).build());
BlazeJavaImportResult javaResult = importJavaWorkspace(workspaceRoot, targetMapBuilder, projectView);
BlazeAndroidImportResult androidResult = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
// The java importer performs jdeps optimization, but the android one does not.
assertThat(javaResult.libraries).isEmpty();
assertThat(androidResult.aarLibraries.stream().map(BlazeAndroidWorkspaceImporterTest::aarName).collect(Collectors.toList())).containsExactly("lib_aar.aar");
}
Aggregations