Search in sources :

Example 6 with LibraryArtifact

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

the class BlazeAndroidLiteSyncPlugin method getSdkLibrary.

@Nullable
private static BlazeLibrary getSdkLibrary(BlazeProjectData blazeProjectData) {
    List<AndroidSdkIdeInfo> sdkTargets = androidSdkTargets(blazeProjectData.targetMap);
    if (sdkTargets.isEmpty()) {
        return null;
    }
    // for now, just add the first one found
    // TODO: warn if there's more than one
    ArtifactLocation sdk = sdkTargets.stream().map(info -> info.androidJar).filter(Objects::nonNull).findFirst().orElse(null);
    return sdk != null ? new BlazeJarLibrary(new LibraryArtifact(null, sdk, ImmutableList.of())) : null;
}
Also used : BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ImmutableSet(com.google.common.collect.ImmutableSet) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) LibrarySource(com.google.idea.blaze.base.sync.libraries.LibrarySource) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) AndroidSdkIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidSdkIdeInfo) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Nullable(javax.annotation.Nullable) Objects(java.util.Objects) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) AndroidSdkIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidSdkIdeInfo) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) Nullable(javax.annotation.Nullable)

Example 7 with LibraryArtifact

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

the class IdeInfoFromProtobuf method makeLibraryArtifact.

@Nullable
private static LibraryArtifact makeLibraryArtifact(IntellijIdeInfo.LibraryArtifact libraryArtifact) {
    ArtifactLocation classJar = libraryArtifact.hasJar() ? makeArtifactLocation(libraryArtifact.getJar()) : null;
    ArtifactLocation iJar = libraryArtifact.hasInterfaceJar() ? makeArtifactLocation(libraryArtifact.getInterfaceJar()) : null;
    ImmutableList.Builder<ArtifactLocation> sourceJars = ImmutableList.builder();
    if (!libraryArtifact.getSourceJarsList().isEmpty()) {
        sourceJars.addAll(libraryArtifact.getSourceJarsList().stream().map(IdeInfoFromProtobuf::makeArtifactLocation).collect(Collectors.toList()));
    } else if (libraryArtifact.hasSourceJar()) {
        sourceJars.add(makeArtifactLocation(libraryArtifact.getSourceJar()));
    }
    if (iJar == null && classJar == null) {
        // drop invalid ArtifactLocations
        return null;
    }
    return new LibraryArtifact(iJar, classJar, sourceJars.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) Nullable(javax.annotation.Nullable)

Example 8 with LibraryArtifact

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

the class BlazeJavaSyncPlugin method warnAboutDeployJars.

/**
 * Looks at your jars for anything that seems to be a deploy jar and warns about it. This often
 * turns out to be a duplicate copy of all your application's code, so you don't want it in your
 * project.
 */
private static void warnAboutDeployJars(BlazeContext context, BlazeJavaSyncData syncData) {
    for (BlazeLibrary library : syncData.importResult.libraries.values()) {
        if (!(library instanceof BlazeJarLibrary)) {
            continue;
        }
        BlazeJarLibrary jarLibrary = (BlazeJarLibrary) library;
        LibraryArtifact libraryArtifact = jarLibrary.libraryArtifact;
        ArtifactLocation artifactLocation = libraryArtifact.jarForIntellijLibrary();
        if (artifactLocation.getRelativePath().endsWith("deploy.jar") || artifactLocation.getRelativePath().endsWith("deploy-ijar.jar") || artifactLocation.getRelativePath().endsWith("deploy-hjar.jar")) {
            context.output(new PerformanceWarning("Performance warning: You have added a deploy jar as a library. " + "This can lead to poor indexing performance, and the debugger may " + "become confused and step into the deploy jar instead of your code. " + "Consider redoing the rule to not use deploy jars, exclude the target " + "from your .blazeproject, or exclude the library.\n" + "Library path: " + artifactLocation.getRelativePath()));
        }
    }
}
Also used : BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) PerformanceWarning(com.google.idea.blaze.base.scope.output.PerformanceWarning) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact)

Example 9 with LibraryArtifact

use of com.google.idea.blaze.base.ideinfo.LibraryArtifact 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 10 with LibraryArtifact

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

the class BlazeAndroidWorkspaceImporter method createAarLibraries.

private ImmutableList<AarLibrary> createAarLibraries(Iterable<TargetIdeInfo> libraryTargets) {
    ImmutableList.Builder<AarLibrary> builder = ImmutableList.builder();
    for (TargetIdeInfo target : libraryTargets) {
        // don't have the equivalent of jdeps data.
        if (target.androidAarIdeInfo == null || target.javaIdeInfo == null || target.javaIdeInfo.jars.isEmpty()) {
            continue;
        }
        // aar_import should only have one jar (a merged jar from the AAR's jars).
        LibraryArtifact firstJar = target.javaIdeInfo.jars.iterator().next();
        builder.add(new AarLibrary(firstJar, target.androidAarIdeInfo.aar));
    }
    return builder.build();
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) ImmutableList(com.google.common.collect.ImmutableList) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact)

Aggregations

LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)14 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)9 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)7 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)6 ImmutableList (com.google.common.collect.ImmutableList)5 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)4 AndroidIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)3 JavaIdeInfo (com.google.idea.blaze.base.ideinfo.JavaIdeInfo)3 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)3 BlazeLibrary (com.google.idea.blaze.base.model.BlazeLibrary)3 Nullable (javax.annotation.Nullable)3 AndroidResourceModuleRegistry (com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry)2 ProtoLibraryLegacyInfo (com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo)2 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)2 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)2 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)2 BlazeJavaSyncAugmenter (com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2