use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testJarsGeneratedFromProjectSourcesExcluded.
@Test
public void testJarsGeneratedFromProjectSourcesExcluded() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example"))).add(DirectoryEntry.include(new WorkspacePath("thirdparty")))).build();
TargetMapBuilder targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example_debug").setBuildFile(source("java/apps/example/BUILD")).setKind("java_library").addSource(source("java/apps/example/Test.java")).setJavaInfo(JavaIdeInfo.builder()).addDependency("//thirdparty/a:a")).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty:jars").setKind("java_library").addSource(source("thirdparty/Other.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setClassJar(gen("thirdparty/a.jar"))).addJar(LibraryArtifact.builder().setClassJar(gen("thirdparty/c.jar")))).build());
jdepsMap.put(TargetKey.forPlainTarget(Label.create("//java/apps/example:example_debug")), Lists.newArrayList(jdepsPath("thirdparty/a.jar"), jdepsPath("thirdparty/c.jar")));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMap, projectView);
assertThat(result.libraries).isEmpty();
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testMixingGeneratedAndNonGeneratedSourcesPartlyWhitelisted.
@Test
public void testMixingGeneratedAndNonGeneratedSourcesPartlyWhitelisted() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/example"))).add(DirectoryEntry.include(new WorkspacePath("java/example2"))).add(DirectoryEntry.include(new WorkspacePath("java/uninterestingdir")))).add(ListSection.builder(GeneratedAndroidResourcesSection.KEY).add(new GenfilesPath("java/example/res")).add(new GenfilesPath("unused/whitelisted/path/res"))).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()).addTarget(TargetIdeInfo.builder().setLabel("//java/example2:lib").setBuildFile(source("java/example2/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example2/AndroidManifest.xml")).addResource(source("java/example2/res")).addResource(gen("java/example2/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example2")).build()).addTarget(TargetIdeInfo.builder().setLabel("//java/uninterestingdir:lib").setBuildFile(source("java/uninterestingdir/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/uninterestingdir/AndroidManifest.xml")).addResource(source("java/uninterestingdir/res")).addResource(gen("java/uninterestingdir/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.uninterestingdir")).build());
importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertIssues("Dropping 1 generated resource directories.\n" + "R classes will not contain resources from these directories.\n" + "Double-click to add to project view if needed to resolve references.", "Dropping generated resource directory " + String.format("'%s/java/example2/res'", FAKE_GEN_ROOT_EXECUTION_PATH_FRAGMENT) + " w/ 2 subdirs", "1 unused entries in project view section \"generated_android_resource_directories\":\n" + "unused/whitelisted/path/res");
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testEmptyResourceModuleIsAddedAsJar.
/**
* Test adding empty resource modules as jars.
*/
@Test
public void testEmptyResourceModuleIsAddedAsJar() {
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 (no res) -> lib1 (has res) \ -> lib2 (has res)
*/
TargetMapBuilder response = 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")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example.lib0").setResourceJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib0/lib0_resources.jar")).setClassJar(gen("java/apps/example/lib0/lib0_resources.jar")))).addDependency("//java/apps/example/lib1:lib1").addDependency("//java/apps/example/lib2:lib2").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib0/lib0.jar")).setClassJar(gen("java/apps/example/lib0/lib0.jar"))).addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib0/lib0_resources.jar")).setClassJar(gen("java/apps/example/lib0/lib0_resources.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").setResourceJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib1/li11_resources.jar")).setClassJar(gen("java/apps/example/lib1/lib1_resources.jar")))).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib1/lib1.jar")).setClassJar(gen("java/apps/example/lib1/lib1.jar"))).addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib1/lib1_resources.jar")).setClassJar(gen("java/apps/example/lib1/lib1_resources.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example/lib2:lib2").setBuildFile(source("java/apps/example/lib2/BUILD")).setKind("android_library").addSource(source("java/apps/example/lib2/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/lib2/AndroidManifest.xml")).addResource(source("java/apps/example/lib2/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.libraries.example.lib2").setResourceJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib2/lib2_resources.jar")).setClassJar(gen("java/apps/example/lib2/lib2_resources.jar")))).setBuildFile(source("java/apps/example/lib2/BUILD")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib2/lib2.jar")).setClassJar(gen("java/apps/example/lib2/lib2.jar"))).addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib2/lib2_resources.jar")).setClassJar(gen("java/apps/example/lib2/lib2_resources.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").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/example_debug.jar")).setClassJar(gen("java/apps/example/example_debug.jar")))));
TargetMap targetMap = response.build();
BlazeAndroidJavaSyncAugmenter syncAugmenter = new BlazeAndroidJavaSyncAugmenter();
List<BlazeJarLibrary> jars = Lists.newArrayList();
List<BlazeJarLibrary> genJars = Lists.newArrayList();
ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(ProjectViewSet.builder().add(projectView).build()).build();
ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
for (TargetIdeInfo target : targetMap.targets()) {
if (importRoots.importAsSource(target.key.label)) {
syncAugmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, jars, genJars);
}
}
assertThat(jars.stream().map(library -> library.libraryArtifact.interfaceJar).map(artifactLocation -> new File(artifactLocation.relativePath).getName()).collect(Collectors.toList())).containsExactly("lib0_resources.jar");
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporterTest method testAarImport_multipleJarLibraries_aarLibraryOnlyOverridesAarJar.
@Test
public void testAarImport_multipleJarLibraries_aarLibraryOnlyOverridesAarJar() {
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:consume_export_aar").addDependency("//third_party/lib:dep_library").build()).addTarget(TargetIdeInfo.builder().setLabel("//third_party/lib:consume_export_aar").setBuildFile(source("third_party/lib/BUILD")).setKind(Kind.AAR_IMPORT).setAndroidAarInfo(new AndroidAarIdeInfo(source("third_party/lib/lib1_aar.aar"))).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setClassJar(gen("third_party/lib/_aar/consume_export_aar/" + "classes_and_libs_merged.jar")))).addDependency("//third_party/lib:dep_aar").build()).addTarget(TargetIdeInfo.builder().setLabel("//third_party/lib:dep_aar").setBuildFile(source("third_party/lib/BUILD")).setKind(Kind.AAR_IMPORT).setAndroidAarInfo(new AndroidAarIdeInfo(source("third_party/lib/lib2_aar.aar"))).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setClassJar(gen("third_party/lib/_aar/dep_aar/" + "classes_and_libs_merged.jar")))).build()).addTarget(TargetIdeInfo.builder().setLabel("//third_party/lib:dep_library").setBuildFile(source("third_party/lib/BUILD")).setKind(Kind.ANDROID_LIBRARY).addSource(source("third_party/lib/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("third_party/lib/AndroidManifest.xml")).addResource(source("third_party/lib/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.lib")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("third_party/lib/dep_library.jar")).setClassJar(gen("third_party/lib/dep_library.jar")))).build());
jdepsMap.put(TargetKey.forPlainTarget(Label.create("//java/example:lib")), ImmutableList.of(jdepsPath("third_party/lib/_aar/dep_aar/classes_and_libs_merged.jar"), jdepsPath("third_party/lib/_aar/consume_export_aar/classes_and_libs_merged.jar"), jdepsPath("third_party/lib/dep_library.jar")));
BlazeJavaImportResult javaResult = importJavaWorkspace(workspaceRoot, targetMapBuilder, projectView);
BlazeAndroidImportResult androidResult = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(javaResult.libraries).hasSize(3);
assertThat(androidResult.aarLibraries).hasSize(2);
assertThat(androidResult.aarLibraries.stream().map(BlazeAndroidWorkspaceImporterTest::aarJarName).collect(Collectors.toList())).containsExactly("classes_and_libs_merged.jar", "classes_and_libs_merged.jar");
assertThat(androidResult.aarLibraries.stream().map(BlazeAndroidWorkspaceImporterTest::aarName).collect(Collectors.toList())).containsExactly("lib1_aar.aar", "lib2_aar.aar");
BlazeAndroidLibrarySource.AarJarFilter aarFilter = new BlazeAndroidLibrarySource.AarJarFilter(androidResult.aarLibraries);
ImmutableList<BlazeJarLibrary> blazeJarLibraries = javaResult.libraries.values().asList();
for (BlazeJarLibrary jarLibrary : blazeJarLibraries) {
if (libraryJarName(jarLibrary).equals("dep_library.jar")) {
assertThat(aarFilter.test(jarLibrary)).isTrue();
} else {
assertThat(aarFilter.test(jarLibrary)).isFalse();
}
}
}
use of com.google.idea.blaze.base.projectview.ProjectView 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();
}
Aggregations