Java Code Examples for com.google.common.collect.ImmutableList#forEach()

The following examples show how to use com.google.common.collect.ImmutableList#forEach() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SparkFilterUtilsTest.java    From spark-bigquery-connector with Apache License 2.0 6 votes vote down vote up
@Test public void testValidFiltersForArrow() {
    ImmutableList<Filter> validFilters = ImmutableList.of(
            EqualTo.apply("foo", "manatee"),
            GreaterThan.apply("foo", "aardvark"),
            GreaterThanOrEqual.apply("bar", 2),
            LessThan.apply("foo", "zebra"),
            LessThanOrEqual.apply("bar", 1),
            In.apply("foo", new Object[] {1, 2, 3}),
            IsNull.apply("foo"),
            IsNotNull.apply("foo"),
            And.apply(IsNull.apply("foo"), IsNotNull.apply("bar")),
            Not.apply(IsNull.apply("foo")),
            StringStartsWith.apply("foo", "abc"),
            StringEndsWith.apply("foo", "def"),
            StringContains.apply("foo", "abcdef")
    );
    validFilters.forEach(f -> assertThat(SparkFilterUtils.unhandledFilters(ARROW, f)).isEmpty());
}
 
Example 2
Source File: OrderedClassFileResourceProvider.java    From bazel with Apache License 2.0 6 votes vote down vote up
public OrderedClassFileResourceProvider(
    ImmutableList<ClassFileResourceProvider> bootclasspathProviders,
    ImmutableList<ClassFileResourceProvider> classfileProviders) {
  final Set<String> bootclasspathDescriptors = Sets.newHashSet();
  for (ClassFileResourceProvider provider : classfileProviders) {
    // Collect all descriptors provided and the first provider providing each.
    bootclasspathProviders.forEach(p -> bootclasspathDescriptors.addAll(p.getClassDescriptors()));
    for (String descriptor : provider.getClassDescriptors()) {
      // Pick first definition of classpath class and filter out platform classes
      // from classpath if present.
      if (!bootclasspathDescriptors.contains(descriptor)
          && descriptors.add(descriptor)) {
        descriptorToProvider.put(descriptor, provider);
      }
    }
  }
}
 
Example 3
Source File: PipelinedModernBuildRule.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public final ImmutableList<? extends Step> getPipelinedBuildSteps(
    BuildContext context, BuildableContext buildableContext, State state) {
  ImmutableList.Builder<Path> outputsBuilder = ImmutableList.builder();
  recordOutputs(outputsBuilder::add);
  ImmutableList<Path> outputs = outputsBuilder.build();
  outputs.forEach(buildableContext::recordArtifact);
  OutputPathResolver outputPathResolver = getOutputPathResolver();
  ImmutableList.Builder<Step> stepsBuilder = ImmutableList.builder();
  ModernBuildRule.getSetupStepsForBuildable(
      context, getProjectFilesystem(), outputs, stepsBuilder, outputPathResolver);
  stepsBuilder.addAll(
      getBuildable()
          .getPipelinedBuildSteps(
              context,
              getProjectFilesystem(),
              state,
              outputPathResolver,
              getBuildCellPathFactory(context, getProjectFilesystem(), outputPathResolver)));
  return stepsBuilder.build();
}
 
Example 4
Source File: BundleToolMain.java    From bundletool with Apache License 2.0 6 votes vote down vote up
/** Displays a general help. */
public static void help() {
  ImmutableList<CommandHelp> commandHelps =
      ImmutableList.of(
          BuildBundleCommand.help(),
          BuildApksCommand.help(),
          ExtractApksCommand.help(),
          GetDeviceSpecCommand.help(),
          InstallApksCommand.help(),
          InstallMultiApksCommand.help(),
          ValidateBundleCommand.help(),
          DumpCommand.help(),
          GetSizeCommand.help(),
          VersionCommand.help());

  System.out.println("Synopsis: bundletool <command> ...");
  System.out.println();
  System.out.println("Use 'bundletool help <command>' to learn more about the given command.");
  System.out.println();
  commandHelps.forEach(commandHelp -> commandHelp.printSummary(System.out));
}
 
