List of usage examples for com.google.common.collect ImmutableList.Builder addAll
boolean addAll(Collection<? extends E> c);
From source file:org.apache.calcite.rel.rules.FilterTableScanRule.java
protected void apply(RelOptRuleCall call, Filter filter, TableScan scan) { final ImmutableIntList projects; final ImmutableList.Builder<RexNode> filters = ImmutableList.builder(); if (scan instanceof Bindables.BindableTableScan) { final Bindables.BindableTableScan bindableScan = (Bindables.BindableTableScan) scan; filters.addAll(bindableScan.filters); projects = bindableScan.projects; } else {/*from www . j a v a 2s . c o m*/ projects = scan.identity(); } final Mapping mapping = Mappings.target(projects, scan.getTable().getRowType().getFieldCount()); filters.add(RexUtil.apply(mapping, filter.getCondition())); call.transformTo( Bindables.BindableTableScan.create(scan.getCluster(), scan.getTable(), filters.build(), projects)); }
From source file:org.sonar.plugins.java.JavaPlugin.java
@Override public void define(Context context) { ImmutableList.Builder<Object> builder = ImmutableList.builder(); Version sonarQubeVersion = context.getSonarQubeVersion(); if (!sonarQubeVersion.isGreaterThanOrEqual(SQ_6_0) || context.getRuntime().getProduct() != SonarProduct.SONARLINT) { builder.addAll(SurefireExtensions.getExtensions()); builder.addAll(JaCoCoExtensions.getExtensions(sonarQubeVersion)); builder.add(JavaSonarWayProfile.class); }//from www . ja v a 2 s. c o m builder.addAll(JavaClasspathProperties.getProperties()); builder.add(JavaClasspath.class, JavaTestClasspath.class, Java.class, PropertyDefinition .builder(Java.FILE_SUFFIXES_KEY).defaultValue(Java.DEFAULT_FILE_SUFFIXES) .category(JavaConstants.JAVA_CATEGORY).name("File suffixes") .description( "Comma-separated list of suffixes for files to analyze. To not filter, leave the list empty.") .subCategory("General").onQualifiers(Qualifiers.PROJECT).build(), new JavaRulesDefinition(context.getSonarQubeVersion()), SonarComponents.class, DefaultJavaResourceLocator.class, JavaSquidSensor.class, PostAnalysisIssueFilter.class, XmlFileSensor.class); context.addExtensions(builder.build()); }
From source file:com.squareup.wire.schema.MessageType.java
public ImmutableList<Field> fieldsAndOneOfFields() { ImmutableList.Builder<Field> result = ImmutableList.builder(); result.addAll(declaredFields); result.addAll(extensionFields);/*from www . jav a 2 s. c o m*/ for (OneOf oneOf : oneOfs) { result.addAll(oneOf.fields()); } return result.build(); }
From source file:co.cask.cdap.client.ServiceClient.java
/** * Gets a list of {@link ServiceHttpEndpoint} that a {@link Service} exposes. * * @param service ID of the service//w w w .j a v a 2 s .c o m * @return A list of {@link ServiceHttpEndpoint} * @throws IOException if a network error occurred * @throws UnauthorizedException if the request is not authorized successfully in the gateway server * @throws NotFoundException if the app or service could not be found */ public List<ServiceHttpEndpoint> getEndpoints(Id.Service service) throws IOException, UnauthorizedException, NotFoundException { ServiceSpecification specification = get(service); ImmutableList.Builder<ServiceHttpEndpoint> builder = new ImmutableList.Builder<>(); for (HttpServiceHandlerSpecification handlerSpecification : specification.getHandlers().values()) { builder.addAll(handlerSpecification.getEndpoints()); } return builder.build(); }
From source file:com.facebook.buck.java.ExternalJavacStep.java
@Override protected int buildWithClasspath(ExecutionContext context, Set<Path> buildClasspathEntries) { ImmutableList.Builder<String> command = ImmutableList.builder(); command.add(pathToJavac.toString()); command.addAll(getOptions(context, buildClasspathEntries)); ImmutableList<Path> expandedSources; try {/*from ww w . ja v a 2 s. c o m*/ expandedSources = getExpandedSourcePaths(context); } catch (IOException e) { throw new HumanReadableException("Unable to expand sources for %s into %s", target, workingDirectory); } if (pathToSrcsList.isPresent()) { try { context.getProjectFilesystem().writeLinesToPath( Iterables.transform(expandedSources, Functions.toStringFunction()), pathToSrcsList.get()); command.add("@" + pathToSrcsList.get()); } catch (IOException e) { context.logError(e, "Cannot write list of .java files to compile to %s file! Terminating compilation.", pathToSrcsList.get()); return 1; } } else { for (Path source : expandedSources) { command.add(source.toString()); } } ProcessBuilder processBuilder = new ProcessBuilder(command.build()); // Add additional information to the environment Map<String, String> env = processBuilder.environment(); env.put("BUCK_INVOKING_RULE", invokingRule.or("")); env.put("BUCK_TARGET", target.toString()); env.put("BUCK_DIRECTORY_ROOT", context.getProjectDirectoryRoot().toString()); env.put("BUCK_OUTPUT_ABI_FILE", pathToOutputAbiFile.or(new File("").toPath()).toString()); processBuilder.directory(context.getProjectDirectoryRoot()); // Run the command int exitCode = -1; try { ProcessExecutor.Result result = context.getProcessExecutor().execute(processBuilder.start()); exitCode = result.getExitCode(); } catch (IOException e) { e.printStackTrace(context.getStdErr()); return exitCode; } if (exitCode != 0) { return exitCode; } // Read ABI key if (abiKeyFile != null) { try { String firstLine = Files.readFirstLine(abiKeyFile, Charsets.UTF_8); if (firstLine != null) { // TODO(user) make sure command is considered in hash abiKey = new Sha1HashCode(firstLine); } } catch (IOException e) { e.printStackTrace(context.getStdErr()); return 1; } } return 0; }
From source file:org.apache.james.mailbox.jpa.mail.JPAAnnotationMapper.java
private List<MailboxAnnotation> flatMapToList(Iterable<List<MailboxAnnotation>> likes) { ImmutableList.Builder<MailboxAnnotation> resultBuilder = ImmutableList.builder(); for (List<MailboxAnnotation> mailboxAnnotations : likes) { resultBuilder.addAll(mailboxAnnotations); }//ww w .j a va 2 s . com return resultBuilder.build(); }
From source file:org.geogit.cli.porcelain.Init.java
/** * Executes the init command./*from w ww . j a v a 2 s . co m*/ */ @Override public void runInternal(GeogitCLI cli) throws IOException { final File repoDir; { File currDir = cli.getPlatform().pwd(); if (location != null && location.size() == 1) { String target = location.get(0); File f = new File(target); if (!f.isAbsolute()) { f = new File(currDir, target).getCanonicalFile(); } repoDir = f; if (!repoDir.exists() && !repoDir.mkdirs()) { throw new CommandFailedException("Can't create directory " + repoDir.getAbsolutePath()); } } else { repoDir = currDir; } } GeoGIT geogit = null; if (cli.getGeogit() == null) { geogit = new GeoGIT(cli.getGeogitInjector(), repoDir); } else { geogit = cli.getGeogit(); } ImmutableList.Builder<String> builder = ImmutableList.builder(); addDefaults(cli.getGeogitInjector().getInstance(PluginDefaults.class), builder); builder.addAll(splitConfig(config)); List<String> effectiveConfiguration = builder.build(); Repository repository = geogit.command(InitOp.class).setConfig(effectiveConfiguration).call(); final boolean repoExisted = repository == null; geogit.setRepository(repository); cli.setGeogit(geogit); final URL envHome = geogit.command(ResolveGeogitDir.class).call().get(); File repoDirectory; try { repoDirectory = new File(envHome.toURI()); } catch (URISyntaxException e) { throw new IllegalStateException("Environment home can't be resolved to a directory", e); } String message; if (repoExisted) { message = "Reinitialized existing Geogit repository in " + repoDirectory.getAbsolutePath(); } else { message = "Initialized empty Geogit repository in " + repoDirectory.getAbsolutePath(); } cli.getConsole().println(message); }
From source file:com.facebook.buck.distributed.build_slave.ActiveCoordinatorService.java
@Override public GetWorkResponse getWork(GetWorkRequest request) { // Create the response with some defaults GetWorkResponse response = new GetWorkResponse(); response.setContinueBuilding(true);//from w w w .j a va 2 s . c o m response.setWorkUnits(new ArrayList<>()); coordinatorBuildRuleEventsPublisher .createBuildRuleCompletionEvents(ImmutableList.copyOf(request.getFinishedTargets())); String minionId = request.getMinionId(); if (allocator.hasMinionFailed(minionId)) { // Minion has failed health checks and its work has already been re-assigned. // In the unlikely case it comes back from the dead, tell it to shut down. // TODO(alisdair): consider implementing logic to allow minions to re-join build LOG.warn(String.format( "GetWorkResponse request received from minion [%s] previously marked as dead. Removing it from build.", minionId)); response.setContinueBuilding(false); return response; } if (exitCodeFuture.isDone()) { // Tell any remaining minions that the build is finished and that they should shutdown. // Note: we cannot assume that when exitCodeFuture was set the first time the // coordinator server will shutdown immediately. response.setContinueBuilding(false); return response; } // If the minion died (with a compilation error), then kill the whole build. if (request.getLastExitCode() != 0) { String msg = String.format("Got non zero exit code in GetWorkRequest from minion [%s]. Exit code [%s]", minionId, request.getLastExitCode()); LOG.error(msg); exitCodeFuture.complete(ExitState.setLocally(request.getLastExitCode(), msg)); response.setContinueBuilding(false); return response; } MinionWorkloadAllocator.WorkloadAllocationResult allocationResult = allocator .updateMinionWorkloadAllocation(minionId, request.getMinionType(), request.getFinishedTargets(), request.getMaxWorkUnitsToFetch()); if (allocationResult.shouldReleaseMinion) { minionHealthTracker.stopTrackingForever(minionId); response.setContinueBuilding(false); return response; } // TODO(alisdair): experiment with only sending started event for first node in chain, // and then send events for later nodes in the chain as their children finish. ImmutableList.Builder<String> startedTargetsBuilder = ImmutableList.builder(); for (WorkUnit workUnit : allocationResult.newWorkUnitsForMinion) { startedTargetsBuilder.addAll(workUnit.getBuildTargets()); } coordinatorBuildRuleEventsPublisher.createBuildRuleStartedEvents(startedTargetsBuilder.build()); if (allocator.haveMostBuildRulesCompleted()) { coordinatorBuildRuleEventsPublisher.createMostBuildRulesCompletedEvent(); } // If the build is already finished (or just finished with this update, then signal this to // the minion. if (allocator.isBuildFinished()) { exitCodeFuture.complete(ExitState.setLocally(0, "Build finished successfully.")); LOG.info(String.format("Minion [%s] is being told to exit because the build has finished.", request.minionId)); minionHealthTracker.stopTrackingForever(request.minionId); response.setContinueBuilding(false); } else { response.setWorkUnits(allocationResult.newWorkUnitsForMinion); } coordinatorBuildRuleEventsPublisher.updateCoordinatorBuildProgress(allocator.getBuildProgress()); return response; }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.design.arcs.model.DefaultArcModifier.java
private Object[] composeAllArguments(final Arc arc, final NormalWord newName, final Priority priority, final ImmutableList<Object> argumentsCopy) { final ImmutableList.Builder<Object> allArgumentsBuilder = ImmutableList.builder(); allArgumentsBuilder.add(arc.getNetwork()); allArgumentsBuilder.add(newName);//ww w .j av a 2s . co m allArgumentsBuilder.add(priority); allArgumentsBuilder.addAll(argumentsCopy); return allArgumentsBuilder.build().toArray(); }
From source file:com.google.devtools.build.buildjar.VanillaJavaBuilder.java
/** Returns the sources to compile, including any source jar entries. */ private ImmutableList<JavaFileObject> getSources(OptionsParser optionsParser, StandardJavaFileManager fileManager) throws IOException { final ImmutableList.Builder<JavaFileObject> sources = ImmutableList.builder(); sources.addAll(fileManager.getJavaFileObjectsFromStrings(optionsParser.getSourceFiles())); for (String sourceJar : optionsParser.getSourceJars()) { for (final Path root : getJarFileSystem(Paths.get(sourceJar)).getRootDirectories()) { Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override/*from w ww .ja va 2 s. c o m*/ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (path.getFileName().toString().endsWith(".java")) { sources.add(new SourceJarFileObject(root, path)); } return FileVisitResult.CONTINUE; } }); } } return sources.build(); }