Search in sources :

Example 1 with Dependency

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

the class FastBuildCompilerFactoryImpl method getJavacJar.

private File getJavacJar(TargetIdeInfo targetIdeInfo) throws FastBuildException {
    BlazeProjectData projectData = projectDataManager.getBlazeProjectData();
    checkState(projectData != null, "not a blaze project");
    List<JavaToolchainIdeInfo> javaToolchains = new ArrayList<>();
    for (Dependency dependency : targetIdeInfo.dependencies) {
        TargetIdeInfo depInfo = projectData.targetMap.get(dependency.targetKey);
        if (depInfo != null && depInfo.javaToolchainIdeInfo != null) {
            javaToolchains.add(depInfo.javaToolchainIdeInfo);
        }
    }
    if (javaToolchains.isEmpty()) {
        throw new FastBuildException("Couldn't find a Java toolchain for target " + targetIdeInfo.key.label);
    }
    if (javaToolchains.size() > 1) {
        throw new FastBuildException("Found multiple Java toolchains for target " + targetIdeInfo.key.label);
    }
    return projectData.artifactLocationDecoder.decode(javaToolchains.get(0).javacJar);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) JavaToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.JavaToolchainIdeInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArrayList(java.util.ArrayList) Dependency(com.google.idea.blaze.base.ideinfo.Dependency)

Example 2 with Dependency

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

the class BlazeJavaWorkspaceImporter method addTargetAsSource.

private void addTargetAsSource(WorkspaceBuilder workspaceBuilder, TargetIdeInfo target, Collection<ArtifactLocation> javaSources) {
    JavaIdeInfo javaIdeInfo = target.javaIdeInfo;
    if (javaIdeInfo == null) {
        return;
    }
    TargetKey targetKey = target.key;
    Collection<String> jars = jdepsMap.getDependenciesForTarget(targetKey);
    if (jars != null) {
        workspaceBuilder.jdeps.addAll(jars);
    }
    // Add all deps if this rule is in the current working set
    if (workingSet == null || workingSet.isTargetInWorkingSet(target)) {
        // Add self, so we pick up our own gen jars if in working set
        workspaceBuilder.directDeps.add(targetKey);
        for (Dependency dep : target.dependencies) {
            if (dep.dependencyType != DependencyType.COMPILE_TIME) {
                continue;
            }
            // forward deps from java proto_library aspect targets
            TargetIdeInfo depTarget = targetMap.get(dep.targetKey);
            if (depTarget != null && Kind.JAVA_PROTO_LIBRARY_KINDS.contains(depTarget.kind)) {
                workspaceBuilder.directDeps.addAll(depTarget.dependencies.stream().map(d -> d.targetKey).collect(Collectors.toList()));
            } else {
                workspaceBuilder.directDeps.add(dep.targetKey);
            }
        }
    }
    for (ArtifactLocation artifactLocation : javaSources) {
        if (artifactLocation.isSource()) {
            duplicateSourceDetector.add(targetKey, artifactLocation);
            workspaceBuilder.sourceArtifacts.add(new SourceArtifact(targetKey, artifactLocation));
            workspaceBuilder.addedSourceFiles.add(artifactLocation);
        }
    }
    ArtifactLocation manifest = javaIdeInfo.packageManifest;
    if (manifest != null) {
        workspaceBuilder.javaPackageManifests.put(targetKey, manifest);
    }
    for (LibraryArtifact libraryArtifact : javaIdeInfo.jars) {
        ArtifactLocation classJar = libraryArtifact.classJar;
        if (classJar != null) {
            workspaceBuilder.buildOutputJars.add(classJar);
        }
    }
    workspaceBuilder.generatedJarsFromSourceTargets.addAll(javaIdeInfo.generatedJars.stream().map(BlazeJarLibrary::new).collect(Collectors.toList()));
    if (javaIdeInfo.filteredGenJar != null) {
        workspaceBuilder.generatedJarsFromSourceTargets.add(new BlazeJarLibrary(javaIdeInfo.filteredGenJar));
    }
    for (BlazeJavaSyncAugmenter augmenter : augmenters) {
        augmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, workspaceBuilder.outputJarsFromSourceTargets.get(targetKey), workspaceBuilder.generatedJarsFromSourceTargets);
    }
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeJavaSyncAugmenter(com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Dependency(com.google.idea.blaze.base.ideinfo.Dependency) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact)

Example 3 with Dependency

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

the class BlazeAndroidTestRunConfigurationHandler method getInstrumentationBinary.

@Nullable
private Label getInstrumentationBinary(Label label) {
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(configuration.getProject()).getBlazeProjectData();
    if (projectData == null) {
        return null;
    }
    TargetMap targetMap = projectData.targetMap;
    TargetIdeInfo instrumentationTest = targetMap.get(TargetKey.forPlainTarget(label));
    for (Dependency dependency : instrumentationTest.dependencies) {
        TargetIdeInfo dependencyInfo = targetMap.get(dependency.targetKey);
        // Should exist via test_app attribute, and be unique.
        if (dependencyInfo != null && dependencyInfo.kind == Kind.ANDROID_BINARY) {
            return dependency.targetKey.label;
        }
    }
    return null;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Dependency(com.google.idea.blaze.base.ideinfo.Dependency) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Nullable(javax.annotation.Nullable)

Example 4 with Dependency

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

the class BlazeApkBuildStepNormalBuild method getTargetToBuild.

/**
 * In case we're dealing with an {@link Kind#ANDROID_INSTRUMENTATION_TEST}, build the underlying
 * {@link Kind#ANDROID_BINARY} instead.
 */
private Label getTargetToBuild() {
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        return label;
    }
    TargetMap targetMap = projectData.targetMap;
    TargetIdeInfo target = targetMap.get(TargetKey.forPlainTarget(label));
    if (target == null || target.kind != Kind.ANDROID_INSTRUMENTATION_TEST) {
        return label;
    }
    for (Dependency dependency : target.dependencies) {
        TargetIdeInfo dependencyInfo = targetMap.get(dependency.targetKey);
        // Should exist via test_app attribute, and be unique.
        if (dependencyInfo != null && dependencyInfo.kind == Kind.ANDROID_BINARY) {
            return dependency.targetKey.label;
        }
    }
    return label;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Dependency(com.google.idea.blaze.base.ideinfo.Dependency) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Example 5 with Dependency

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

Dependency (com.google.idea.blaze.base.ideinfo.Dependency)5 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)5 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)3 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)2 JavaIdeInfo (com.google.idea.blaze.base.ideinfo.JavaIdeInfo)2 JavaToolchainIdeInfo (com.google.idea.blaze.base.ideinfo.JavaToolchainIdeInfo)2 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)2 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)2 Nullable (javax.annotation.Nullable)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 GoIdeInfo (com.google.idea.blaze.base.ideinfo.GoIdeInfo)1 JsIdeInfo (com.google.idea.blaze.base.ideinfo.JsIdeInfo)1 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)1 ProtoLibraryLegacyInfo (com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo)1 PyIdeInfo (com.google.idea.blaze.base.ideinfo.PyIdeInfo)1