Example 5
Source File: WorkerSpawnStrategyTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Test
public void expandArgumentsPreservesEmptyLines() throws Exception {
  File flagfile = folder.newFile("flagfile.txt");

  ImmutableList<String> flags = ImmutableList.of("--hello", "", "--world");

  try (PrintWriter pw = new PrintWriter(Files.newBufferedWriter(flagfile.toPath(), UTF_8))) {
    flags.forEach(pw::println);
  }

  Path execRoot = fs.getPath(folder.getRoot().getAbsolutePath());
  WorkRequest.Builder requestBuilder = WorkRequest.newBuilder();
  WorkerSpawnRunner.expandArgument(execRoot, "@flagfile.txt", requestBuilder);

  assertThat(requestBuilder.getArgumentsList()).containsExactlyElementsIn(flags);
}
 
Example 6
Source File: ZipPath.java    From bundletool with Apache License 2.0 5 votes vote down vote up
public static ZipPath create(ImmutableList<String> names) {
  names.forEach(
      name -> {
        checkArgument(
            !name.contains("/"),
            "Name '%s' contains a forward slash and cannot be used in a path.",
            name);
        checkArgument(
            !FORBIDDEN_NAMES.contains(name), "Name '%s' is not supported inside path.", name);
      });
  return new AutoValue_ZipPath(names);
}
 
Example 7
Source File: ModernBuildRule.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public final ImmutableList<Step> getBuildSteps(
    BuildContext context, BuildableContext buildableContext) {
  ImmutableList.Builder<Path> outputsBuilder = ImmutableList.builder();
  recordOutputs(outputsBuilder::add);
  ImmutableList<Path> outputs = outputsBuilder.build();
  outputs.forEach(buildableContext::recordArtifact);
  return stepsForBuildable(context, buildable, getProjectFilesystem(), getBuildTarget(), outputs);
}
 
Example 8
Source File: IcannReportingStager.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/** Creates and stores a manifest file on GCS, indicating which reports were generated. */
void createAndUploadManifest(String subdir, ImmutableList<String> filenames) throws IOException {
  String reportBucketname = String.format("%s/%s", reportingBucket, subdir);
  final GcsFilename gcsFilename = new GcsFilename(reportBucketname, MANIFEST_FILE_NAME);
  StringBuilder manifestString = new StringBuilder();
  filenames.forEach((filename) -> manifestString.append(filename).append("\n"));
  gcsUtils.createFromBytes(gcsFilename, manifestString.toString().getBytes(UTF_8));
  logger.atInfo().log("Wrote %d filenames to manifest at %s", filenames.size(), gcsFilename);
}
 
Example 9
Source File: ReschedulingExecutor.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
  if (!active.get()) {
    ImmutableList<Future<?>> existingTasks = ImmutableList.copyOf(tasks.values());
    tasks.clear();
    existingTasks.forEach(task -> task.cancel(mayInterrupt));
  }
}
 
Example 10
Source File: FilteringAggregate.java    From james-project with Apache License 2.0 5 votes vote down vote up
public List<? extends Event> defineRules(List<Rule> rules) {
    Preconditions.checkArgument(shouldNotContainDuplicates(rules));
    ImmutableList<RuleSetDefined> events = ImmutableList.of(
        new RuleSetDefined(aggregateId, history.getNextEventId(), ImmutableList.copyOf(rules)));
    events.forEach(this::apply);
    return events;
}
 
Example 11
Source File: PerfManifestCommand.java    From buck with Apache License 2.0 5 votes vote down vote up
private static ImmutableMap<BuildRule, ImmutableSet<SourcePath>> getInputsAfterBuildingLocally(
    CommandRunnerParams params,
    ActionGraphBuilder graphBuilder,
    ImmutableList<BuildRule> rulesInGraph) {
  ImmutableMap.Builder<BuildRule, ImmutableSet<SourcePath>> usedInputs = ImmutableMap.builder();

  rulesInGraph.forEach(
      rule -> {
        if (rule instanceof SupportsDependencyFileRuleKey
            && ((SupportsDependencyFileRuleKey) rule).useDependencyFileRuleKeys()) {
          try {
            usedInputs.put(
                rule,
                ImmutableSet.copyOf(
                    ((SupportsDependencyFileRuleKey) rule)
                        .getInputsAfterBuildingLocally(
                            BuildContext.of(
                                graphBuilder.getSourcePathResolver(),
                                params.getCells().getRootCell().getRoot().getPath(),
                                params.getJavaPackageFinder(),
                                params.getBuckEventBus(),
                                false),
                            params.getCells().getRootCell().getCellPathResolver())));
          } catch (Exception e) {
            throw new BuckUncheckedExecutionException(
                e, "When asking %s for its inputs.", rule.getBuildTarget());
          }
        }
      });
  return usedInputs.build();
}
 
