Search in sources :

Example 11 with BlazeAndroidImportResult

use of com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult 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)

Example 12 with BlazeAndroidImportResult

use of com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult 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 13 with BlazeAndroidImportResult

use of com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporter method importWorkspace.

public BlazeAndroidImportResult importWorkspace() {
    List<TargetIdeInfo> sourceTargets = targetMap.targets().stream().filter(target -> target.kind.languageClass == LanguageClass.ANDROID).filter(target -> target.androidIdeInfo != null).filter(importFilter::isSourceTarget).filter(target -> !importFilter.excludeTarget(target)).collect(Collectors.toList());
    TransitiveResourceMap transitiveResourceMap = new TransitiveResourceMap(targetMap);
    WorkspaceBuilder workspaceBuilder = new WorkspaceBuilder();
    for (TargetIdeInfo target : sourceTargets) {
        addSourceTarget(workspaceBuilder, transitiveResourceMap, target);
    }
    GeneratedResourceWarnings.submit(project, context, projectViewSet, artifactLocationDecoder, workspaceBuilder.generatedResourceLocations, whitelistedGenResourcePaths);
    ImmutableList<AndroidResourceModule> androidResourceModules = buildAndroidResourceModules(workspaceBuilder);
    BlazeResourceLibrary resourceLibrary = createResourceLibrary(androidResourceModules);
    ImmutableList<AarLibrary> aarLibraries = createAarLibraries(sourceFilter.getLibraryTargets());
    return new BlazeAndroidImportResult(androidResourceModules, resourceLibrary, aarLibraries, getJavacJar(targetMap.targets()));
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) GeneratedAndroidResourcesSection(com.google.idea.blaze.android.projectview.GeneratedAndroidResourcesSection) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) Multimap(com.google.common.collect.Multimap) BlazeResourceLibrary(com.google.idea.blaze.android.sync.model.BlazeResourceLibrary) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) Kind(com.google.idea.blaze.base.model.primitives.Kind) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) TransitiveResourceMap(com.google.idea.blaze.android.sync.importer.aggregators.TransitiveResourceMap) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) PerformanceWarning(com.google.idea.blaze.base.scope.output.PerformanceWarning) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableSet(com.google.common.collect.ImmutableSet) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) Collection(java.util.Collection) Set(java.util.Set) ComparisonChain(com.google.common.collect.ComparisonChain) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) BlazeAndroidImportResult(com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) GeneratedResourceWarnings(com.google.idea.blaze.android.sync.importer.problems.GeneratedResourceWarnings) List(java.util.List) Stream(java.util.stream.Stream) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) Collections(java.util.Collections) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) BlazeAndroidImportResult(com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult) TransitiveResourceMap(com.google.idea.blaze.android.sync.importer.aggregators.TransitiveResourceMap) BlazeResourceLibrary(com.google.idea.blaze.android.sync.model.BlazeResourceLibrary)

Aggregations

BlazeAndroidImportResult (com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult)13 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)11 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)11 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)11 Test (org.junit.Test)11 AndroidAarIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo)5 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)5 BlazeAndroidLibrarySource (com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource)3 BlazeResourceLibrary (com.google.idea.blaze.android.sync.model.BlazeResourceLibrary)2 JavaSourceFilter (com.google.idea.blaze.java.sync.importer.JavaSourceFilter)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 ComparisonChain (com.google.common.collect.ComparisonChain)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 GeneratedAndroidResourcesSection (com.google.idea.blaze.android.projectview.GeneratedAndroidResourcesSection)1 GenfilesPath (com.google.idea.blaze.android.projectview.GenfilesPath)1 BlazeAndroidWorkspaceImporter (com.google.idea.blaze.android.sync.importer.BlazeAndroidWorkspaceImporter)1