Search in sources :

Example 11 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.

the class JavaPrefetchFileSource method addFilesToPrefetch.

@Override
public void addFilesToPrefetch(Project project, ProjectViewSet projectViewSet, ImportRoots importRoots, BlazeProjectData blazeProjectData, Set<File> files) {
    BlazeJavaSyncData syncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
    if (syncData == null) {
        return;
    }
    // If we have a local jar cache we don't need to prefetch anything
    if (JarCache.getInstance(project).isEnabled()) {
        return;
    }
    Collection<BlazeLibrary> libraries = BlazeLibraryCollector.getLibraries(projectViewSet, blazeProjectData);
    ArtifactLocationDecoder artifactLocationDecoder = blazeProjectData.artifactLocationDecoder;
    for (BlazeLibrary library : libraries) {
        if (!(library instanceof BlazeJarLibrary)) {
            continue;
        }
        BlazeJarLibrary jarLibrary = (BlazeJarLibrary) library;
        files.add(artifactLocationDecoder.decode(jarLibrary.libraryArtifact.jarForIntellijLibrary()));
        files.addAll(artifactLocationDecoder.decodeAll(jarLibrary.libraryArtifact.sourceJars));
    }
}
Also used : BlazeJavaSyncData(com.google.idea.blaze.java.sync.model.BlazeJavaSyncData) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)

Example 12 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporter method buildLibraries.

private ImmutableMap<LibraryKey, BlazeJarLibrary> buildLibraries(WorkspaceBuilder workspaceBuilder, TargetMap targetMap, List<TargetIdeInfo> libraryTargets, List<TargetIdeInfo> protoLibraries) {
    // Build library maps
    Multimap<TargetKey, BlazeJarLibrary> targetKeyToLibrary = ArrayListMultimap.create();
    Map<String, BlazeJarLibrary> jdepsPathToLibrary = Maps.newHashMap();
    // Add any output jars from source rules
    for (TargetKey key : workspaceBuilder.outputJarsFromSourceTargets.keySet()) {
        Collection<BlazeJarLibrary> jars = workspaceBuilder.outputJarsFromSourceTargets.get(key);
        targetKeyToLibrary.putAll(key, jars);
        for (BlazeJarLibrary library : jars) {
            addLibraryToJdeps(jdepsPathToLibrary, library);
        }
    }
    for (TargetIdeInfo target : libraryTargets) {
        JavaIdeInfo javaIdeInfo = target.javaIdeInfo;
        if (javaIdeInfo == null) {
            continue;
        }
        List<LibraryArtifact> allJars = Lists.newArrayList();
        allJars.addAll(javaIdeInfo.jars);
        Collection<BlazeJarLibrary> libraries = allJars.stream().map(BlazeJarLibrary::new).collect(Collectors.toList());
        targetKeyToLibrary.putAll(target.key, libraries);
        for (BlazeJarLibrary library : libraries) {
            addLibraryToJdeps(jdepsPathToLibrary, library);
        }
    }
    // proto legacy jdeps support
    for (TargetIdeInfo target : protoLibraries) {
        ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
        if (protoLibraryLegacyInfo == null) {
            continue;
        }
        for (LibraryArtifact libraryArtifact : Iterables.concat(protoLibraryLegacyInfo.jarsV1, protoLibraryLegacyInfo.jarsMutable, protoLibraryLegacyInfo.jarsImmutable)) {
            addLibraryToJdeps(jdepsPathToLibrary, new BlazeJarLibrary(libraryArtifact));
        }
    }
    Map<LibraryKey, BlazeJarLibrary> result = Maps.newHashMap();
    // Collect jars from jdep references
    for (String jdepsPath : workspaceBuilder.jdeps) {
        if (sourceFilter.jdepsPathsForExcludedJars.contains(jdepsPath)) {
            continue;
        }
        BlazeJarLibrary library = jdepsPathToLibrary.get(jdepsPath);
        if (library == null) {
            // It's in the target's jdeps, but our aspect never attached to the target building it
            // Perhaps it's an implicit dependency, or not referenced in an attribute we propagate along
            // Or it could be that this is a multi-configuration project, and jdeps refers to a
            // configuration different from the one we picked for the TargetMap.
            // Make a best-effort attempt to add it to the project anyway.
            ExecutionPathFragmentAndRelativePath split = ExecutionPathFragmentAndRelativePath.split(jdepsPath);
            ArtifactLocation location = ArtifactLocation.builder().setIsSource(false).setRootExecutionPathFragment(split.rootExecutionPathFragment).setRelativePath(split.relativePath).build();
            library = new BlazeJarLibrary(new LibraryArtifact(location, null, ImmutableList.of()));
        }
        result.put(library.key, library);
    }
    // Collect jars referenced by direct deps from your working set
    for (TargetKey deps : workspaceBuilder.directDeps) {
        for (BlazeJarLibrary library : targetKeyToLibrary.get(deps)) {
            result.put(library.key, library);
        }
    }
    // Collect legacy proto libraries from direct deps
    addProtoLegacyLibrariesFromDirectDeps(workspaceBuilder, targetMap, result);
    // Collect generated jars from source rules
    for (BlazeJarLibrary library : workspaceBuilder.generatedJarsFromSourceTargets) {
        result.put(library.key, library);
    }
    return ImmutableMap.copyOf(result);
}
Also used : ProtoLibraryLegacyInfo(com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact)