Example 12
Source File: DynamicClient.java    From karate-grpc with MIT License 5 votes vote down vote up
private ListenableFuture<Void> callClientStreaming(
        ImmutableList<DynamicMessage> requests,
        StreamObserver<DynamicMessage> responseObserver,
        CallOptions callOptions) {
    DoneObserver<DynamicMessage> doneObserver = new DoneObserver<>();
    StreamObserver<DynamicMessage> requestObserver = ClientCalls.asyncClientStreamingCall(
            createCall(callOptions),
            ComponentObserver.of(responseObserver, doneObserver));
    requests.forEach(requestObserver::onNext);
    requestObserver.onCompleted();
    return doneObserver.getCompletionFuture();
}
 
Example 13
Source File: DynamicClient.java    From karate-grpc with MIT License 5 votes vote down vote up
private ListenableFuture<Void> callBidiStreaming(
        ImmutableList<DynamicMessage> requests,
        StreamObserver<DynamicMessage> responseObserver,
        CallOptions callOptions) {
    DoneObserver<DynamicMessage> doneObserver = new DoneObserver<>();
    StreamObserver<DynamicMessage> requestObserver = ClientCalls.asyncBidiStreamingCall(
            createCall(callOptions),
            ComponentObserver.of(responseObserver, doneObserver));
    requests.forEach(requestObserver::onNext);
    requestObserver.onCompleted();
    return doneObserver.getCompletionFuture();
}
 
Example 14
Source File: ObjectDefinitionFileParser.java    From luna with MIT License 4 votes vote down vote up
@Override
public void onCompleted(ImmutableList<ObjectDefinition> tokenObjects) throws Exception {
    tokenObjects.forEach(ObjectDefinition.ALL::storeDefinition);
}
 
Example 15
Source File: CompilerWrapperProviderImpl.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Override
public File createCompilerExecutableWrapper(
    File executionRoot, File blazeCompilerExecutableFile) {
  try {
    File blazeCompilerWrapper =
        FileUtil.createTempFile("blaze_compiler", ".sh", true /* deleteOnExit */);
    if (!blazeCompilerWrapper.setExecutable(true)) {
      logger.warn("Unable to make compiler wrapper script executable: " + blazeCompilerWrapper);
      return null;
    }
    ImmutableList<String> compilerWrapperScriptLines =
        ImmutableList.of(
            "#!/bin/bash",
            "",
            "# The c toolchain compiler wrapper script doesn't handle arguments files, so we",
            "# need to move the compiler arguments from the file to the command line. We",
            "# preserve any existing commandline arguments, and remove the escaping from",
            "# arguments inside the args file.",
            "",
            "parsedargs=()",
            "for arg in \"${@}\"; do ",
            "  case \"$arg\" in",
            "    @*)",
            "      # Make sure the file ends with a newline - the read loop will not return",
            "      # the final line if it does not.",
            "      echo >> ${arg#@}",
            "      # Args file, the read will remove a layer of escaping",
            "      while read; do",
            "        parsedargs+=($REPLY)",
            "      done < ${arg#@}",
            "      ;;",
            "    *)",
            "      # Regular arg",
            "      parsedargs+=(\"$arg\")",
            "      ;;",
            "  esac",
            "done",
            "",
            "# The actual compiler wrapper script we get from blaze",
            String.format("EXE=%s", blazeCompilerExecutableFile.getPath()),
            "# Read in the arguments file so we can pass the arguments on the command line.",
            String.format("(cd %s && $EXE \"${parsedargs[@]}\")", executionRoot));

    try (PrintWriter pw = new PrintWriter(blazeCompilerWrapper, UTF_8.name())) {
      compilerWrapperScriptLines.forEach(pw::println);
    }
    return blazeCompilerWrapper;
  } catch (IOException e) {
    logger.warn(
        "Unable to write compiler wrapper script executable: " + blazeCompilerExecutableFile, e);
    return null;
  }
}
 
