Example usage for com.google.common.collect ImmutableList.Builder addAll

List of usage examples for com.google.common.collect ImmutableList.Builder addAll

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList.Builder addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:com.google.devtools.build.lib.rules.objc.J2ObjcAspect.java

private static J2ObjcMappingFileProvider createJ2ObjcTranspilationAction(RuleContext ruleContext,
        Iterable<Artifact> sources, Iterable<Artifact> sourceJars,
        J2ObjcMappingFileProvider depJ2ObjcMappingFileProvider, JavaCompilationArgsProvider compArgsProvider,
        J2ObjcSource j2ObjcSource) {//  w ww . j  av  a2s  .c  om
    CustomCommandLine.Builder argBuilder = CustomCommandLine.builder();
    PathFragment javaExecutable = ruleContext.getFragment(Jvm.class, HOST).getJavaExecutable();
    argBuilder.add("--java").add(javaExecutable.getPathString());

    Artifact j2ObjcDeployJar = ruleContext.getPrerequisiteArtifact("$j2objc", Mode.HOST);
    argBuilder.addExecPath("--j2objc", j2ObjcDeployJar);

    argBuilder.add("--main_class").add("com.google.devtools.j2objc.J2ObjC");
    argBuilder.add("--objc_file_path").addPath(j2ObjcSource.getObjcFilePath());

    Artifact outputDependencyMappingFile = j2ObjcOutputDependencyMappingFile(ruleContext);
    argBuilder.addExecPath("--output_dependency_mapping_file", outputDependencyMappingFile);

    ImmutableList.Builder<Artifact> sourceJarOutputFiles = ImmutableList.builder();
    if (!Iterables.isEmpty(sourceJars)) {
        sourceJarOutputFiles.addAll(sourceJarOutputs(ruleContext));
        argBuilder.addJoinExecPaths("--src_jars", ",", sourceJars);
        argBuilder.add(sourceJarFlags(ruleContext));
    }

    Iterable<String> translationFlags = ruleContext.getFragment(J2ObjcConfiguration.class)
            .getTranslationFlags();
    argBuilder.add(translationFlags);

    NestedSet<Artifact> depsHeaderMappingFiles = depJ2ObjcMappingFileProvider.getHeaderMappingFiles();
    if (!depsHeaderMappingFiles.isEmpty()) {
        argBuilder.addJoinExecPaths("--header-mapping", ",", depsHeaderMappingFiles);
    }

    Artifact outputHeaderMappingFile = j2ObjcOutputHeaderMappingFile(ruleContext);
    argBuilder.addExecPath("--output-header-mapping", outputHeaderMappingFile);

    NestedSet<Artifact> depsClassMappingFiles = depJ2ObjcMappingFileProvider.getClassMappingFiles();
    if (!depsClassMappingFiles.isEmpty()) {
        argBuilder.addJoinExecPaths("--mapping", ",", depsClassMappingFiles);
    }

    Artifact archiveSourceMappingFile = j2ObjcOutputArchiveSourceMappingFile(ruleContext);
    argBuilder.addExecPath("--output_archive_source_mapping_file", archiveSourceMappingFile);

    Artifact compiledLibrary = ObjcRuleClasses.j2objcIntermediateArtifacts(ruleContext).archive();
    argBuilder.addExecPath("--compiled_archive_file_path", compiledLibrary);

    Artifact bootclasspathJar = ruleContext.getPrerequisiteArtifact("$jre_emul_jar", Mode.HOST);
    argBuilder.add("-Xbootclasspath:" + bootclasspathJar.getExecPathString());

    argBuilder.add("-d").addPath(j2ObjcSource.getObjcFilePath());

    // In J2ObjC, the jars you pass as dependencies must be precisely the same as the
    // jars used to transpile those dependencies--we cannot use ijars here.
    NestedSet<Artifact> compileTimeJars = compArgsProvider.getRecursiveJavaCompilationArgs().getRuntimeJars();
    if (!compileTimeJars.isEmpty()) {
        argBuilder.addJoinExecPaths("-classpath", ":", compileTimeJars);
    }

    argBuilder.addExecPaths(sources);

    Artifact paramFile = j2ObjcOutputParamFile(ruleContext);
    ruleContext.registerAction(new ParameterFileWriteAction(ruleContext.getActionOwner(), paramFile,
            argBuilder.build(), ParameterFile.ParameterFileType.UNQUOTED, ISO_8859_1));

    SpawnAction.Builder builder = new SpawnAction.Builder().setMnemonic("TranspilingJ2objc")
            .setExecutable(ruleContext.getPrerequisiteArtifact("$j2objc_wrapper", Mode.HOST))
            .addInput(ruleContext.getPrerequisiteArtifact("$j2objc_wrapper", Mode.HOST))
            .addInput(j2ObjcDeployJar).addInput(bootclasspathJar).addInputs(sources).addInputs(sourceJars)
            .addTransitiveInputs(compileTimeJars)
            .addTransitiveInputs(JavaHelper.getHostJavabaseInputs(ruleContext))
            .addTransitiveInputs(depsHeaderMappingFiles).addTransitiveInputs(depsClassMappingFiles)
            .addInput(paramFile)
            .setCommandLine(CustomCommandLine.builder().addPaths("@%s", paramFile.getExecPath()).build())
            .addOutputs(j2ObjcSource.getObjcSrcs()).addOutputs(j2ObjcSource.getObjcHdrs())
            .addOutput(outputHeaderMappingFile).addOutput(outputDependencyMappingFile)
            .addOutput(archiveSourceMappingFile);

    ruleContext.registerAction(builder.build(ruleContext));

    return new J2ObjcMappingFileProvider(
            NestedSetBuilder.<Artifact>stableOrder().add(outputHeaderMappingFile).build(),
            NestedSetBuilder.<Artifact>stableOrder().build(),
            NestedSetBuilder.<Artifact>stableOrder().add(outputDependencyMappingFile).build(),
            NestedSetBuilder.<Artifact>stableOrder().add(archiveSourceMappingFile).build());
}

