use of com.google.idea.blaze.base.projectview.ProjectView 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.projectview.ProjectView 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.projectview.ProjectView 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"));
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testImporterWorksWithWorkspaceRootDirectoryIncluded.
/**
* Test that the non-android libraries can be imported.
*/
@Test
public void testImporterWorksWithWorkspaceRootDirectoryIncluded() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("")))).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")).setJavaInfo(JavaIdeInfo.builder()).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/library/something:something")).addTarget(TargetIdeInfo.builder().setLabel("//java/library/something:something").setBuildFile(source("java/library/something/BUILD")).setKind("java_library").addSource(source("java/library/something/SomeJavaFile.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/library/something/something.jar")).setClassJar(gen("java/library/something/something.jar")))));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(result.contentEntries).containsExactly(BlazeContentEntry.builder("/root").addSource(BlazeSourceDirectory.builder("/root").build()).addSource(BlazeSourceDirectory.builder("/root/java").build()).build());
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testLibraryDependenciesWithJdepsSet.
@Test
public void testLibraryDependenciesWithJdepsSet() {
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();
TargetMapBuilder targetMapBuilder = targetMapForJdepsSuite();
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, targetMapBuilder, projectView);
assertThat(result.libraries.values().stream().map(BlazeJavaWorkspaceImporterTest::libraryFileName).collect(Collectors.toList())).containsExactly("a.jar", "c.jar");
}
Aggregations