Example 16
Source File: MailsShouldBeWellReceived.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Test
default void mailsShouldBeWellReceivedByTenRecipient(GuiceJamesServer server) throws Exception {
    server.getProbe(DataProbeImpl.class).fluent()
            .addDomain(DOMAIN)
            .addUser(JAMES_USER, PASSWORD);

    ImmutableList<String> users = generateNUsers(10);

    users.forEach((ThrowingConsumer<String>) user -> server.getProbe(DataProbeImpl.class)
                    .fluent()
                    .addUser(user, PASSWORD));

    MailboxProbeImpl mailboxProbe = server.getProbe(MailboxProbeImpl.class);
    mailboxProbe.createMailbox("#private", JAMES_USER, DefaultMailboxes.INBOX);
    users.forEach((ThrowingConsumer<String>) user ->
                    mailboxProbe.createMailbox("#private", user, DefaultMailboxes.INBOX));


    Port smtpPort = server.getProbe(SmtpGuiceProbe.class).getSmtpPort();
    String message = Resources.toString(Resources.getResource("eml/htmlMail.eml"), StandardCharsets.UTF_8);

    try (SMTPMessageSender sender = new SMTPMessageSender(Domain.LOCALHOST.asString())) {
        sender.connect(JAMES_SERVER_HOST, smtpPort);
        sendUniqueMessageToUsers(sender, message, users);
    }

    CALMLY_AWAIT_FIVE_MINUTE.untilAsserted(() ->
        assertThat(
            server
                .getProbe(SpoolerProbe.class)
                .processingFinished()
        ).isTrue());

    try (TestIMAPClient reader = new TestIMAPClient()) {
        users.forEach((ThrowingConsumer<String>) user -> reader
            .connect(JAMES_SERVER_HOST, server.getProbe(ImapGuiceProbe.class).getImapPort())
            .login(user, PASSWORD)
            .select(TestIMAPClient.INBOX)
            .awaitMessageCount(CALMLY_AWAIT, 1));
    }
}
 
Example 17
Source File: TransactionManagerTest.java    From nomulus with Apache License 2.0 4 votes vote down vote up
private static void assertAllEntitiesNotExist(ImmutableList<TestEntity> entities) {
  entities.forEach(TransactionManagerTest::assertEntityNotExist);
}
 
Example 18
Source File: OutputsMaterializer.java    From buck with Apache License 2.0 4 votes vote down vote up
private void processFetchAndMaterialize() {
  ImmutableList.Builder<PendingMaterialization> builder = ImmutableList.builder();
  int size = 0;
  int items = 0;
  while (!waitingMaterialization.isEmpty()) {
    PendingMaterialization data = waitingMaterialization.poll();
    if (data == null) {
      break;
    }
    if (items == 0 || (data.digest.getSize() + size < sizeLimit)) {
      builder.add(data);
      size += data.digest.getSize();
      items++;
    } else {
      waitingMaterialization.addFirst(data);
      break;
    }
  }
  ImmutableList<PendingMaterialization> pending = builder.build();

  if (!pending.isEmpty()) {
    try (SimplePerfEvent.Scope ignored =
        SimplePerfEvent.scope(
            buckEventBus,
            SimplePerfEvent.PerfEventId.of("outputs-materializer"),
            "size",
            size,
            "items",
            pending.size())) {
      if (size > sizeLimit) {
        LOG.debug("Starting stream request for: " + pending.size() + " requests, size: " + size);
        PendingMaterialization large = Iterables.getOnlyElement(pending);

        // Download large files as a stream
        WritableByteChannel channel =
            large.materializer.getOutputChannel(large.path, large.isExecutable);
        ListenableFuture<Unit> fetchToStream = fetcher.fetchToStream(large.digest, channel);
        try {
          // Wait for the stream to finish downloading before picking up more work
          large.future.setFuture(fetchToStream);
          fetchToStream.get();
        } finally {
          tryCloseChannel(channel);
        }
      } else {
        LOG.debug("Starting batch request for: " + pending.size() + " items, size: " + size);
        // Download batches of small objects
        ImmutableMultimap.Builder<Digest, Callable<WritableByteChannel>> digestMap =
            ImmutableMultimap.builder();
        ImmutableMultimap.Builder<Digest, SettableFuture<Unit>> futureMap =
            ImmutableMultimap.builder();
        for (PendingMaterialization p : pending) {
          digestMap.put(p.digest, () -> p.materializer.getOutputChannel(p.path, p.isExecutable));
          futureMap.put(p.digest, p.future);
        }

        ImmutableMultimap<Digest, Callable<WritableByteChannel>> batch = digestMap.build();
        ImmutableMultimap<Digest, SettableFuture<Unit>> futures = futureMap.build();
        fetcher.batchFetchBlobs(batch, futures).get();
      }
      LOG.debug("Finished materializing: " + pending.size() + " requests, size: " + size);
    } catch (Exception e) {
      pending.forEach(materialization -> materialization.future.setException(e));
    }
  }

  if (!waitingMaterialization.isEmpty()) {
    materializerService.submit(this::processFetchAndMaterialize);
  }
}
 
