Search in sources :

Example 1 with BlazeAndroidLibrarySource

use of com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method testAarImport_outsideSources_createsAarLibrary.

@Test
public void testAarImport_outsideSources_createsAarLibrary() {
    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());
    jdepsMap.put(TargetKey.forPlainTarget(Label.create("//java/example:lib")), ImmutableList.of(jdepsPath("third_party/lib/_aar/an_aar/classes_and_libs_merged.jar")));
    BlazeJavaImportResult javaResult = importJavaWorkspace(workspaceRoot, targetMapBuilder, projectView);
    BlazeAndroidImportResult androidResult = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    // We get 2 libraries representing the AAR. One from java and one from android.
    assertThat(javaResult.libraries).hasSize(1);
    assertThat(androidResult.aarLibraries).hasSize(1);
    assertThat(androidResult.aarLibraries.stream().map(BlazeAndroidWorkspaceImporterTest::aarJarName).collect(Collectors.toList())).containsExactly("classes_and_libs_merged.jar");
    assertThat(androidResult.aarLibraries.stream().map(BlazeAndroidWorkspaceImporterTest::aarName).collect(Collectors.toList())).containsExactly("lib_aar.aar");
    // Check that BlazeAndroidLibrarySource can filter out the java one, so that only the
    // android version takes effect.
    BlazeAndroidLibrarySource.AarJarFilter aarFilter = new BlazeAndroidLibrarySource.AarJarFilter(androidResult.aarLibraries);
    assertThat(aarFilter.test(javaResult.libraries.values().asList().get(0))).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeAndroidLibrarySource(com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource) AndroidAarIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo) BlazeAndroidImportResult(com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Aggregations

BlazeAndroidLibrarySource (com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource)1 BlazeAndroidImportResult (com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult)1 AndroidAarIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo)1 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)1 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)1 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)1 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)1 Test (org.junit.Test)1