From source file:org.prebake.html.TextBlock.java

static TextChunk make(List<TextChunk> chunks) {
    if (chunks.isEmpty()) {
        return new SimpleTextChunk("");
    }//from   w ww . ja va2s.c o  m
    if (chunks.size() == 1 && chunks.get(0).breaks()) {
        return chunks.get(0);
    }
    ImmutableList.Builder<TextChunk> parts = ImmutableList.builder();
    List<TextChunk> inlineParts = Lists.newArrayList();
    for (TextChunk c : chunks) {
        if (!c.breaks()) {
            inlineParts.add(c);
        } else {
            switch (inlineParts.size()) {
            case 0:
                break;
            case 1:
                parts.add(inlineParts.get(0));
                break;
            default:
                parts.add(InlineText.make(inlineParts));
                break;
            }
            inlineParts.clear();
            if (c instanceof TextBlock) {
                parts.addAll(((TextBlock) c).parts);
            } else {
                parts.add(c);
            }
        }
    }
    switch (inlineParts.size()) {
    case 0:
        break;
    case 1:
        parts.add(inlineParts.get(0));
        break;
    default:
        parts.add(InlineText.make(inlineParts));
        break;
    }
    return new TextBlock(parts.build());
}

From source file:com.google.devtools.build.lib.rules.android.AndroidSkylarkData.java

private static ImmutableList<Artifact> filesFromConfiguredTargets(SkylarkList<ConfiguredTarget> targets) {
    ImmutableList.Builder<Artifact> builder = ImmutableList.builder();
    for (FileProvider provider : getFileProviders(targets)) {
        builder.addAll(provider.getFilesToBuild());
    }//from  ww w  .j  a v a  2  s .c  o  m

    return builder.build();
}

