List of usage examples for com.google.common.collect ImmutableList builder
public static <E> Builder<E> builder()
From source file:com.querydsl.core.types.AppendingFactoryExpression.java
protected AppendingFactoryExpression(Expression<T> base, Expression<?>... rest) { super(base.getType()); this.base = base; ImmutableList.Builder<Expression<?>> builder = ImmutableList.builder(); builder.add(base);/*from w ww. ja v a 2 s . co m*/ builder.add(rest); this.args = builder.build(); }
From source file:com.google.devtools.build.lib.sandbox.SandboxActionContextProvider.java
public static SandboxActionContextProvider create(CommandEnvironment env, BuildRequest buildRequest) throws IOException { boolean verboseFailures = buildRequest.getOptions(ExecutionOptions.class).verboseFailures; ImmutableList.Builder<ActionContext> contexts = ImmutableList.builder(); switch (OS.getCurrent()) { case LINUX://ww w .jav a 2 s .c om if (LinuxSandboxedStrategy.isSupported(env)) { boolean fullySupported = LinuxSandboxRunner.isSupported(env); if (!fullySupported && !buildRequest.getOptions(SandboxOptions.class).ignoreUnsupportedSandboxing) { env.getReporter().handle(Event.warn(SANDBOX_NOT_SUPPORTED_MESSAGE)); } contexts.add(new LinuxSandboxedStrategy(buildRequest, env.getDirectories(), verboseFailures, env.getRuntime().getProductName(), fullySupported)); } break; case DARWIN: if (DarwinSandboxRunner.isSupported()) { contexts.add(DarwinSandboxedStrategy.create(buildRequest, env.getClientEnv(), env.getDirectories(), verboseFailures, env.getRuntime().getProductName())); } else { if (!buildRequest.getOptions(SandboxOptions.class).ignoreUnsupportedSandboxing) { env.getReporter().handle(Event.warn(SANDBOX_NOT_SUPPORTED_MESSAGE)); } } break; default: // No sandboxing available. } return new SandboxActionContextProvider(contexts.build()); }
From source file:com.facebook.buck.testutil.UnixUtils.java
/** Returns a command builder for a unix platform */ @Override public ImmutableList.Builder<String> getCommandBuilder() { return ImmutableList.builder(); }
From source file:com.github.imasahiro.stringformatter.processor.FormatterMethod.java
private static List<ParameterSpec> buildParamTypes(List<TypeMirror> argumentTypes) { ImmutableList.Builder<ParameterSpec> builder = ImmutableList.builder(); for (int i = 0; i < argumentTypes.size(); i++) { builder.add(/* ww w . ja v a 2 s.com*/ ParameterSpec.builder(TypeName.get(argumentTypes.get(i)), "arg" + i, Modifier.FINAL).build()); } return builder.build(); }
From source file:com.facebook.buck.file.StackedDownloader.java
public static Downloader createFromConfig(BuckConfig config, Optional<Path> androidSdkRoot) { ImmutableList.Builder<Downloader> downloaders = ImmutableList.builder(); DownloadConfig downloadConfig = new DownloadConfig(config); Optional<Proxy> proxy = downloadConfig.getProxy(); HttpDownloader httpDownloader = new HttpDownloader(proxy); for (Map.Entry<String, String> kv : downloadConfig.getAllMavenRepos().entrySet()) { String repo = kv.getValue(); // Check the type. if (repo.startsWith("http:") || repo.startsWith("https://")) { String repoName = kv.getKey(); Optional<PasswordAuthentication> credentials = downloadConfig.getRepoCredentials(repoName); downloaders.add(new RemoteMavenDownloader(httpDownloader, repo, credentials)); } else if (repo.startsWith("file:")) { try { URL url = new URL(repo); Preconditions.checkNotNull(url.getPath()); downloaders.add(new OnDiskMavenDownloader( config.resolvePathThatMayBeOutsideTheProjectFilesystem(Paths.get(url.getPath())))); } catch (FileNotFoundException e) { throw new HumanReadableException(e, "Error occurred when attempting to use %s " + "as a local Maven repository as configured in .buckconfig. See " + "https://buckbuild.com/concept/buckconfig.html#maven_repositories for how to " + "configure this setting", repo);/* www . j a v a2 s . co m*/ } catch (MalformedURLException e) { throw new HumanReadableException("Unable to determine path from %s", repo); } } else { try { downloaders.add(new OnDiskMavenDownloader( config.resolvePathThatMayBeOutsideTheProjectFilesystem(Paths.get(repo)))); } catch (FileNotFoundException e) { throw new HumanReadableException(e, "Error occurred when attempting to use %s " + "as a local Maven repository as configured in .buckconfig. See " + "https://buckbuild.com/concept/buckconfig.html#maven_repositories for how to " + "configure this setting", repo); } } } if (androidSdkRoot.isPresent()) { Path androidMavenRepo = androidSdkRoot.get().resolve("extras/android/m2repository"); try { downloaders.add(new OnDiskMavenDownloader(androidMavenRepo)); } catch (FileNotFoundException e) { LOG.warn("Android Maven repo %s doesn't exist", androidMavenRepo.toString()); } Path googleMavenRepo = androidSdkRoot.get().resolve("extras/google/m2repository"); try { downloaders.add(new OnDiskMavenDownloader(googleMavenRepo)); } catch (FileNotFoundException e) { LOG.warn("Google Maven repo '%s' doesn't exist", googleMavenRepo.toString()); } } // Add a default downloader // TODO(shs96c): Remove the maven_repo check Optional<String> defaultMavenRepo = downloadConfig.getMavenRepo(); if (defaultMavenRepo.isPresent()) { LOG.warn("Please configure maven repos by adding them to a 'maven_repositories' " + "section in your buckconfig"); } downloaders.add(downloadConfig.getMaxNumberOfRetries() .map(retries -> (Downloader) RetryingDownloader.from(httpDownloader, retries)) .orElse(httpDownloader)); return new StackedDownloader(downloaders.build()); }
From source file:com.google.devtools.moe.client.svn.SvnUtil.java
String runSvnCommandWithWorkingDirectory(String workingDirectory, String command, String... args) throws CommandRunner.CommandException { ImmutableList.Builder<String> withAuthArgs = ImmutableList.builder(); withAuthArgs.add("--no-auth-cache").add(command).addAll(Arrays.asList(args)); return cmd.runCommand("svn", withAuthArgs.build(), workingDirectory); }
From source file:com.google.devtools.build.android.UnvalidatedAndroidDirectories.java
protected static ImmutableList<Path> splitPaths(String pathsString, FileSystem fileSystem) { if (pathsString.length() == 0) { return ImmutableList.of(); }//from w w w. ja v a2s. co m ImmutableList.Builder<Path> paths = new ImmutableList.Builder<>(); for (String pathString : pathsString.split("#")) { paths.add(exists(fileSystem.getPath(pathString))); } return paths.build(); }
From source file:com.google.api.codegen.discovery.Document.java
/** * Returns a document constructed from root. * * @param root the root node to parse.//w w w. j av a 2 s . co m * @return a document. */ public static Document from(DiscoveryNode root) { AuthType authType; DiscoveryNode scopesNode = root.getObject("auth").getObject("oauth2").getObject("scopes"); ImmutableList.Builder<String> authScopes = new Builder<>(); if (scopesNode.isEmpty()) { authType = AuthType.API_KEY; } else { authScopes.addAll(scopesNode.getFieldNames()); if (scopesNode.has(CLOUD_PLATFORM_SCOPE)) { authType = AuthType.ADC; } else { authType = AuthType.OAUTH_3L; } } String canonicalName = root.getString("canonicalName"); String description = root.getString("description"); String id = root.getString("id"); Map<String, Schema> schemas = parseSchemas(root); List<Method> methods = parseMethods(root); Collections.sort(methods); // Ensure methods are ordered alphabetically by their ID. String ownerDomain = root.getString("ownerDomain"); String name = root.getString("name"); if (canonicalName.isEmpty()) { canonicalName = name; } Map<String, List<Method>> resources = parseResources(root); String revision = root.getString("revision"); String rootUrl = root.getString("rootUrl"); String servicePath = root.getString("servicePath"); String title = root.getString("title"); String version = root.getString("version"); boolean versionModule = root.getBoolean("version_module"); String baseUrl = root.has("baseUrl") ? root.getString("baseUrl") : (rootUrl + Strings.nullToEmpty(root.getString("basePath"))); Document thisDocument = new AutoValue_Document("", // authInstructionsUrl (only intended to be overridden). authScopes.build(), authType, baseUrl, canonicalName, description, "", // discoveryDocUrl (only intended to be overridden). id, methods, name, ownerDomain, resources, revision, rootUrl, schemas, servicePath, title, version, versionModule); for (Schema schema : schemas.values()) { schema.setParent(thisDocument); } for (Method method : methods) { method.setParent(thisDocument); } for (List<Method> resourceMethods : resources.values()) { for (Method method : resourceMethods) { method.setParent(thisDocument); } } return thisDocument; }
From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.InlinesSubstitution.java
public List<Inline> apply(List<Inline> inlines) { ImmutableList.Builder<Inline> builder = ImmutableList.builder(); boolean inReplacementSegment = false; for (Inline inline : inlines) { if (inline == first) { inReplacementSegment = true; builder.addAll(substitution); }/*w w w . j a va 2s . c o m*/ if (!inReplacementSegment) { builder.add(inline); } if (inReplacementSegment && inline == last) { inReplacementSegment = false; } } return builder.build(); }
From source file:com.google.gerrit.server.git.BranchOrderSection.java
public BranchOrderSection(String[] order) { if (order.length == 0) { this.order = ImmutableList.of(); } else {/* w w w . j a v a2 s . com*/ ImmutableList.Builder<String> builder = ImmutableList.builder(); for (String b : order) { builder.add(RefNames.fullName(b)); } this.order = builder.build(); } }