Search in sources :

Example 1 with JavaIdeInfo

use of com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo in project bazel by bazelbuild.

the class AndroidStudioInfoAspect method makeJavaIdeInfo.

private JavaIdeInfo makeJavaIdeInfo(ConfiguredTarget base, RuleContext ruleContext, JavaRuleOutputJarsProvider outputJarsProvider, AndroidStudioInfoFilesProvider.Builder providerBuilder) {
    NestedSetBuilder<Artifact> ideResolveArtifacts = providerBuilder.ideResolveFilesBuilder();
    JavaIdeInfo.Builder builder = JavaIdeInfo.newBuilder();
    List<Artifact> javaSources = Lists.newArrayList();
    List<Artifact> generatedJavaSources = Lists.newArrayList();
    List<Artifact> srcjars = Lists.newArrayList();
    divideJavaSources(ruleContext, javaSources, generatedJavaSources, srcjars);
    if (!javaSources.isEmpty()) {
        Artifact packageManifest = derivedArtifact(base, ruleContext, ".manifest");
        providerBuilder.ideInfoFilesBuilder().add(packageManifest);
        ruleContext.registerAction(makePackageManifestAction(ruleContext, packageManifest, javaSources));
        builder.setPackageManifest(makeArtifactLocation(packageManifest));
    }
    // This can be removed once android_resources is deleted
    if (ruleContext.attributes().has("resources", BuildType.LABEL) && ruleContext.getRule().getRuleClass().startsWith("android_")) {
        srcjars = ImmutableList.of();
    }
    if (!javaSources.isEmpty() && (!generatedJavaSources.isEmpty() || !srcjars.isEmpty())) {
        Artifact filteredGenJar = derivedArtifact(base, ruleContext, "-filtered-gen.jar");
        Artifact filteredGenSrcJar = derivedArtifact(base, ruleContext, "-filtered-gen-src.jar");
        List<Artifact> jars = Lists.newArrayList();
        List<Artifact> sourceJars = Lists.newArrayList();
        for (OutputJar outputJar : outputJarsProvider.getOutputJars()) {
            Artifact jar = outputJar.getIJar();
            if (jar == null) {
                jar = outputJar.getClassJar();
            }
            if (jar != null) {
                jars.add(jar);
            }
            if (outputJar.getSrcJar() != null) {
                sourceJars.add(outputJar.getSrcJar());
            }
        }
        ruleContext.registerAction(makeFilteredJarAction(ruleContext, jars, sourceJars, generatedJavaSources, srcjars, filteredGenJar, filteredGenSrcJar));
        ideResolveArtifacts.add(filteredGenJar);
        ideResolveArtifacts.add(filteredGenSrcJar);
        builder.setFilteredGenJar(makeLibraryArtifact(ideResolveArtifacts, filteredGenJar, null, filteredGenSrcJar));
    }
    collectJarsFromOutputJarsProvider(builder, ideResolveArtifacts, outputJarsProvider);
    Artifact jdeps = outputJarsProvider.getJdeps();
    if (jdeps != null) {
        builder.setJdeps(makeArtifactLocation(jdeps));
    }
    JavaGenJarsProvider genJarsProvider = base.getProvider(JavaGenJarsProvider.class);
    if (genJarsProvider != null) {
        collectGenJars(builder, ideResolveArtifacts, genJarsProvider);
    }
    Collection<Artifact> sourceFiles = getSources(ruleContext);
    for (Artifact sourceFile : sourceFiles) {
        builder.addSources(makeArtifactLocation(sourceFile));
    }
    return builder.build();
}
Also used : OutputJar(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar) JavaGenJarsProvider(com.google.devtools.build.lib.rules.java.JavaGenJarsProvider) JavaIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo) Artifact(com.google.devtools.build.lib.actions.Artifact) LibraryArtifact(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact)

Example 2 with JavaIdeInfo

use of com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo in project bazel by bazelbuild.

the class AndroidStudioInfoAspectTest method testExternalTarget.

@Test
public void testExternalTarget() throws Exception {
    scratch.file("/r/BUILD", "java_import(", "    name = 'junit',", "    jars = ['junit.jar'],", ")");
    scratch.file("/r/junit.jar");
    // AnalysisMock adds required toolchains, etc. to WORKSPACE, so retain the previous contents.
    String oldContents = scratch.readFile("WORKSPACE");
    scratch.overwriteFile("WORKSPACE", oldContents + "\nlocal_repository(name='r', path='/r')");
    invalidatePackages();
    scratch.file("com/google/example/BUILD", "java_library(", "    name = 'junit',", "    exports = ['@r//:junit'],", ")");
    Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:junit");
    assertThat(getTargetIdeInfoAndVerifyLabel("//com/google/example:junit", targetIdeInfos).getBuildFileArtifactLocation().getIsExternal()).isFalse();
    TargetIdeInfo targetInfo = getTargetIdeInfoAndVerifyLabel("@r//:junit", targetIdeInfos);
    assertThat(targetInfo.getBuildFileArtifactLocation().getIsExternal()).isTrue();
    assertThat(targetInfo.getBuildFileArtifactLocation().getRelativePath()).startsWith("external");
    JavaIdeInfo javaInfo = targetInfo.getJavaIdeInfo();
    assertThat(javaInfo.getJarsList()).hasSize(1);
    ArtifactLocation jar = javaInfo.getJars(0).getJar();
    assertThat(jar.getIsSource()).isTrue();
    assertThat(jar.getIsExternal()).isTrue();
    assertThat(jar.getRelativePath()).isEqualTo("external/r/junit.jar");
}
Also used : TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) ArtifactLocation(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.ArtifactLocation) ByteString(com.google.protobuf.ByteString) JavaIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo) Test(org.junit.Test)

