+ final Table<FileKind, String, Supplier<String>> generatedFiles = generator.generateFileContent(
+ ignoreDuplicateFiles);
+
+ // Step two: create generation tasks for each target file and group them by parent directory
+ final ListMultimap<Path, GenerationTask> dirs = MultimapBuilder.hashKeys().arrayListValues().build();
+ for (Cell<FileKind, String, Supplier<String>> cell : generatedFiles.cellSet()) {
+ final File target;
+ switch (cell.getRowKey()) {
+ case PERSISTENT:
+ target = new File(persistentSourcesDir, cell.getColumnKey());
+ if (target.exists()) {
+ LOG.debug("Skipping existing persistent {}", target);
+ continue;
+ }
+ break;
+ case TRANSIENT:
+ target = new File(outputBaseDir, cell.getColumnKey());
+ break;
+ default:
+ throw new IllegalStateException("Unsupported file type in " + cell);
+ }
+
+ dirs.put(target.getParentFile().toPath(), new GenerationTask(buildContext, target, cell.getValue()));
+ }
+ LOG.info("Generating {} Binding source files into {} directories", dirs.size(), dirs.keySet().size());
+
+ // Step three: submit parent directory creation tasks (via parallelStream()) and wait for them to complete
+ sw.reset().start();
+ dirs.keySet().parallelStream().forEach(path -> {
+ try {
+ Files.createDirectories(path);
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to create " + path, e);
+ }
+ });
+ LOG.debug("Parent directories created in {}", sw);