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

Code before:
      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(buildOptions, defaultCredentialRetrievers)
        .forEach(registryImage::addCredentialRetriever);
    JibContainerBuilder containerBuilder = Jib.from(registryImage);
    if (!from.getPlatforms().isEmpty()) {
      containerBuilder.setPlatforms(
          from.getPlatforms()
              .stream()
              .map(
                  platformSpec ->
                      new Platform(platformSpec.getArchitecture(), platformSpec.getOs()))
              .collect(Collectors.toSet()));
    }
    return containerBuilder;
  }
}


Review comment (refactor):
The iteration order is actually important. Internally we used `LinkedHashSet` everywhere to preserve the order while conveniently removing duplicates (also signifying that duplicates can't exist). However, I see that it can easily make the Jib API user to mess up with the order. Maybe accepting a `Set` wasn't a good idea.

Anyways, the question is, would `Collectors.toSet()` preserve the insertion order?

Code after:
          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(cliOptions, defaultCredentialRetrievers)
        .forEach(registryImage::addCredentialRetriever);
    JibContainerBuilder containerBuilder = Jib.from(registryImage);
    if (!from.getPlatforms().isEmpty()) {
      containerBuilder.setPlatforms(
          from.getPlatforms()
              .stream()
              .map(
                  platformSpec ->
                      new Platform(platformSpec.getArchitecture(), platformSpec.getOs()))
              .collect(Collectors.toCollection(LinkedHashSet::new)));
    }
    return containerBuilder;
  }
}