+ try {
+ Futures.whenAllComplete(parentFutures).call(() -> {
+ for (ListenableFuture<Void> future : parentFutures) {
+ Futures.getDone(future);
+ }
+ return null;
+ }, MoreExecutors.directExecutor()).get();
+ } catch (InterruptedException e) {
+ throw new IOException("Interrupted while creating parent directories", e);
+ } catch (ExecutionException e) {
+ LOG.debug("Failed to create parent directories", e);
+ Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
+ throw new IOException("Failed to create parent directories", e);
+ }
+ LOG.debug("Parent directories created in {}", sw);
+
+ // Step four: submit all code generation tasks and wait for them to complete
+ sw.reset().start();
+ final List<ListenableFuture<File>> futureFiles = dirs.values().stream()
+ .map(service::submit)
+ .collect(Collectors.toList());
+
+ final List<File> result;
+ try {
+ result = Futures.whenAllComplete(futureFiles).call(() -> {
+ List<File> ret = new ArrayList<>(futureFiles.size());
+ for (ListenableFuture<File> future : futureFiles) {
+ ret.add(Futures.getDone(future));
+ }
+ return ret;
+ }, MoreExecutors.directExecutor()).get();
+ } catch (InterruptedException e) {
+ throw new IOException("Interrupted while generating files", e);
+ } catch (ExecutionException e) {
+ LOG.error("Failed to create generated files", e);
+ Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
+ throw new IOException("Failed to create generated files", e);