From source file:edu.mit.streamjit.test.Benchmarker.java

/**
 * Runs all the datasets for all the benchmarks in the given provider on the
 * given compiler.  This entry point is to make the individual provider
 * classes runnable (call this from main()) for convenience when debugging
 * an individual benchmark.//w  w w  .  ja  va2 s.  co  m
 * @param provider the provider to run benchmarks of
 * @param compiler the compiler to use
 */
public static List<Result> runBenchmarks(BenchmarkProvider provider, StreamCompiler compiler) {
    ImmutableList.Builder<Result> results = ImmutableList.builder();
    for (Benchmark benchmark : provider)
        results.addAll(runBenchmark(benchmark, compiler));
    return results.build();
}

From source file:com.google.devtools.build.lib.analysis.DependencyResolver.java

private static Iterable<Aspect> extractAspectCandidates(Iterable<Aspect> aspects, Attribute attribute,
        Rule originalRule) {//from   w ww  .  j a va2 s .c  o m
    ImmutableList.Builder<Aspect> aspectCandidates = ImmutableList.builder();
    aspectCandidates.addAll(attribute.getAspects(originalRule));
    for (Aspect aspect : aspects) {
        if (aspect.getDefinition().propagateAlong(attribute)) {
            aspectCandidates.add(aspect);
        }
    }
    return aspectCandidates.build();
}

From source file:com.opengamma.strata.calc.marketdata.scenario.ScenarioDefinition.java

/**
 * Returns a list created by repeating the items in the input list multiple times, with each item repeated
 * in groups.//from  www .java 2 s. co  m
 * <p>
 * For example, given a list [1, 2, 3, 4], total count 12, group size 3 the result is
 * [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4].
 * <p>
 * This is used when creating scenarios from every possible combination of a set of perturbations.
 *
 * @param inputs  an input list whose elements are repeated in the output
 * @param totalCount  the number of elements in the output list
 * @param groupSize  the number of times each element should be repeated in each group
 * @param <T>  the type of the elements
 * @return a list created by repeating the elements of the input list
 */
static <T> List<T> repeatItems(List<T> inputs, int totalCount, int groupSize) {
    ImmutableList.Builder<T> builder = ImmutableList.builder();

    for (int i = 0; i < (totalCount / groupSize / inputs.size()); i++) {
        for (T input : inputs) {
            builder.addAll(Collections.nCopies(groupSize, input));
        }
    }
    return builder.build();
}

From source file:com.facebook.buck.features.rust.RustCompileUtils.java