Example 13 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporter method importWorkspace.

public BlazeJavaImportResult importWorkspace(BlazeContext context) {
    WorkspaceBuilder workspaceBuilder = new WorkspaceBuilder();
    for (TargetIdeInfo target : sourceFilter.sourceTargets) {
        addTargetAsSource(workspaceBuilder, target, sourceFilter.targetToJavaSources.get(target.key));
    }
    SourceDirectoryCalculator sourceDirectoryCalculator = new SourceDirectoryCalculator();
    ImmutableList<BlazeContentEntry> contentEntries = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, artifactLocationDecoder, importRoots, workspaceBuilder.sourceArtifacts, workspaceBuilder.javaPackageManifests);
    int totalContentEntryCount = 0;
    for (BlazeContentEntry contentEntry : contentEntries) {
        totalContentEntryCount += contentEntry.sources.size();
    }
    context.output(PrintOutput.log("Java content entry count: " + totalContentEntryCount));
    ImmutableMap<LibraryKey, BlazeJarLibrary> libraries = buildLibraries(workspaceBuilder, targetMap, sourceFilter.libraryTargets, sourceFilter.protoLibraries);
    duplicateSourceDetector.reportDuplicates(context);
    String sourceVersion = findSourceVersion(targetMap);
    return new BlazeJavaImportResult(contentEntries, libraries, ImmutableList.copyOf(workspaceBuilder.buildOutputJars.stream().sorted().collect(Collectors.toList())), ImmutableSet.copyOf(workspaceBuilder.addedSourceFiles), sourceVersion);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) SourceDirectoryCalculator(com.google.idea.blaze.java.sync.source.SourceDirectoryCalculator)

Example 14 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method testIdlClassJarIsAddedAsLibrary.

