List of usage examples for com.google.common.collect ImmutableList.Builder add
boolean add(E e);
From source file:com.google.devtools.build.lib.rules.android.NativeLibs.java
public static NativeLibs fromLinkedNativeDeps(RuleContext ruleContext, String nativeDepsFileName, Multimap<String, TransitiveInfoCollection> depsByArchitecture, Map<String, CcToolchainProvider> toolchainMap, Map<String, BuildConfiguration> configurationMap) throws InterruptedException { Map<String, Iterable<Artifact>> result = new LinkedHashMap<>(); String nativeDepsLibraryBasename = null; for (Map.Entry<String, Collection<TransitiveInfoCollection>> entry : depsByArchitecture.asMap() .entrySet()) {/*from ww w. j av a2 s . c o m*/ CcLinkParams linkParams = AndroidCommon .getCcLinkParamsStore(entry.getValue(), ImmutableList.of("-Wl,-soname=lib" + ruleContext.getLabel().getName())) .get(/* linkingStatically */ true, /* linkShared */ true); Artifact nativeDepsLibrary = NativeDepsHelper.linkAndroidNativeDepsIfPresent(ruleContext, linkParams, configurationMap.get(entry.getKey()), toolchainMap.get(entry.getKey())); ImmutableList.Builder<Artifact> librariesBuilder = ImmutableList.builder(); if (nativeDepsLibrary != null) { librariesBuilder.add(nativeDepsLibrary); nativeDepsLibraryBasename = nativeDepsLibrary.getExecPath().getBaseName(); } librariesBuilder .addAll(filterUniqueSharedLibraries(ruleContext, nativeDepsLibrary, linkParams.getLibraries())); ImmutableList<Artifact> libraries = librariesBuilder.build(); if (!libraries.isEmpty()) { result.put(entry.getKey(), libraries); } } if (result.isEmpty()) { return NativeLibs.EMPTY; } else if (nativeDepsLibraryBasename == null) { return new NativeLibs(ImmutableMap.copyOf(result), null); } else { // The native deps name file must be the only file in its directory because ApkBuilder does // not have an option to add a particular file to the .apk, only one to add every file in a // particular directory. Artifact nativeDepsName = ruleContext.getUniqueDirectoryArtifact("nativedeps_filename", nativeDepsFileName, ruleContext.getBinOrGenfilesDirectory()); ruleContext.registerAction( FileWriteAction.create(ruleContext, nativeDepsName, nativeDepsLibraryBasename, false)); return new NativeLibs(ImmutableMap.copyOf(result), nativeDepsName); } }
From source file:com.spectralogic.ds3client.helpers.strategy.StrategyUtils.java
/** * Filters out chunks that have already been completed. We will get the same chunk name back from the server, but it * will not have any objects in it, so we remove that from the list of objects that are returned. * @param chunks The list to be filtered * @return The filtered list/*from w w w . ja va 2 s.c o m*/ */ public static ImmutableList<Objects> filterChunks(final Iterable<Objects> chunks) { final ImmutableList.Builder<Objects> builder = ImmutableList.builder(); for (final Objects chunk : chunks) { final Objects filteredChunk = filterChunk(chunk); if (filteredChunk.getObjects().size() > 0) { builder.add(filteredChunk); } } return builder.build(); }
From source file:com.spotify.dns.XBillDnsSrvResolver.java
private static List<LookupResult> toLookupResults(Record[] queryResult) { ImmutableList.Builder<LookupResult> builder = ImmutableList.builder(); if (queryResult != null) { for (Record record : queryResult) { if (record instanceof SRVRecord) { SRVRecord srvRecord = (SRVRecord) record; builder.add(LookupResult.create(srvRecord.getTarget().toString(), srvRecord.getPort(), srvRecord.getPriority(), srvRecord.getWeight(), srvRecord.getTTL())); }/*from w w w .ja v a2s. c om*/ } } return builder.build(); }
From source file:com.facebook.buck.apple.RuleUtils.java
/** * Extract the source and header paths and flags from the input list * and populate the output collections.//from w w w .j a v a 2 s .com * * @param outputSources The ordered tree of sources, headers, and groups (as * they should appear in a generated Xcode project) will be added to * this builder. * @param outputPerFileFlags per file flags will be added to this builder * @param items input list of sources */ public static void extractSourcePaths(ImmutableList.Builder<GroupedSource> outputSources, ImmutableMap.Builder<SourcePath, String> outputPerFileFlags, ImmutableList<AppleSource> items) { for (AppleSource item : items) { switch (item.getType()) { case SOURCE_PATH: outputSources.add(GroupedSource.ofSourcePath(item.getSourcePath())); break; case SOURCE_PATH_WITH_FLAGS: Pair<SourcePath, String> pair = item.getSourcePathWithFlags(); outputSources.add(GroupedSource.ofSourcePath(pair.getFirst())); outputPerFileFlags.put(pair.getFirst(), pair.getSecond()); break; case SOURCE_GROUP: Pair<String, ImmutableList<AppleSource>> sourceGroup = item.getSourceGroup(); String sourceGroupName = sourceGroup.getFirst(); ImmutableList<AppleSource> sourceGroupItems = sourceGroup.getSecond(); ImmutableList.Builder<GroupedSource> nestedSourceGroups = ImmutableList.builder(); extractSourcePaths(nestedSourceGroups, outputPerFileFlags, sourceGroupItems); outputSources.add(GroupedSource.ofSourceGroup(sourceGroupName, nestedSourceGroups.build())); break; default: throw new RuntimeException("Unhandled AppleSource item type: " + item.getType()); } } }
From source file:org.apache.beam.runners.core.construction.TransformInputs.java
/** * Gets all inputs of the {@link AppliedPTransform} that are not returned by {@link * PTransform#getAdditionalInputs()}.// w ww .j ava 2 s .c o m */ public static Collection<PValue> nonAdditionalInputs(AppliedPTransform<?, ?, ?> application) { ImmutableList.Builder<PValue> mainInputs = ImmutableList.builder(); PTransform<?, ?> transform = application.getTransform(); for (Map.Entry<TupleTag<?>, PValue> input : application.getInputs().entrySet()) { if (!transform.getAdditionalInputs().containsKey(input.getKey())) { mainInputs.add(input.getValue()); } } checkArgument(!mainInputs.build().isEmpty() || application.getInputs().isEmpty(), "Expected at least one main input if any inputs exist"); return mainInputs.build(); }
From source file:com.google.devtools.build.lib.sandbox.RealSandboxfsProcess.java
/** * Mounts a new sandboxfs instance.//from w w w . ja v a 2s . c o m * * <p>The root of the file system instance is left unmapped which means that it remains as * read-only throughout the lifetime of this instance. Writable subdirectories can later be * mapped via {@link #map(List)}. * * @param binary path to the sandboxfs binary. This is a {@link PathFragment} and not a * {@link Path} because we want to support "bare" (non-absolute) names for the location of * the sandboxfs binary; such names are automatically looked for in the {@code PATH}. * @param mountPoint directory on which to mount the sandboxfs instance * @param logFile path to the file that will receive all sandboxfs logging output * @return a new handle that represents the running process * @throws IOException if there is a problem starting the process */ static SandboxfsProcess mount(PathFragment binary, Path mountPoint, Path logFile) throws IOException { log.info("Mounting sandboxfs (" + binary + ") onto " + mountPoint); // TODO(jmmv): Before starting a sandboxfs serving instance, we must query the current version // of sandboxfs and check if we support its communication protocol. ImmutableList.Builder<String> argvBuilder = ImmutableList.builder(); argvBuilder.add(binary.getPathString()); // On macOS, we need to allow users other than self to access the sandboxfs instance. This is // necessary because macOS's amfid, which runs as root, has to have access to the binaries // within the sandbox in order to validate signatures. See: // http://julio.meroh.net/2017/10/fighting-execs-sandboxfs-macos.html argvBuilder.add(OS.getCurrent() == OS.DARWIN ? "--allow=other" : "--allow=self"); // TODO(jmmv): Pass flags to enable sandboxfs' debugging support (--listen_address and --debug) // when requested by the user via --sandbox_debug. Tricky because we have to figure out how to // deal with port numbers (which sandboxfs can autoassign, but doesn't currently promise a way // to tell us back what it picked). argvBuilder.add(mountPoint.getPathString()); SubprocessBuilder processBuilder = new SubprocessBuilder(); processBuilder.setArgv(argvBuilder.build()); processBuilder.setStderr(logFile.getPathFile()); processBuilder.setEnv(ImmutableMap.of( // sandboxfs may need to locate fusermount depending on the FUSE implementation so pass the // PATH to the subprocess (which we assume is sufficient). "PATH", System.getenv("PATH"))); Subprocess process = processBuilder.start(); RealSandboxfsProcess sandboxfs = new RealSandboxfsProcess(mountPoint, process); // TODO(jmmv): We should have a better mechanism to wait for sandboxfs to start successfully but // sandboxfs currently provides no interface to do so. Just try to push an empty configuration // and see if it works. try { sandboxfs.reconfigure("[]\n\n"); } catch (IOException e) { destroyProcess(process); throw new IOException("sandboxfs failed to start", e); } return sandboxfs; }
From source file:com.spectralogic.ds3autogen.java.generators.requestmodels.GetObjectRequestGenerator.java
/** * Creates the constructor for the get object request that uses OutputStream *///from ww w. j a va 2 s.com protected static RequestConstructor createOutputStreamConstructor( final ImmutableList<Arguments> constructorArgs, final ImmutableList<Arguments> optionalArgs, final ImmutableList<QueryParam> queryParams, final String requestName, final Ds3DocSpec docSpec) { final ImmutableList.Builder<Arguments> constructorArgBuilder = ImmutableList.builder(); constructorArgBuilder.addAll(constructorArgs); constructorArgBuilder.addAll(optionalArgs); constructorArgBuilder.add(new Arguments("OutputStream", "Stream")); final ImmutableList.Builder<QueryParam> queryParamsBuilder = ImmutableList.builder(); queryParamsBuilder.addAll(queryParams); queryParamsBuilder.addAll(argsToQueryParams(optionalArgs)); final ImmutableList.Builder<Arguments> assignmentsBuilder = ImmutableList.builder(); assignmentsBuilder.addAll(constructorArgs); assignmentsBuilder.addAll(optionalArgs); final ImmutableList<Arguments> updatedConstructorArgs = constructorArgBuilder.build(); final ImmutableList<String> argNames = updatedConstructorArgs.stream().map(Arguments::getName) .collect(GuavaCollectors.immutableList()); final ImmutableList<String> additionalLines = ImmutableList .of("this.channel = Channels.newChannel(stream);"); return new RequestConstructor(false, additionalLines, updatedConstructorArgs, assignmentsBuilder.build(), queryParamsBuilder.build(), toConstructorDocs(requestName, argNames, docSpec, 1)); }
From source file:org.codehaus.httpcache4j.HeaderUtils.java
public static List<LinkDirective> toLinkDirectives(Header header) { Validate.isTrue(LINK_HEADER.equals(header.getName()), "This must be a \"Link\" header"); ImmutableList.Builder<LinkDirective> links = ImmutableList.builder(); for (Directive directive : header.getDirectives()) { if (directive instanceof LinkDirective) { links.add((LinkDirective) directive); } else {/*from ww w . ja v a2s .c om*/ links.add(new LinkDirective(directive)); } } return links.build(); }
From source file:com.google.devtools.build.lib.collect.CollectionUtils.java
/** * Returns an immutable list of all non-null parameters in the order in which * they are specified./*from w ww .j a v a 2 s . c om*/ */ @SuppressWarnings("unchecked") public static <T> ImmutableList<T> asListWithoutNulls(T... elements) { ImmutableList.Builder<T> builder = ImmutableList.builder(); for (T element : elements) { if (element != null) { builder.add(element); } } return builder.build(); }
From source file:com.noodlewiz.xjavab.ext.xfixes.internal.ReplyUnpacker.java
public static GetCursorImageAndNameReply unpackGetCursorImageAndName(final ByteBuffer __xjb_buf) { __xjb_buf.position(4);// ww w . java 2 s. c o m final long length = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); __xjb_buf.position(1); com.noodlewiz.xjavab.core.internal.Unpacker.unpackPad(__xjb_buf, 1); __xjb_buf.position(8); final short x = com.noodlewiz.xjavab.core.internal.Unpacker.unpackShort(__xjb_buf); final short y = com.noodlewiz.xjavab.core.internal.Unpacker.unpackShort(__xjb_buf); final int width = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf); final int height = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf); final int xhot = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf); final int yhot = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf); final long cursorSerial = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); final long cursorAtom = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf); final int nbytes = com.noodlewiz.xjavab.core.internal.Unpacker.unpackUShort(__xjb_buf); com.noodlewiz.xjavab.core.internal.Unpacker.unpackPad(__xjb_buf, 2); final String name = com.noodlewiz.xjavab.core.internal.Unpacker.unpackString(__xjb_buf, nbytes); final com.google.common.collect.ImmutableList.Builder<Long> __xjb_cursorImageBuilder = new com.google.common.collect.ImmutableList.Builder<Long>(); for (int __xjb_i = 0; (__xjb_i < (width * height)); __xjb_i++) { __xjb_cursorImageBuilder.add(com.noodlewiz.xjavab.core.internal.Unpacker.unpackUInt(__xjb_buf)); } final List<Long> cursorImage = __xjb_cursorImageBuilder.build(); return new GetCursorImageAndNameReply(x, y, width, height, xhot, yhot, cursorSerial, cursorAtom, nbytes, name, cursorImage); }