Repository: GoogleContainerTools/jib
File: jib-cli/src/main/java/com/google/cloud/tools/jib/cli/ContainerBuilders.java (Java)

Code before:
      String baseImageReference,
      List<Platform> platforms,
      CommonCliOptions commonCliOptions,
      ConsoleLogger logger)
      throws InvalidImageReferenceException, FileNotFoundException {
    if (baseImageReference.startsWith(DOCKER_DAEMON_IMAGE_PREFIX)) {
      return Jib.from(
          DockerDaemonImage.named(baseImageReference.replaceFirst(DOCKER_DAEMON_IMAGE_PREFIX, "")));
    }
    if (baseImageReference.startsWith(TAR_IMAGE_PREFIX)) {
      return Jib.from(
          TarImage.at(Paths.get(baseImageReference.replaceFirst(TAR_IMAGE_PREFIX, ""))));
    }
    ImageReference imageReference =
        ImageReference.parse(baseImageReference.replaceFirst(REGISTRY_IMAGE_PREFIX, ""));
    RegistryImage registryImage = RegistryImage.named(imageReference);
    DefaultCredentialRetrievers defaultCredentialRetrievers =
        DefaultCredentialRetrievers.init(
            CredentialRetrieverFactory.forImage(
                imageReference,
                logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage())));
    Credentials.getFromCredentialRetrievers(commonCliOptions, defaultCredentialRetrievers)
        .forEach(registryImage::addCredentialRetriever);
    JibContainerBuilder containerBuilder = Jib.from(registryImage);
    if (!platforms.isEmpty()) {
      containerBuilder.setPlatforms(platforms.stream().collect(Collectors.toSet()));
    }
    return containerBuilder;
  }
}


Review comment (bug):
If you make `create()` accept `Set<Platform>`, it won't need `stream().collect()`.

BTW, [this link](https://stackoverflow.com/q/27611896/1701388) says `toSet()` doesn't preserve the order. The order of platforms is important, so that's why the original code used `Collectors.toCollection(LinkedHashSet::new))`.

Code after:
      Set<Platform> platforms,
      CommonCliOptions commonCliOptions,
      ConsoleLogger logger)
      throws InvalidImageReferenceException, FileNotFoundException {
    if (baseImageReference.startsWith(DOCKER_DAEMON_IMAGE_PREFIX)) {
      return Jib.from(
          DockerDaemonImage.named(baseImageReference.replaceFirst(DOCKER_DAEMON_IMAGE_PREFIX, "")));
    }
    if (baseImageReference.startsWith(TAR_IMAGE_PREFIX)) {
      return Jib.from(
          TarImage.at(Paths.get(baseImageReference.replaceFirst(TAR_IMAGE_PREFIX, ""))));
    }
    ImageReference imageReference =
        ImageReference.parse(baseImageReference.replaceFirst(REGISTRY_IMAGE_PREFIX, ""));
    RegistryImage registryImage = RegistryImage.named(imageReference);
    DefaultCredentialRetrievers defaultCredentialRetrievers =
        DefaultCredentialRetrievers.init(
            CredentialRetrieverFactory.forImage(
                imageReference,
                logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage())));
    Credentials.getFromCredentialRetrievers(commonCliOptions, defaultCredentialRetrievers)
        .forEach(registryImage::addCredentialRetriever);
    JibContainerBuilder containerBuilder = Jib.from(registryImage);
    if (!platforms.isEmpty()) {
      containerBuilder.setPlatforms(platforms);
    }
    return containerBuilder;
  }
}