Search in sources :

Example 1 with ProtoLibraryLegacyInfo

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

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

the class BlazeJavaWorkspaceImporter method addProtoLegacyLibrariesFromDirectDeps.

private void addProtoLegacyLibrariesFromDirectDeps(WorkspaceBuilder workspaceBuilder, TargetMap targetMap, Map<LibraryKey, BlazeJarLibrary> result) {
    List<TargetKey> version1Targets = Lists.newArrayList();
    List<TargetKey> immutableTargets = Lists.newArrayList();
    List<TargetKey> mutableTargets = Lists.newArrayList();
    for (TargetKey targetKey : workspaceBuilder.directDeps) {
        TargetIdeInfo target = targetMap.get(targetKey);
        if (target == null) {
            continue;
        }
        ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
        if (protoLibraryLegacyInfo == null) {
            continue;
        }
        switch(protoLibraryLegacyInfo.apiFlavor) {
            case VERSION_1:
                version1Targets.add(targetKey);
                break;
            case IMMUTABLE:
                immutableTargets.add(targetKey);
                break;
            case MUTABLE:
                mutableTargets.add(targetKey);
                break;
            case BOTH:
                mutableTargets.add(targetKey);
                immutableTargets.add(targetKey);
                break;
            default:
                // Can't happen
                break;
        }
    }
    addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.VERSION_1, version1Targets, result);
    addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.IMMUTABLE, immutableTargets, result);
    addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.MUTABLE, mutableTargets, result);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ProtoLibraryLegacyInfo(com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo)

Example 3 with ProtoLibraryLegacyInfo

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

the class BlazeJavaWorkspaceImporter method addProtoLegacyLibrariesFromDirectDepsForFlavor.

private void addProtoLegacyLibrariesFromDirectDepsForFlavor(TargetMap targetMap, ProtoLibraryLegacyInfo.ApiFlavor apiFlavor, List<TargetKey> targetKeys, Map<LibraryKey, BlazeJarLibrary> result) {
    for (TargetKey key : targetKeys) {
        TargetIdeInfo target = targetMap.get(key);
        if (target == null) {
            continue;
        }
        ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
        if (protoLibraryLegacyInfo == null) {
            continue;
        }
        final Collection<LibraryArtifact> libraries;
        switch(apiFlavor) {
            case VERSION_1:
                libraries = protoLibraryLegacyInfo.jarsV1;
                break;
            case MUTABLE:
                libraries = protoLibraryLegacyInfo.jarsMutable;
                break;
            case IMMUTABLE:
                libraries = protoLibraryLegacyInfo.jarsImmutable;
                break;
            default:
                // Can't happen
                libraries = null;
                break;
        }
        if (libraries != null) {
            for (LibraryArtifact libraryArtifact : libraries) {
                BlazeJarLibrary library = new BlazeJarLibrary(libraryArtifact);
                result.put(library.key, library);
            }
        }
    }
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) ProtoLibraryLegacyInfo(com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo)

Example 4 with ProtoLibraryLegacyInfo

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

the class IdeInfoFromProtobuf method makeTargetIdeInfo.

