Search in sources :

Example 1 with JavaGenJarsProvider

use of com.google.devtools.build.lib.rules.java.JavaGenJarsProvider 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 JavaGenJarsProvider

use of com.google.devtools.build.lib.rules.java.JavaGenJarsProvider in project bazel by bazelbuild.

the class J2ObjcAspect method java.

private ConfiguredAspect java(ConfiguredTarget base, RuleContext ruleContext, AspectParameters parameters) throws InterruptedException {
    JavaCompilationArgsProvider compilationArgsProvider = base.getProvider(JavaCompilationArgsProvider.class);
    JavaSourceInfoProvider sourceInfoProvider = base.getProvider(JavaSourceInfoProvider.class);
    JavaGenJarsProvider genJarProvider = base.getProvider(JavaGenJarsProvider.class);
    ImmutableSet.Builder<Artifact> javaSourceFilesBuilder = ImmutableSet.builder();
    ImmutableSet.Builder<Artifact> javaSourceJarsBuilder = ImmutableSet.builder();
    if (sourceInfoProvider != null) {
        javaSourceFilesBuilder.addAll(sourceInfoProvider.getSourceFiles());
        javaSourceJarsBuilder.addAll(sourceInfoProvider.getSourceJars()).addAll(sourceInfoProvider.getSourceJarsForJarFiles());
    }
    if (genJarProvider != null && genJarProvider.getGenSourceJar() != null) {
        javaSourceJarsBuilder.add(genJarProvider.getGenSourceJar());
    }
    ImmutableSet<Artifact> javaSourceFiles = javaSourceFilesBuilder.build();
    ImmutableSet<Artifact> javaSourceJars = javaSourceJarsBuilder.build();
    J2ObjcSource j2ObjcSource = javaJ2ObjcSource(ruleContext, javaSourceFiles, javaSourceJars);
    J2ObjcMappingFileProvider depJ2ObjcMappingFileProvider = depJ2ObjcMappingFileProvider(ruleContext);
    J2ObjcMappingFileProvider directJ2ObjcMappingFileProvider;
    if (Iterables.isEmpty(j2ObjcSource.getObjcSrcs())) {
        directJ2ObjcMappingFileProvider = new J2ObjcMappingFileProvider.Builder().build();
    } else {
        directJ2ObjcMappingFileProvider = createJ2ObjcTranspilationAction(ruleContext, javaSourceFiles, javaSourceJars, depJ2ObjcMappingFileProvider, compilationArgsProvider, j2ObjcSource);
    }
    return buildAspect(base, ruleContext, parameters, j2ObjcSource, directJ2ObjcMappingFileProvider, JAVA_DEPENDENT_ATTRIBUTES);
}
Also used : JavaCompilationArgsProvider(com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider) ImmutableSet(com.google.common.collect.ImmutableSet) JavaSourceInfoProvider(com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider) JavaGenJarsProvider(com.google.devtools.build.lib.rules.java.JavaGenJarsProvider) NestedSetBuilder(com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder) ProtoCompileActionBuilder(com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

Artifact (com.google.devtools.build.lib.actions.Artifact)2 JavaGenJarsProvider (com.google.devtools.build.lib.rules.java.JavaGenJarsProvider)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)1 JavaCompilationArgsProvider (com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider)1 OutputJar (com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar)1 JavaSourceInfoProvider (com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider)1 ProtoCompileActionBuilder (com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder)1 JavaIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.JavaIdeInfo)1 LibraryArtifact (com.google.devtools.intellij.ideinfo.IntellijIdeInfo.LibraryArtifact)1