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