Example 19
Source File: AuditModulesCommand.java    From buck with Apache License 2.0 4 votes vote down vote up
private static void dumpModuleInformationInRawFormat(
    Console console, ImmutableList<AuditModuleInformation> modules) {

  modules.forEach(module -> dumpModuleInformationInRawFormat(console.getStdOut(), module));
}
 
Example 20
Source File: NinjaGraphTest.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Test
public void testNinjaGraphRuleWithPhonyTree() throws Exception {
  rewriteWorkspace(
      "workspace(name = 'test')", "toplevel_output_directories(paths = ['build_config'])");

  // We do not have to have the real files in place, the rule only reads
  // the contents of Ninja files.
  scratch.file(
      "build_config/build.ninja",
      "rule cat",
      "  command = cat ${in} > ${out}",
      "rule echo",
      "  command = echo \"Hello $$(cat ${in} | tr '\\r\\n' ' ')!\" > ${out}",
      "build a: cat a.txt",
      "build b: cat b.txt",
      "build c: cat c.txt",
      "build d: cat d.txt",
      // e should be executed unconditionally as it depends on always-dirty phony action
      "build e: cat e.txt always_dirty",
      "build always_dirty: phony",
      "build group1: phony a b c",
      "build group2: phony d e",
      "build inputs_alias: phony group1 group2",
      "build hello.txt: echo inputs_alias",
      "build alias: phony hello.txt");

  ConfiguredTarget configuredTarget =
      scratchConfiguredTarget(
          "",
          "graph",
          "ninja_graph(name = 'graph', output_root = 'build_config',",
          " working_directory = 'build_config',",
          " main = 'build_config/build.ninja',",
          " output_root_inputs = ['a.txt', 'b.txt', 'c.txt', 'd.txt', 'e.txt'])");
  assertThat(configuredTarget).isInstanceOf(RuleConfiguredTarget.class);
  RuleConfiguredTarget ninjaConfiguredTarget = (RuleConfiguredTarget) configuredTarget;
  ImmutableList<ActionAnalysisMetadata> actions = ninjaConfiguredTarget.getActions();
  assertThat(actions).hasSize(5);
  List<String> outputs = Lists.newArrayList();
  actions.forEach(a -> outputs.add(Iterables.getOnlyElement(a.getOutputs()).getExecPathString()));
  assertThat(outputs)
      .containsExactlyElementsIn(
          new String[] {
            "build_config/a.txt",
            "build_config/b.txt",
            "build_config/c.txt",
            "build_config/d.txt",
            "build_config/e.txt"
          });

  for (ActionAnalysisMetadata action : actions) {
    assertThat(action).isInstanceOf(SymlinkAction.class);
    SymlinkAction symlinkAction = (SymlinkAction) action;
    assertThat(symlinkAction.executeUnconditionally()).isTrue();
    assertThat(symlinkAction.getInputPath().getParentDirectory())
        .isEqualTo(PathFragment.create("/workspace/build_config"));
    assertThat(symlinkAction.getInputPath().getFileExtension()).isEqualTo("txt");
    PathFragment execRootPath = symlinkAction.getPrimaryOutput().getExecPath();
    assertThat(execRootPath.getParentDirectory()).isEqualTo(PathFragment.create("build_config"));
    assertThat(execRootPath.getFileExtension()).isEqualTo("txt");
  }
}