use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder 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.ideinfo.TargetMapBuilder 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");
}
use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testImportTargetOutput.
@Test
public void testImportTargetOutput() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("import")))).add(ListSection.builder(ImportTargetOutputSection.KEY).add(Label.create("//import:import"))).build();
TargetMapBuilder response = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//import:lib").setBuildFile(source("import/BUILD")).setKind("java_library").addSource(source("import/Lib.java")).setJavaInfo(JavaIdeInfo.builder()).addDependency("//import:import")).addTarget(TargetIdeInfo.builder().setLabel("//import:import").setBuildFile(source("import/BUILD")).setKind("java_library").addSource(source("import/Import.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("import/import.jar")).setClassJar(gen("import/import.jar")))));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, response, projectView);
errorCollector.assertNoIssues();
assertThat(result.libraries).isNotEmpty();
}
use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testLegacyProtoLibraryInfo.
/**
* Test legacy proto_library jars, complete with overrides and everything.
*/
@Test
public void testLegacyProtoLibraryInfo() {
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:liba").setBuildFile(source("java/example/BUILD")).setKind("java_library").addSource(source("java/example/Liba.java")).setJavaInfo(JavaIdeInfo.builder()).addDependency("//thirdparty/proto/a:a")).addTarget(TargetIdeInfo.builder().setLabel("//java/example:libb").setBuildFile(source("java/example/BUILD")).setKind("java_library").addSource(source("java/example/Libb.java")).setJavaInfo(JavaIdeInfo.builder()).addDependency("//thirdparty/proto/b:b")).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty/proto/a:a").setBuildFile(source("/thirdparty/a/BUILD")).setKind("proto_library").setProtoLibraryLegacyInfo(ProtoLibraryLegacyInfo.builder(ProtoLibraryLegacyInfo.ApiFlavor.IMMUTABLE).addJarV1(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/a/liba-1-ijar.jar"))).addJarImmutable(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/a/liba-ijar.jar")))).addDependency("//thirdparty/proto/b:b").addDependency("//thirdparty/proto/c:c")).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty/proto/b:b").setBuildFile(source("/thirdparty/b/BUILD")).setKind("proto_library").setProtoLibraryLegacyInfo(ProtoLibraryLegacyInfo.builder(ProtoLibraryLegacyInfo.ApiFlavor.VERSION_1).addJarV1(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/b/libb-ijar.jar"))).addJarImmutable(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/b/libb-2-ijar.jar")))).addDependency("//thirdparty/proto/d:d")).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty/proto/c:c").setBuildFile(source("/thirdparty/c/BUILD")).setKind("proto_library").setProtoLibraryLegacyInfo(ProtoLibraryLegacyInfo.builder(ProtoLibraryLegacyInfo.ApiFlavor.IMMUTABLE).addJarV1(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/c/libc-1-ijar.jar"))).addJarImmutable(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/c/libc-ijar.jar")))).addDependency("//thirdparty/proto/d:d")).addTarget(TargetIdeInfo.builder().setLabel("//thirdparty/proto/d:d").setBuildFile(source("/thirdparty/d/BUILD")).setKind("proto_library").setProtoLibraryLegacyInfo(ProtoLibraryLegacyInfo.builder(ProtoLibraryLegacyInfo.ApiFlavor.VERSION_1).addJarV1(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/d/libd-ijar.jar"))).addJarImmutable(LibraryArtifact.builder().setInterfaceJar(gen("thirdparty/proto/d/libd-2-ijar.jar")))));
workingSet = new JavaWorkingSet(workspaceRoot, new WorkingSet(ImmutableList.of(), ImmutableList.of(), ImmutableList.of()), Predicate.isEqual("BUILD"));
// First test - make sure that jdeps is working
jdepsMap.put(TargetKey.forPlainTarget(Label.create("//java/example:liba")), Lists.newArrayList(jdepsPath("thirdparty/proto/a/liba-ijar.jar")));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(result.libraries).hasSize(1);
assertThat(findLibrary(result.libraries, "liba-ijar.jar")).isNotNull();
// Second test
// Put everything in the working set, which should expand to include the direct deps
workingSet = new JavaWorkingSet(workspaceRoot, new WorkingSet(ImmutableList.of(new WorkspacePath("java/example/BUILD")), ImmutableList.of(), ImmutableList.of()), Predicate.isEqual("BUILD"));
result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(result.libraries).hasSize(2);
assertThat(findLibrary(result.libraries, "liba-ijar.jar")).isNotNull();
assertThat(findLibrary(result.libraries, "libb-ijar.jar")).isNotNull();
}
use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testSingleModule.
@Test
public void testSingleModule() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example")))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example_debug").setBuildFile(source("java/apps/example/BUILD")).setKind("android_binary").addSource(source("java/apps/example/MainActivity.java")).addSource(source("java/apps/example/subdir/SubdirHelper.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")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/example_debug-ijar.jar")).setClassJar(gen("java/apps/example/example_debug.jar")))));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(result.buildOutputJars).hasSize(1);
ArtifactLocation compilerOutputLib = result.buildOutputJars.iterator().next();
assertNotNull(compilerOutputLib);
assertThat(compilerOutputLib.relativePath).endsWith("example_debug.jar");
assertThat(result.contentEntries).containsExactly(BlazeContentEntry.builder("/root/java/apps/example").addSource(BlazeSourceDirectory.builder("/root/java/apps/example").setPackagePrefix("apps.example").build()).build());
assertThat(result.javaSourceFiles).containsExactly(source("java/apps/example/MainActivity.java"), source("java/apps/example/subdir/SubdirHelper.java"));
}
Aggregations