Search in sources :

Example 26 with TargetMapBuilder

use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method testConflictingResourceRClasses.

@Test
public void testConflictingResourceRClasses() {
    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().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).addDependency("//java/example2:resources").build()).addTarget(TargetIdeInfo.builder().setLabel("//java/example:lib2").setBuildFile(source("java/example2/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example2/AndroidManifest.xml")).addResource(source("java/example/res2")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).build());
    BlazeAndroidImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertIssueContaining("Multiple R classes generated");
    assertThat(result.androidResourceModules).containsExactly(AndroidResourceModule.builder(TargetKey.forPlainTarget(Label.create("//java/example:lib"))).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 27 with TargetMapBuilder

use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method testMixingGeneratedAndNonGeneratedSourcesWhitelisted.

@Test
public void testMixingGeneratedAndNonGeneratedSourcesWhitelisted() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("java/example")))).add(ListSection.builder(GeneratedAndroidResourcesSection.KEY).add(new GenfilesPath("java/example/res"))).build();
    TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/example:lib").setBuildFile(source("java/example/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).addResource(gen("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:lib"))).addResourceAndTransitiveResource(source("java/example/res")).addResourceAndTransitiveResource(gen("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) GenfilesPath(com.google.idea.blaze.android.projectview.GenfilesPath) Test(org.junit.Test)

Example 28 with TargetMapBuilder

use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method testAarImport_outsideSourcesAndNoJdeps_keepsAarLibrary.

@Test
public void testAarImport_outsideSourcesAndNoJdeps_keepsAarLibrary() {
    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(Kind.ANDROID_LIBRARY).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("example")).setJavaInfo(JavaIdeInfo.builder()).addSource(source("java/example/Source.java")).addDependency("//third_party/lib:an_aar").build()).addTarget(TargetIdeInfo.builder().setLabel("//third_party/lib:an_aar").setBuildFile(source("third_party/lib/BUILD")).setKind(Kind.AAR_IMPORT).setAndroidAarInfo(new AndroidAarIdeInfo(source("third_party/lib/lib_aar.aar"))).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setClassJar(gen("third_party/lib/_aar/an_aar/" + "classes_and_libs_merged.jar")))).build());
    BlazeJavaImportResult javaResult = importJavaWorkspace(workspaceRoot, targetMapBuilder, projectView);
    BlazeAndroidImportResult androidResult = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    // The java importer performs jdeps optimization, but the android one does not.
    assertThat(javaResult.libraries).isEmpty();
    assertThat(androidResult.aarLibraries.stream().map(BlazeAndroidWorkspaceImporterTest::aarName).collect(Collectors.toList())).containsExactly("lib_aar.aar");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) AndroidAarIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo) BlazeAndroidImportResult(com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult) 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 29 with TargetMapBuilder

use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method testResourceInheritance.

/**
 * Test that a two packages use the same un-imported android_library
 */
@Test
public void testResourceInheritance() {
    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();
    /**
     * Deps are project -> lib0 -> lib1 -> shared project -> shared
     */
    TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example/lib0:lib0").setKind("android_library").setBuildFile(source("java/apps/example/lib0/BUILD")).addSource(source("java/apps/example/lib0/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/lib0/AndroidManifest.xml")).addResource(source("java/apps/example/lib0/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example.lib0")).addDependency("//java/apps/example/lib1:lib1").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib0/lib0.jar")).setClassJar(gen("java/apps/example/lib0/lib0.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example/lib1:lib1").setKind("android_library").setBuildFile(source("java/apps/example/lib1/BUILD")).addSource(source("java/apps/example/lib1/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/apps/example/lib1/AndroidManifest.xml")).addResource(source("java/apps/example/lib1/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.apps.example.lib1")).addDependency("//java/libraries/shared:shared").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/lib1/lib1.jar")).setClassJar(gen("java/apps/example/lib1/lib1.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//java/apps/example:example_debug").setKind("android_binary").setBuildFile(source("java/apps/example/BUILD")).addSource(source("java/apps/example/MainActivity.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")).addDependency("//java/apps/example/lib0:lib0").addDependency("//java/libraries/shared:shared").setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/apps/example/example_debug.jar")).setClassJar(gen("java/apps/example/example_debug.jar"))))).addTarget(TargetIdeInfo.builder().setLabel("//java/libraries/shared:shared").setBuildFile(source("java/libraries/shared/BUILD")).setKind("android_library").addSource(source("java/libraries/shared/SharedActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/libraries/shared/AndroidManifest.xml")).addResource(source("java/libraries/shared/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.libraries.shared")).setBuildFile(source("java/libraries/shared/BUILD")).setJavaInfo(JavaIdeInfo.builder().addJar(LibraryArtifact.builder().setInterfaceJar(gen("java/libraries/shared.jar")).setClassJar(gen("java/libraries/shared.jar")))));
    BlazeAndroidImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    assertThat(result.androidResourceModules).containsExactly(AndroidResourceModule.builder(TargetKey.forPlainTarget(Label.create("//java/apps/example:example_debug"))).addResourceAndTransitiveResource(source("java/apps/example/res")).addTransitiveResource(source("java/apps/example/lib0/res")).addTransitiveResource(source("java/apps/example/lib1/res")).addTransitiveResource(source("java/libraries/shared/res")).addTransitiveResourceDependency("//java/apps/example/lib0:lib0").addTransitiveResourceDependency("//java/apps/example/lib1:lib1").addTransitiveResourceDependency("//java/libraries/shared:shared").build(), AndroidResourceModule.builder(TargetKey.forPlainTarget(Label.create("//java/apps/example/lib0:lib0"))).addResourceAndTransitiveResource(source("java/apps/example/lib0/res")).addTransitiveResource(source("java/apps/example/lib1/res")).addTransitiveResource(source("java/libraries/shared/res")).addTransitiveResourceDependency("//java/apps/example/lib1:lib1").addTransitiveResourceDependency("//java/libraries/shared:shared").build(), AndroidResourceModule.builder(TargetKey.forPlainTarget(Label.create("//java/apps/example/lib1:lib1"))).addResourceAndTransitiveResource(source("java/apps/example/lib1/res")).addTransitiveResource(source("java/libraries/shared/res")).addTransitiveResourceDependency("//java/libraries/shared:shared").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 30 with TargetMapBuilder

use of com.google.idea.blaze.base.ideinfo.TargetMapBuilder in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method testResourceImportOutsideSourceFilterIsAddedToResourceLibrary.

@Test
public void testResourceImportOutsideSourceFilterIsAddedToResourceLibrary() {
    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().setManifestFile(source("java/example/AndroidManifest.xml")).addResource(source("java/example/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example")).addDependency("//java/example2:resources").build()).addTarget(TargetIdeInfo.builder().setLabel("//java/example2:resources").setBuildFile(source("java/example2/BUILD")).setKind("android_library").setAndroidInfo(AndroidIdeInfo.builder().setManifestFile(source("java/example2/AndroidManifest.xml")).addResource(source("java/example2/res")).setGenerateResourceClass(true).setResourceJavaPackage("com.google.android.example2")).build());
    BlazeAndroidImportResult result = importWorkspace(workspaceRoot, targetMapBuilder, projectView);
    errorCollector.assertNoIssues();
    BlazeResourceLibrary library = result.resourceLibrary;
    assertThat(library).isNotNull();
    assertThat(library.sources).containsExactly(ArtifactLocation.builder().setRelativePath("java/example2/res").setIsSource(true).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) BlazeResourceLibrary(com.google.idea.blaze.android.sync.model.BlazeResourceLibrary) 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