Example 3 with JavaIdeInfo

use of com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo in project bazel by bazelbuild.

the class AndroidStudioInfoAspectTest method testJavaImport.

@Test
public void testJavaImport() throws Exception {
    scratch.file("com/google/example/BUILD", "java_import(", "   name = 'imp',", "   jars = ['a.jar', 'b.jar'],", "   srcjar = 'impsrc.jar',", ")", "java_library(", "   name = 'lib',", "   srcs = ['Lib.java'],", "   deps = [':imp'],", ")");
    Map<String, TargetIdeInfo> targetIdeInfos = buildIdeInfo("//com/google/example:lib");
    final TargetIdeInfo libInfo = getTargetIdeInfoAndVerifyLabel("//com/google/example:lib", targetIdeInfos);
    TargetIdeInfo impInfo = getTargetIdeInfoAndVerifyLabel("//com/google/example:imp", targetIdeInfos);
    assertThat(impInfo.getKindString()).isEqualTo("java_import");
    assertThat(libInfo.getDependenciesList()).contains("//com/google/example:imp");
    JavaIdeInfo javaIdeInfo = impInfo.getJavaIdeInfo();
    assertThat(javaIdeInfo).isNotNull();
    assertThat(transform(javaIdeInfo.getJarsList(), LIBRARY_ARTIFACT_TO_STRING)).containsExactly(jarString("com/google/example", "a.jar", "_ijar/imp/com/google/example/a-ijar.jar", "impsrc.jar"), jarString("com/google/example", "b.jar", "_ijar/imp/com/google/example/b-ijar.jar", "impsrc.jar")).inOrder();
    assertThat(getIdeResolveFiles()).containsExactly("com/google/example/_ijar/imp/com/google/example/a-ijar.jar", "com/google/example/_ijar/imp/com/google/example/b-ijar.jar", "com/google/example/liblib.jar", "com/google/example/liblib-hjar.jar", "com/google/example/liblib-src.jar");
}
Also used : TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) ByteString(com.google.protobuf.ByteString) JavaIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo) Test(org.junit.Test)

Example 4 with JavaIdeInfo

use of com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo in project bazel by bazelbuild.

the class AndroidStudioInfoAspect method createIdeBuildArtifact.