@Nullable
public static TargetIdeInfo makeTargetIdeInfo(IntellijIdeInfo.TargetIdeInfo message) {
    Kind kind = getKind(message);
    if (kind == null) {
        return null;
    }
    TargetKey key = getKey(message);
    ArtifactLocation buildFile = getBuildFile(message);
    final Collection<Dependency> dependencies;
    if (message.getDepsCount() > 0) {
        dependencies = message.getDepsList().stream().map(IdeInfoFromProtobuf::makeDependency).collect(toList());
    } else {
        dependencies = Lists.newArrayListWithCapacity(message.getDependenciesCount() + message.getRuntimeDepsCount());
        dependencies.addAll(makeDependencyListFromLabelList(message.getDependenciesList(), DependencyType.COMPILE_TIME));
        dependencies.addAll(makeDependencyListFromLabelList(message.getRuntimeDepsList(), DependencyType.RUNTIME));
    }
    Collection<String> tags = ImmutableList.copyOf(message.getTagsList());
    Collection<ArtifactLocation> sources = Lists.newArrayList();
    CIdeInfo cIdeInfo = null;
    if (message.hasCIdeInfo()) {
        cIdeInfo = makeCIdeInfo(message.getCIdeInfo());
        sources.addAll(cIdeInfo.sources);
        sources.addAll(cIdeInfo.headers);
        sources.addAll(cIdeInfo.textualHeaders);
    }
    CToolchainIdeInfo cToolchainIdeInfo = null;
    if (message.hasCToolchainIdeInfo()) {
        cToolchainIdeInfo = makeCToolchainIdeInfo(message.getCToolchainIdeInfo());
    }
    JavaIdeInfo javaIdeInfo = null;
    if (message.hasJavaIdeInfo()) {
        javaIdeInfo = makeJavaIdeInfo(message.getJavaIdeInfo());
        Collection<ArtifactLocation> javaSources = makeArtifactLocationList(message.getJavaIdeInfo().getSourcesList());
        sources.addAll(javaSources);
    }
    AndroidIdeInfo androidIdeInfo = null;
    if (message.hasAndroidIdeInfo()) {
        androidIdeInfo = makeAndroidIdeInfo(message.getAndroidIdeInfo());
    }
    AndroidSdkIdeInfo androidSdkIdeInfo = null;
    if (message.hasAndroidSdkIdeInfo()) {
        androidSdkIdeInfo = makeAndroidSdkIdeInfo(message.getAndroidSdkIdeInfo());
    }
    AndroidAarIdeInfo androidAarIdeInfo = null;
    if (message.hasAndroidAarIdeInfo()) {
        androidAarIdeInfo = makeAndroidAarIdeInfo(message.getAndroidAarIdeInfo());
    }
    PyIdeInfo pyIdeInfo = null;
    if (message.hasPyIdeInfo()) {
        pyIdeInfo = makePyIdeInfo(message.getPyIdeInfo());
        sources.addAll(pyIdeInfo.sources);
    }
    GoIdeInfo goIdeInfo = null;
    if (message.hasGoIdeInfo()) {
        goIdeInfo = makeGoIdeInfo(message.getGoIdeInfo());
        sources.addAll(goIdeInfo.sources);
    }
    JsIdeInfo jsIdeInfo = null;
    if (message.hasJsIdeInfo()) {
        jsIdeInfo = makeJsIdeInfo(message.getJsIdeInfo());
        sources.addAll(jsIdeInfo.sources);
    }
    TsIdeInfo tsIdeInfo = null;
    if (message.hasTsIdeInfo()) {
        tsIdeInfo = makeTsIdeInfo(message.getTsIdeInfo());
        sources.addAll(tsIdeInfo.sources);
    }
    DartIdeInfo dartIdeInfo = null;
    if (message.hasDartIdeInfo()) {
        dartIdeInfo = makeDartIdeInfo(message.getDartIdeInfo());
        sources.addAll(dartIdeInfo.sources);
    }
    TestIdeInfo testIdeInfo = null;
    if (message.hasTestInfo()) {
        testIdeInfo = makeTestIdeInfo(message.getTestInfo());
    }
    ProtoLibraryLegacyInfo protoLibraryLegacyInfo = null;
    if (message.hasProtoLibraryLegacyJavaIdeInfo()) {
        protoLibraryLegacyInfo = makeProtoLibraryLegacyInfo(message.getProtoLibraryLegacyJavaIdeInfo());
    }
    JavaToolchainIdeInfo javaToolchainIdeInfo = null;
    if (message.hasJavaToolchainIdeInfo()) {
        javaToolchainIdeInfo = makeJavaToolchainIdeInfo(message.getJavaToolchainIdeInfo());
    }
    return new TargetIdeInfo(key, kind, buildFile, dependencies, tags, sources, cIdeInfo, cToolchainIdeInfo, javaIdeInfo, androidIdeInfo, androidSdkIdeInfo, androidAarIdeInfo, pyIdeInfo, goIdeInfo, jsIdeInfo, tsIdeInfo, dartIdeInfo, testIdeInfo, protoLibraryLegacyInfo, javaToolchainIdeInfo);
}
Also used : TsIdeInfo(com.google.idea.blaze.base.ideinfo.TsIdeInfo) PyIdeInfo(com.google.idea.blaze.base.ideinfo.PyIdeInfo) JsIdeInfo(com.google.idea.blaze.base.ideinfo.JsIdeInfo) GoIdeInfo(com.google.idea.blaze.base.ideinfo.GoIdeInfo) Dependency(com.google.idea.blaze.base.ideinfo.Dependency) DartIdeInfo(com.google.idea.blaze.base.ideinfo.DartIdeInfo) TestIdeInfo(com.google.idea.blaze.base.ideinfo.TestIdeInfo) ProtoLibraryLegacyInfo(com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) JavaToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.JavaToolchainIdeInfo) CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) AndroidAarIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo) Kind(com.google.idea.blaze.base.model.primitives.Kind) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) CIdeInfo(com.google.idea.blaze.base.ideinfo.CIdeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) AndroidSdkIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidSdkIdeInfo) Nullable(javax.annotation.Nullable)

Aggregations

ProtoLibraryLegacyInfo (com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo)4 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)4 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)4 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)2 JavaIdeInfo (com.google.idea.blaze.base.ideinfo.JavaIdeInfo)2 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)2 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)2 AndroidAarIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo)1 AndroidIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)1 AndroidSdkIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidSdkIdeInfo)1 CIdeInfo (com.google.idea.blaze.base.ideinfo.CIdeInfo)1 CToolchainIdeInfo (com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo)1 DartIdeInfo (com.google.idea.blaze.base.ideinfo.DartIdeInfo)1 Dependency (com.google.idea.blaze.base.ideinfo.Dependency)1 GoIdeInfo (com.google.idea.blaze.base.ideinfo.GoIdeInfo)1 JavaToolchainIdeInfo (com.google.idea.blaze.base.ideinfo.JavaToolchainIdeInfo)1 JsIdeInfo (com.google.idea.blaze.base.ideinfo.JsIdeInfo)1 PyIdeInfo (com.google.idea.blaze.base.ideinfo.PyIdeInfo)1 TestIdeInfo (com.google.idea.blaze.base.ideinfo.TestIdeInfo)1 TsIdeInfo (com.google.idea.blaze.base.ideinfo.TsIdeInfo)1