Search in sources :

Example 1 with BlazeResourceLibrary

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

use of com.google.idea.blaze.android.sync.model.BlazeResourceLibrary 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)2 BlazeResourceLibrary (com.google.idea.blaze.android.sync.model.BlazeResourceLibrary)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 TransitiveResourceMap (com.google.idea.blaze.android.sync.importer.aggregators.TransitiveResourceMap)1 GeneratedResourceWarnings (com.google.idea.blaze.android.sync.importer.problems.GeneratedResourceWarnings)1 AarLibrary (com.google.idea.blaze.android.sync.model.AarLibrary)1 AndroidResourceModule (com.google.idea.blaze.android.sync.model.AndroidResourceModule)1 AndroidIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)1 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)1 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)1 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)1 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)1 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)1