private AndroidStudioInfoFilesProvider createIdeBuildArtifact(ConfiguredTarget base, RuleContext ruleContext, DependenciesResult dependenciesResult, AndroidStudioInfoFilesProvider.Builder providerBuilder) {
    Artifact ideInfoFile = derivedArtifact(base, ruleContext, ASWB_BUILD_SUFFIX);
    Artifact ideInfoTextFile = derivedArtifact(base, ruleContext, ASWB_BUILD_TEXT_SUFFIX);
    providerBuilder.ideInfoFilesBuilder().add(ideInfoFile);
    providerBuilder.ideInfoTextFilesBuilder().add(ideInfoTextFile);
    NestedSetBuilder<Artifact> ideResolveArtifacts = providerBuilder.ideResolveFilesBuilder();
    TargetIdeInfo.Builder outputBuilder = TargetIdeInfo.newBuilder();
    outputBuilder.setLabel(base.getLabel().toString());
    outputBuilder.setBuildFileArtifactLocation(makeArtifactLocation(ruleContext.getRule().getPackage(), ruleContext.getLabel()));
    outputBuilder.setKindString(ruleContext.getRule().getRuleClass());
    // Java rules
    JavaRuleOutputJarsProvider outputJarsProvider = JavaProvider.getProvider(JavaRuleOutputJarsProvider.class, base);
    if (outputJarsProvider != null && !androidStudioInfoSemantics.suppressJavaRuleInfo(base)) {
        JavaIdeInfo javaIdeInfo = makeJavaIdeInfo(base, ruleContext, outputJarsProvider, providerBuilder);
        outputBuilder.setJavaIdeInfo(javaIdeInfo);
    }
    // C rules
    if (isCppRule(base)) {
        CppCompilationContext cppCompilationContext = base.getProvider(CppCompilationContext.class);
        if (cppCompilationContext != null) {
            CIdeInfo cIdeInfo = makeCIdeInfo(base, ruleContext, cppCompilationContext, ideResolveArtifacts);
            outputBuilder.setCIdeInfo(cIdeInfo);
        }
    }
    // CCToolchain rule
    CcToolchainProvider ccToolchainProvider = base.getProvider(CcToolchainProvider.class);
    if (ccToolchainProvider != null) {
        CppConfiguration cppConfiguration = ccToolchainProvider.getCppConfiguration();
        if (cppConfiguration != null) {
            CToolchainIdeInfo cToolchainIdeInfo = makeCToolchainIdeInfo(ruleContext, cppConfiguration);
            if (cToolchainIdeInfo != null) {
                outputBuilder.setCToolchainIdeInfo(cToolchainIdeInfo);
            }
        }
    }
    // Android rules
    AndroidIdeInfoProvider androidIdeInfoProvider = base.getProvider(AndroidIdeInfoProvider.class);
    if (androidIdeInfoProvider != null) {
        outputBuilder.setAndroidIdeInfo(makeAndroidIdeInfo(androidIdeInfoProvider, dependenciesResult, ideResolveArtifacts));
    }
    // Python rules
    if (isPythonRule(base)) {
        outputBuilder.setPyIdeInfo(makePyIdeInfo(base, ruleContext, ideResolveArtifacts));
    }
    // Test rules
    if (TargetUtils.isTestRule(base.getTarget())) {
        TestInfo.Builder builder = TestInfo.newBuilder();
        String attr = NonconfigurableAttributeMapper.of(base.getTarget().getAssociatedRule()).get("size", Type.STRING);
        if (attr != null) {
            builder.setSize(attr);
        }
        outputBuilder.setTestInfo(builder);
    }
    // Java toolchain rule
    JavaToolchainProvider javaToolchainProvider = base.getProvider(JavaToolchainProvider.class);
    if (javaToolchainProvider != null) {
        outputBuilder.setJavaToolchainIdeInfo(JavaToolchainIdeInfo.newBuilder().setSourceVersion(javaToolchainProvider.getSourceVersion()).setTargetVersion(javaToolchainProvider.getTargetVersion()));
    }
    androidStudioInfoSemantics.augmentRuleInfo(outputBuilder, base, ruleContext, ideResolveArtifacts);
    AndroidStudioInfoFilesProvider provider = providerBuilder.build();
    outputBuilder.addAllDependencies(transform(dependenciesResult.deps, LABEL_TO_STRING));
    outputBuilder.addAllRuntimeDeps(transform(dependenciesResult.runtimeDeps, LABEL_TO_STRING));
    outputBuilder.addAllTags(base.getTarget().getAssociatedRule().getRuleTags());
    final TargetIdeInfo targetIdeInfo = outputBuilder.build();
    ruleContext.registerAction(makeProtoWriteAction(ruleContext.getActionOwner(), targetIdeInfo, ideInfoFile));
    ruleContext.registerAction(makeProtoTextWriteAction(ruleContext.getActionOwner(), targetIdeInfo, ideInfoTextFile));
    return provider;
}
Also used : JavaRuleOutputJarsProvider(com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider) CcToolchainProvider(com.google.devtools.build.lib.rules.cpp.CcToolchainProvider) Artifact(com.google.devtools.build.lib.actions.Artifact) LibraryArtifact(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact) TargetIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo) CppCompilationContext(com.google.devtools.build.lib.rules.cpp.CppCompilationContext) CToolchainIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo) CppConfiguration(com.google.devtools.build.lib.rules.cpp.CppConfiguration) JavaToolchainProvider(com.google.devtools.build.lib.rules.java.JavaToolchainProvider) AndroidIdeInfoProvider(com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider) CIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo) TestInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TestInfo) JavaIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo)

Aggregations

JavaIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo)4 TargetIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo)3 Artifact (com.google.devtools.build.lib.actions.Artifact)2 LibraryArtifact (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact)2 ByteString (com.google.protobuf.ByteString)2 Test (org.junit.Test)2 AndroidIdeInfoProvider (com.google.devtools.build.lib.rules.android.AndroidIdeInfoProvider)1 CcToolchainProvider (com.google.devtools.build.lib.rules.cpp.CcToolchainProvider)1 CppCompilationContext (com.google.devtools.build.lib.rules.cpp.CppCompilationContext)1 CppConfiguration (com.google.devtools.build.lib.rules.cpp.CppConfiguration)1 JavaGenJarsProvider (com.google.devtools.build.lib.rules.java.JavaGenJarsProvider)1 JavaRuleOutputJarsProvider (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider)1 OutputJar (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar)1 JavaToolchainProvider (com.google.devtools.build.lib.rules.java.JavaToolchainProvider)1 ArtifactLocation (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.ArtifactLocation)1 CIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CIdeInfo)1 CToolchainIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.CToolchainIdeInfo)1 TestInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TestInfo)1