Search in sources :

Example 16 with TargetMapBuilder

use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder 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)

Example 17 with TargetMapBuilder

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

the class BlazeAndroidWorkspaceImporterTest method testAarImport_inSourcesAndNoJdeps_keepsAarLibrary.

@Test
public void testAarImport_inSourcesAndNoJdeps_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("com.google.android.example")).setJavaInfo(JavaIdeInfo.builder()).addSource(source("java/example/Source.java")).addDependency("//java/example:an_aar").build()).addTarget(TargetIdeInfo.builder().setLabel("//java/example:an_aar").setBuildFile(source("java/example/BUILD")).setKind(Kind.AAR_IMPORT).setAndroidAarInfo(new AndroidAarIdeInfo(source("java/example/an_aar.aar"))).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setClassJar(gen("java/example/_aar/an_aar/" + "classes_and_libs_merged.jar")))).build());
    BlazeJavaImportResult javaResult = importJavaWorkspace(workspaceRoot, targetMapBuilder, projectView);
    BlazeAndroidImportResult androidResult = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    assertThat(javaResult.libraries).isEmpty();
    assertThat(androidResult.aarLibraries.stream().map(BlazeAndroidWorkspaceImporterTest::aarName).collect(Collectors.toList())).containsExactly("an_aar.aar");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) 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)

Example 18 with TargetMapBuilder

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

the class BlazeAndroidWorkspaceImporterTest method testMixingGeneratedAndNonGeneratedSourcesGeneratesIssue.

@Test
public void testMixingGeneratedAndNonGeneratedSourcesGeneratesIssue() {
    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("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).addResource(gen("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).build());
    importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertIssueContaining("Dropping 1 generated resource");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 19 with TargetMapBuilder

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

the class BlazeAndroidWorkspaceImporterTest method testAarImport_inSources_createsAarLibrary.

@Test
public void testAarImport_inSources_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("com.google.android.example")).setJavaInfo(JavaIdeInfo.builder()).addSource(source("java/example/Source.java")).addDependency("//java/example:an_aar").build()).addTarget(TargetIdeInfo.builder().setLabel("//java/example:an_aar").setBuildFile(source("java/example/BUILD")).setKind(Kind.AAR_IMPORT).setAndroidAarInfo(new AndroidAarIdeInfo(source("java/example/an_aar.aar"))).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setClassJar(gen("java/example/_aar/an_aar/" + "classes_and_libs_merged.jar")))).build());
    jdepsMap.put(TargetKey.forPlainTarget(Label.create("//java/example:lib")), ImmutableList.of(jdepsPath("java/example/_aar/an_aar/classes_and_libs_merged.jar")));
    BlazeJavaImportResult javaResult = importJavaWorkspace(workspaceRoot, targetMapBuilder, projectView);
    BlazeAndroidImportResult androidResult = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    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("an_aar.aar");
    assertThat(javaResult.libraries).hasSize(1);
    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)

Example 20 with TargetMapBuilder

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

the class TransitiveAggregatorTest method testAggregate100.

@Test
public void testAggregate100() {
    TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder();
    // Put the targets with more dependencies first so we don't cheat with a partially filled map.
    for (int i = 99; i >= 0; --i) {
        TargetIdeInfo.Builder targetIdeInfoBuilder = TargetIdeInfo.builder().setLabel("//:t" + i);
        for (int j = i - 1; j >= 0; --j) {
            targetIdeInfoBuilder.addDependency("//:t" + j);
        }
        targetMapBuilder.addTarget(targetIdeInfoBuilder);
    }
    createCount = 0;
    reduceCount = 0;
    TargetKeyAggregator aggregator = new TargetKeyAggregator(targetMapBuilder.build());
    IntStream.range(0, 100).forEach(i -> assertThat(aggregator.get("//:t" + i)).containsExactlyElementsIn(IntStream.rangeClosed(0, i).boxed().map(j -> "//:t" + j).collect(Collectors.toList())));
    // One create per target.
    assertThat(createCount).isEqualTo(100);
    // One reduce per direct dependency: 0 + 1 + 2 + ... + 97 + 98 + 99 = 100*99/2
    assertThat(reduceCount).isEqualTo(4950);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) ImmutableSet(com.google.common.collect.ImmutableSet) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) RunWith(org.junit.runner.RunWith) Set(java.util.Set) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) Label(com.google.idea.blaze.base.model.primitives.Label) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) Test(org.junit.Test)

Aggregations

TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)49 Test (org.junit.Test)48 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)44 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)40 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)33 BlazeAndroidImportResult (com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult)13 AndroidAarIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo)7 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)7 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)7 BlazeAndroidLibrarySource (com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource)5 WorkingSet (com.google.idea.blaze.base.sync.workspace.WorkingSet)5 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)5 JavaWorkingSet (com.google.idea.blaze.java.sync.workingset.JavaWorkingSet)5 GenfilesPath (com.google.idea.blaze.android.projectview.GenfilesPath)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 BlazeResourceLibrary (com.google.idea.blaze.android.sync.model.BlazeResourceLibrary)3 BlazeTestCase (com.google.idea.blaze.base.BlazeTestCase)3 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)3 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)3