@Test
public void testIdlClassJarIsAddedAsLibrary() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("example")))).build();
    TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//example:lib").setBuildFile(source("example/BUILD")).setKind("android_binary").addSource(source("example/MainActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setResourceJavaPackage("example").setIdlJar(LibraryArtifact.builder().setInterfaceJar(gen("example/libidl.jar")).addSourceJar(gen("example/libidl.srcjar")).build()).setHasIdlSources(true)));
    TargetMap targetMap = targetMapBuilder.build();
    BlazeAndroidJavaSyncAugmenter syncAugmenter = new BlazeAndroidJavaSyncAugmenter();
    List<BlazeJarLibrary> jars = Lists.newArrayList();
    List<BlazeJarLibrary> genJars = Lists.newArrayList();
    ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(ProjectViewSet.builder().add(projectView).build()).build();
    ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
    for (TargetIdeInfo target : targetMap.targets()) {
        if (importRoots.importAsSource(target.key.label)) {
            syncAugmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, jars, genJars);
        }
    }
    assertThat(genJars.stream().map(library -> library.libraryArtifact.interfaceJar).map(artifactLocation -> new File(artifactLocation.relativePath).getName()).collect(Collectors.toList())).containsExactly("libidl.jar");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) GeneratedAndroidResourcesSection(com.google.idea.blaze.android.projectview.GeneratedAndroidResourcesSection) BlazeAndroidJavaSyncAugmenter(com.google.idea.blaze.android.sync.BlazeAndroidJavaSyncAugmenter) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) JavaWorkingSet(com.google.idea.blaze.java.sync.workingset.JavaWorkingSet) WorkingSet(com.google.idea.blaze.base.sync.workspace.WorkingSet) JavaLikeLanguage(com.google.idea.blaze.java.sync.source.JavaLikeLanguage) BlazeAndroidLibrarySource(com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableSet(com.google.common.collect.ImmutableSet) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) Predicate(java.util.function.Predicate) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) Collectors(java.util.stream.Collectors) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) BlazeAndroidImportResult(com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact) List(java.util.List) ErrorCollector(com.google.idea.blaze.base.scope.ErrorCollector) 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) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) JavaSourcePackageReader(com.google.idea.blaze.java.sync.source.JavaSourcePackageReader) PackageManifestReader(com.google.idea.blaze.java.sync.source.PackageManifestReader) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) RunWith(org.junit.runner.RunWith) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter) MockJdepsMap(com.google.idea.blaze.java.sync.jdeps.MockJdepsMap) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ExperimentService(com.google.idea.common.experiments.ExperimentService) BlazeResourceLibrary(com.google.idea.blaze.android.sync.model.BlazeResourceLibrary) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) 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) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) AndroidAarIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) BlazeJavaSyncAugmenter(com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter) File(java.io.File) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) Label(com.google.idea.blaze.base.model.primitives.Label) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) GenfilesPath(com.google.idea.blaze.android.projectview.GenfilesPath) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) BlazeAndroidJavaSyncAugmenter(com.google.idea.blaze.android.sync.BlazeAndroidJavaSyncAugmenter) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Example 15 with BlazeJarLibrary

use of com.google.idea.blaze.java.sync.model.BlazeJarLibrary in project intellij by bazelbuild.

the class BlazeAndroidLibrarySource method getLibraries.

@Override
public List<BlazeLibrary> getLibraries() {
    BlazeAndroidSyncData syncData = blazeProjectData.syncState.get(BlazeAndroidSyncData.class);
    if (syncData == null) {
        return ImmutableList.of();
    }
    ImmutableList.Builder<BlazeLibrary> libraries = ImmutableList.builder();
    if (syncData.importResult.resourceLibrary != null) {
        libraries.add(syncData.importResult.resourceLibrary);
    }
    if (syncData.importResult.javacJar != null) {
        libraries.add(new BlazeJarLibrary(new LibraryArtifact(null, syncData.importResult.javacJar, ImmutableList.of())));
    }
    libraries.addAll(syncData.importResult.aarLibraries);
    return libraries.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) BlazeAndroidSyncData(com.google.idea.blaze.android.sync.model.BlazeAndroidSyncData) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact)

Aggregations

BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)21 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)11 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)9 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)9 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)7 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)7 ImmutableList (com.google.common.collect.ImmutableList)6 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)6 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Nullable (javax.annotation.Nullable)6 JavaIdeInfo (com.google.idea.blaze.base.ideinfo.JavaIdeInfo)5 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)5 Kind (com.google.idea.blaze.base.model.primitives.Kind)5 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)5 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)5 Test (org.junit.Test)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)4 BlazeLibrary (com.google.idea.blaze.base.model.BlazeLibrary)4