Search in sources :

Example 51 with ProjectView

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();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 52 with ProjectView

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();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) JavaWorkingSet(com.google.idea.blaze.java.sync.workingset.JavaWorkingSet) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) JavaWorkingSet(com.google.idea.blaze.java.sync.workingset.JavaWorkingSet) WorkingSet(com.google.idea.blaze.base.sync.workspace.WorkingSet) Test(org.junit.Test)

Example 53 with ProjectView

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"));
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 54 with ProjectView

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());
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Example 55 with ProjectView

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");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) Test(org.junit.Test)

Aggregations

ProjectView (com.google.idea.blaze.base.projectview.ProjectView)87 Test (org.junit.Test)81 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)55 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)45 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)40 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)33 BlazeAndroidImportResult (com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult)13 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)12 File (java.io.File)12 BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)9 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)8 AndroidAarIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo)7 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)6 WorkingSet (com.google.idea.blaze.base.sync.workspace.WorkingSet)5 JavaWorkingSet (com.google.idea.blaze.java.sync.workingset.JavaWorkingSet)5 ImmutableList (com.google.common.collect.ImmutableList)4 GenfilesPath (com.google.idea.blaze.android.projectview.GenfilesPath)4 BlazeAndroidLibrarySource (com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource)4 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)4 DirectorySection (com.google.idea.blaze.base.projectview.section.sections.DirectorySection)4