public static BinaryWrapperRule createBinaryBuildRule(BuildTarget buildTarget,
        ProjectFilesystem projectFilesystem, BuildRuleParams params, ActionGraphBuilder graphBuilder,
        RustBuckConfig rustBuckConfig, RustPlatform rustPlatform, Optional<String> crateName,
        Optional<String> edition, ImmutableSortedSet<String> features, Iterator<String> rustcFlags,
        Iterator<String> linkerFlags, LinkableDepType linkStyle, boolean rpath,
        ImmutableSortedSet<SourcePath> srcs, Optional<SourcePath> crateRoot, ImmutableSet<String> defaultRoots,
        CrateType crateType, Iterable<BuildRule> deps) {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder);
    SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder);

    ImmutableList.Builder<String> rustcArgs = ImmutableList.builder();

    RustCompileUtils.addFeatures(buildTarget, features, rustcArgs);

    RustCompileUtils.addTargetTripleForFlavor(rustPlatform.getFlavor(), rustcArgs);
    rustcArgs.addAll(rustcFlags);

    ImmutableList.Builder<String> linkerArgs = ImmutableList.builder();
    linkerArgs.addAll(linkerFlags);/*from w w  w  .jav a  2s .  c o m*/

    String crate = crateName.orElse(ruleToCrateName(buildTarget.getShortName()));

    CxxPlatform cxxPlatform = rustPlatform.getCxxPlatform();

    Pair<SourcePath, ImmutableSortedSet<SourcePath>> rootModuleAndSources = getRootModuleAndSources(buildTarget,
            graphBuilder, pathResolver, ruleFinder, cxxPlatform, crate, crateRoot, defaultRoots, srcs);

    // The target to use for the link rule.
    BuildTarget binaryTarget = buildTarget.withAppendedFlavors(crateType.getFlavor());

    if (crateType.isCheck() || !rustBuckConfig.getUnflavoredBinaries()) {
        binaryTarget = binaryTarget.withAppendedFlavors(cxxPlatform.getFlavor());
    }

    boolean forceRlib = rustBuckConfig.getForceRlib();
    boolean preferStatic = rustBuckConfig.getPreferStaticLibs();

    CommandTool.Builder executableBuilder = new CommandTool.Builder();

    // Special handling for dynamically linked binaries.
    if (linkStyle == Linker.LinkableDepType.SHARED) {

        // Create a symlink tree with for all native shared (NativeLinkable) libraries
        // needed by this binary.
        SymlinkTree sharedLibraries = (SymlinkTree) graphBuilder.computeIfAbsent(
                createSharedLibrarySymlinkTreeTarget(buildTarget, cxxPlatform.getFlavor()),
                target -> CxxDescriptionEnhancer.createSharedLibrarySymlinkTree(target, projectFilesystem,
                        graphBuilder, ruleFinder, cxxPlatform, deps,
                        r -> r instanceof RustLinkable
                                ? Optional.of(((RustLinkable) r).getRustLinakbleDeps(rustPlatform))
                                : Optional.empty()));

        // Embed a origin-relative library path into the binary so it can find the shared libraries.
        // The shared libraries root is absolute. Also need an absolute path to the linkOutput
        Path absBinaryDir = buildTarget.getCellPath()
                .resolve(RustCompileRule.getOutputDir(binaryTarget, projectFilesystem));

        linkerArgs.addAll(Linkers.iXlinker("-rpath",
                String.format("%s/%s", cxxPlatform.getLd().resolve(graphBuilder).origin(),
                        absBinaryDir.relativize(sharedLibraries.getRoot()).toString())));

        // Add all the shared libraries and the symlink tree as inputs to the tool that represents
        // this binary, so that users can attach the proper deps.
        executableBuilder.addNonHashableInput(sharedLibraries.getRootSourcePath());
        executableBuilder.addInputs(sharedLibraries.getLinks().values());

        // Also add Rust shared libraries as runtime deps. We don't need these in the symlink tree
        // because rustc will include their dirs in rpath by default. We won't have any if we're
        // forcing the use of rlibs.
        Map<String, SourcePath> rustSharedLibraries = getTransitiveRustSharedLibraries(rustPlatform, deps,
                forceRlib);
        executableBuilder.addInputs(rustSharedLibraries.values());
    }

    RustCompileRule buildRule = (RustCompileRule) graphBuilder.computeIfAbsent(binaryTarget,
            target -> createBuild(target, crate, projectFilesystem, params, graphBuilder, ruleFinder,
                    rustPlatform, rustBuckConfig, rustcArgs.build(), linkerArgs.build(),
                    /* linkerInputs */ ImmutableList.of(), crateType, edition, linkStyle, rpath,
                    rootModuleAndSources.getSecond(), rootModuleAndSources.getFirst(), forceRlib, preferStatic,
                    deps, rustBuckConfig.getIncremental(rustPlatform.getFlavor().getName())));

    // Add the binary as the first argument.
    executableBuilder.addArg(SourcePathArg.of(buildRule.getSourcePathToOutput()));

    CommandTool executable = executableBuilder.build();

    return new BinaryWrapperRule(buildTarget, projectFilesystem, params.copyAppendingExtraDeps(buildRule)) {

        @Override
        public Tool getExecutableCommand() {
            return executable;
        }

        @Override
        public SourcePath getSourcePathToOutput() {
            return ForwardingBuildTargetSourcePath.of(getBuildTarget(), buildRule.getSourcePathToOutput());
        }
    };
}

