Search in sources :

Example 31 with TargetMapBuilder

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

Example 32 with TargetMapBuilder

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");
}
Also used : 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 33 with TargetMapBuilder

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();
}
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 34 with TargetMapBuilder

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();
}
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 35 with TargetMapBuilder

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"));
}
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)

Aggregations

TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)49 Test (org.junit.Test)48 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)44 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)40 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)33 BlazeAndroidImportResult (com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult)13 AndroidAarIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo)7 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)7 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)7 BlazeAndroidLibrarySource (com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource)5 WorkingSet (com.google.idea.blaze.base.sync.workspace.WorkingSet)5 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)5 JavaWorkingSet (com.google.idea.blaze.java.sync.workingset.JavaWorkingSet)5 GenfilesPath (com.google.idea.blaze.android.projectview.GenfilesPath)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 BlazeResourceLibrary (com.google.idea.blaze.android.sync.model.BlazeResourceLibrary)3 BlazeTestCase (com.google.idea.blaze.base.BlazeTestCase)3 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)3 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)3