use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testExcludeTarget.
/*
* Test the exclude_target section
*/
@Test
public void testExcludeTarget() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/apps/example")))).add(ListSection.builder(ExcludeTargetSection.KEY).add(Label.create("//java/apps/example:example"))).build();
TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example").setBuildFile(source("java/apps/example/BUILD")).setKind("java_library").addSource(source("java/apps/example/Example.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("example.jar")))));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
errorCollector.assertNoIssues();
assertThat(result.javaSourceFiles).isEmpty();
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testImportAsLibraryTagLegacy.
@Test
public void testImportAsLibraryTagLegacy() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("lib"))).add(DirectoryEntry.include(new WorkspacePath("lib2")))).build();
TargetMapBuilder response = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//lib:lib").setBuildFile(source("lib/BUILD")).setKind("java_library").addSource(source("lib/Lib.java")).addDependency("//lib2:lib2").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("lib/lib.jar")).setClassJar(gen("lib/lib.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//lib2:lib2").setBuildFile(source("lib2/BUILD")).setKind("java_library").addSource(source("lib2/Lib2.java")).addTag("aswb-import-as-library").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("lib2/lib2.jar")).setClassJar(gen("lib2/lib2.jar")))));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, response, projectView);
errorCollector.assertNoIssues();
assertThat(result.libraries).hasSize(1);
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporterTest method testTargetWithMixedGeneratedSourcesAddsFilteredGenJar.
@Test
public void testTargetWithMixedGeneratedSourcesAddsFilteredGenJar() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("import")))).build();
TargetMapBuilder response = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//import:lib").setBuildFile(source("import/BUILD")).setKind("java_library").addSource(source("import/Import.java")).addSource(gen("import/Import.java")).setJavaInfo(JavaIdeInfo.builder().setFilteredGenJar(LibraryArtifact.builder().setInterfaceJar(gen("import/filtered-gen.jar")))));
BlazeJavaImportResult result = importWorkspace(workspaceRoot, response, projectView);
errorCollector.assertNoIssues();
assertThat(findLibrary(result.libraries, "filtered-gen.jar")).isNotNull();
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class ProjectViewParserTest method testRootDirectory.
@Test
public void testRootDirectory() throws Exception {
projectViewStorageManager.add(".blazeproject", "directories:", " .", " -java/com/google/android/notme", "", "targets:", " //java/com/google:all");
projectViewParser.parseProjectView(new File(".blazeproject"));
errorCollector.assertNoIssues();
ProjectViewSet projectViewSet = projectViewParser.getResult();
ProjectViewSet.ProjectViewFile projectViewFile = projectViewSet.getTopLevelProjectViewFile();
assertThat(projectViewFile).isNotNull();
assertThat(projectViewFile.projectViewFile).isEqualTo(new File(".blazeproject"));
assertThat(projectViewSet.getProjectViewFiles()).containsExactly(projectViewFile);
ProjectView projectView = projectViewFile.projectView;
assertThat(projectView.getSectionsOfType(DirectorySection.KEY).get(0).items()).containsExactly(new DirectoryEntry(new WorkspacePath(""), true), new DirectoryEntry(new WorkspacePath("java/com/google/android/notme"), false));
assertThat(projectView.getSectionsOfType(TargetSection.KEY).get(0).items()).containsExactly(TargetExpression.fromStringSafe("//java/com/google:all"));
String text = ProjectViewParser.projectViewToString(projectView);
assertThat(text).isEqualTo(Joiner.on('\n').join("directories:", " .", " -java/com/google/android/notme", "", "targets:", " //java/com/google:all"));
}
use of com.google.idea.blaze.base.projectview.ProjectView in project intellij by bazelbuild.
the class BlazeScalaWorkspaceImporterTest method testScalaBinaryWithMultipleLibraries.
@Test
public void testScalaBinaryWithMultipleLibraries() {
ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("src/main/scala/apps/example")))).build();
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/apps/example:example").setBuildFile(source("src/main/scala/apps/example/BUILD")).setKind("scala_binary").addSource(source("src/main/scala/apps/example/Main.scala")).addSource(source("src/main/scala/apps/example/subdir/SubdirHelper.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/apps/example/example.jar")).setClassJar(gen("src/main/scala/apps/example/example.jar")))).addDependency("//src/main/scala/some/library1:library1").addDependency("//src/main/java/other/library2:library2")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/scala/some/library1:library1").setBuildFile(source("src/main/scala/some/library1/BUILD")).setKind("scala_library").addSource(source("src/main/scala/some/library1/Library.scala")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/scala/some/library1/library1_ijar.jar")).setClassJar(gen("src/main/scala/some/library1/library1.jar")))).addDependency("//src/main/java/other/import:import")).addTarget(TargetIdeInfo.builder().setLabel("//src/main/java/other/library2:library2").setBuildFile(source("src/main/java/other/library2/BUILD")).setKind("java_library").addSource(source("src/main/java/other/library2/Library.java")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/java/other/library2/liblibrary2-ijar.jar")).setClassJar(gen("src/main/java/other/library2/liblibrary2.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//src/main/java/other/import:import").setBuildFile(source("src/main/java/other/import/BUILD")).setKind("java_import").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("src/main/java/other/import/libimport-ijar.jar")).setClassJar(gen("src/main/java/other/import/libimport.jar"))))).build();
BlazeJavaImportResult javaImportResult = importJava(projectView, targetMap);
BlazeScalaImportResult scalaImportResult = importScala(projectView, targetMap);
errorCollector.assertNoIssues();
assertThat(javaImportResult.contentEntries).containsExactly(BlazeContentEntry.builder("/root/src/main/scala/apps/example").addSource(BlazeSourceDirectory.builder("/root/src/main/scala/apps/example").setPackagePrefix("apps.example").build()).build());
// Direct library deps will be double counted.
assertThat(javaImportResult.libraries).hasSize(2);
assertThat(hasLibrary(javaImportResult.libraries, "library1_ijar")).isTrue();
assertThat(hasLibrary(javaImportResult.libraries, "library2-ijar")).isTrue();
assertThat(javaImportResult.javaSourceFiles).containsExactly(source("src/main/scala/apps/example/Main.scala"), source("src/main/scala/apps/example/subdir/SubdirHelper.scala"));
assertThat(scalaImportResult.libraries).hasSize(3);
assertThat(hasLibrary(scalaImportResult.libraries, "library1_ijar")).isTrue();
assertThat(hasLibrary(scalaImportResult.libraries, "library2-ijar")).isTrue();
assertThat(hasLibrary(scalaImportResult.libraries, "import-ijar")).isTrue();
}
Aggregations