From source file:com.torodb.torod.db.postgresql.query.processors.InProcessor.java

@Nullable
private static ProcessedQueryCriteria getNumericQuery(InQueryCriteria criteria,
        Multimap<BasicType, Value<?>> byTypeValues) {
    ImmutableList.Builder<Value<?>> newInBuilder = ImmutableList.builder();

    for (Value<?> value : byTypeValues.values()) {
        newInBuilder.add(value);/*w  w w .  j  ava  2  s .  com*/
    }

    ImmutableList<Value<?>> newIn = newInBuilder.build();

    if (newIn.isEmpty()) {
        return null;
    }

    DisjunctionBuilder structureBuilder = new DisjunctionBuilder();

    structureBuilder.add(new TypeIsQueryCriteria(criteria.getAttributeReference(), BasicType.DOUBLE));
    structureBuilder.add(new TypeIsQueryCriteria(criteria.getAttributeReference(), BasicType.INTEGER));
    structureBuilder.add(new TypeIsQueryCriteria(criteria.getAttributeReference(), BasicType.LONG));

    newInBuilder.addAll(byTypeValues.get(BasicType.DOUBLE));
    newInBuilder.addAll(byTypeValues.get(BasicType.INTEGER));
    newInBuilder.addAll(byTypeValues.get(BasicType.LONG));

    return new ProcessedQueryCriteria(structureBuilder.build(),
            new InQueryCriteria(criteria.getAttributeReference(), newIn));
}

From source file:com.facebook.presto.metadata.SignatureBinder.java

private static List<TypeSignature> expandVarargFormalTypeSignature(List<TypeSignature> formalTypeSignatures,
        int actualArity) {
    int variableArityArgumentsCount = actualArity - formalTypeSignatures.size() + 1;
    if (variableArityArgumentsCount == 0) {
        return formalTypeSignatures.subList(0, formalTypeSignatures.size() - 1);
    }//w w w  .  ja v a 2  s. c  o  m
    if (variableArityArgumentsCount == 1) {
        return formalTypeSignatures;
    }
    checkArgument(variableArityArgumentsCount > 1 && !formalTypeSignatures.isEmpty());

    ImmutableList.Builder<TypeSignature> builder = ImmutableList.builder();
    builder.addAll(formalTypeSignatures);
    TypeSignature lastTypeSignature = formalTypeSignatures.get(formalTypeSignatures.size() - 1);
    for (int i = 1; i < variableArityArgumentsCount; i++) {
        builder.add(lastTypeSignature);
    }
    return builder.build();
}

From source file:eu.arthepsy.sonar.plugins.rebrand.RebrandConfiguration.java

public static List<PropertyDefinition> getPropertyDefinitions() {
    ImmutableList.Builder<PropertyDefinition> properties = ImmutableList.builder();
    final String generalCategory = "#General";
    properties.add(//  w  w  w  .  java  2s  .  co m
            PropertyDefinition.builder(ORIGINAL_LOGO_VISIBLE).category(CATEGORY).subCategory(generalCategory)
                    .index(0).name("SonarQube logo").description("Visibility of SonarQube logo")
                    .type(PropertyType.BOOLEAN).defaultValue("true").build());
    properties.add(
            PropertyDefinition.builder(ORIGINAL_FOOTER_VISIBLE).category(CATEGORY).subCategory(generalCategory)
                    .index(0).name("SonarQube footer").description("Visibility of SonarQube footer")
                    .type(PropertyType.BOOLEAN).defaultValue("true").build());
    properties.addAll(getImagePropertyDefinitions(SIDEBAR_PREFIX, "Sidebar"));
    properties.addAll(getImagePropertyDefinitions(CONTENT_PREFIX, "Content"));
    return properties.build();
}