use of com.google.idea.blaze.base.projectview.ProjectView 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");
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testResourceInheritance.
/**
* Test that a two packages use the same un-imported android_library
*/
@Test
public void testResourceInheritance() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("javatests/apps/example")))).build();
/**
* Deps are project -> lib0 -> lib1 -> shared project -> shared
*/
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example/lib0:lib0").setKind("android_library").setBuildFile(source("java/apps/example/lib0/BUILD")).addSource(source("java/apps/example/lib0/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/lib0/AndroidManifest.xml")).addResource(source("java/apps/example/lib0/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example.lib0")).addDependency("//java/apps/example/lib1:lib1").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib0/lib0.jar")).setClassJar(gen("java/apps/example/lib0/lib0.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example/lib1:lib1").setKind("android_library").setBuildFile(source("java/apps/example/lib1/BUILD")).addSource(source("java/apps/example/lib1/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/lib1/AndroidManifest.xml")).addResource(source("java/apps/example/lib1/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example.lib1")).addDependency("//java/libraries/shared:shared").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib1/lib1.jar")).setClassJar(gen("java/apps/example/lib1/lib1.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example_debug").setKind("android_binary").setBuildFile(source("java/apps/example/BUILD")).addSource(source("java/apps/example/MainActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/AndroidManifest.xml")).addResource(source("java/apps/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example")).addDependency("//java/apps/example/lib0:lib0").addDependency("//java/libraries/shared:shared").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/example_debug.jar")).setClassJar(gen("java/apps/example/example_debug.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//java/libraries/shared:shared").setBuildFile(source("java/libraries/shared/BUILD")).setKind("android_library").addSource(source("java/libraries/shared/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/libraries/shared/AndroidManifest.xml")).addResource(source("java/libraries/shared/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.libraries.shared")).setBuildFile(source("java/libraries/shared/BUILD")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/libraries/shared.jar")).setClassJar(gen("java/libraries/shared.jar")))));
BlazeAndroidImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(result.androidResourceModules).containsExactly(AndroidResourceModule.builder(TargetKey.forPlainTarget(Label.create("//java/apps/example:example_debug"))).addResourceAndTransitiveResource(source("java/apps/example/res")).addTransitiveResource(source("java/apps/example/lib0/res")).addTransitiveResource(source("java/apps/example/lib1/res")).addTransitiveResource(source("java/libraries/shared/res")).addTransitiveResourceDependency("//java/apps/example/lib0:lib0").addTransitiveResourceDependency("//java/apps/example/lib1:lib1").addTransitiveResourceDependency("//java/libraries/shared:shared").build(), AndroidResourceModule.builder(TargetKey.forPlainTarget(Label.create("//java/apps/example/lib0:lib0"))).addResourceAndTransitiveResource(source("java/apps/example/lib0/res")).addTransitiveResource(source("java/apps/example/lib1/res")).addTransitiveResource(source("java/libraries/shared/res")).addTransitiveResourceDependency("//java/apps/example/lib1:lib1").addTransitiveResourceDependency("//java/libraries/shared:shared").build(), AndroidResourceModule.builder(TargetKey.forPlainTarget(Label.create("//java/apps/example/lib1:lib1"))).addResourceAndTransitiveResource(source("java/apps/example/lib1/res")).addTransitiveResource(source("java/libraries/shared/res")).addTransitiveResourceDependency("//java/libraries/shared:shared").build());
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testResourceImportOutsideSourceFilterIsAddedToResourceLibrary.
@Test
public void testResourceImportOutsideSourceFilterIsAddedToResourceLibrary() {
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")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).addDependency("//java/example2:resources").build()).addTarget(TargetIdeInfo.builder().setLabel("//java/example2:resources").setBuildFile(source("java/example2/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example2/AndroidManifest.xml")).addResource(source("java/example2/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example2")).build());
BlazeAndroidImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
BlazeResourceLibrary library = result.resourceLibrary;
assertThat(library).isNotNull();
assertThat(library.sources).containsExactly(ArtifactLocation.builder().setRelativePath("java/example2/res").setIsSource(true).build());
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testAndroidResourceImport.
@Test
public void testAndroidResourceImport() {
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().setLegacyResources(Label.create("//java/example:resources")).setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).build()).addTarget(TargetIdeInfo.builder().setLabel("//java/example:resources").setBuildFile(source("java/example/BUILD")).setKind("android_resources").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).build());
BlazeAndroidImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(result.androidResourceModules).containsExactly(AndroidResourceModule.builder(TargetKey.forPlainTarget(Label.create("//java/example:resources"))).addResourceAndTransitiveResource(source("java/example/res")).build());
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testLanguageLevelIsReadFromToolchain.
@Test
public void testLanguageLevelIsReadFromToolchain() {
ProjectView projectView = ProjectView.builder().build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java:toolchain").setBuildFile(source("java/BUILD")).setKind("java_toolchain").setJavaToolchainIdeInfo(JavaToolchainIdeInfo.builder().setSourceVersion("8").setTargetVersion("8")));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
assertThat(result.sourceVersion).isEqualTo("8");
}
Aggregations